String to long Coversion
We have an application where the database columns are BIGINTs and the corresponding Java Value Object have String. So there is a conversion happening the application between String->long and long->String. Will this cause any serious performance problems when done in a huge volume?
Is it suggestable to have these conversions in the code?
Thanks,
Rama
[382 byte] By [
ramaraoca] at [2007-10-3 3:00:02]

I guess you need to try whether the performance is acceptable in your environment. How am I supposed to tell whether you could get a performance problem?
Working with Strings is amazingly ... clumsy. They need amazingly much memory, are hard to compare, and quite difficult to check for validity.
I will get beaten for this by some guys here, but: if you don't have to use Strings, avoid them. Because writing is the common human way to memorize things, many people prefer Strings to store and process almost anything. In very many cases, this is one of the worst choices they can make.
So yeah: if you have a number, the logical consequence is to parse your database entry to something like a long, int or BigInteger, instead of carrying the original String around.
> I will get beaten for this by some guys here, but: if
> you don't have to use Strings, avoid them. Because
> writing is the common human way to memorize things,
> many people prefer Strings to store and process
> almost anything. In very many cases, this is one of
> the worst choices they can make.
Would you care to explain why you expect to be "beaten by some guys here" for that statement? I haven't seen anybody advising to use a String if a long is needed, and I've been around for a while.
>
> Would you care to explain why you expect to be
> "beaten by some guys here" for that statement? I
> haven't seen anybody advising to use a String if a
> long is needed, and I've been around for a while.
Because "Strings are evil" seemed to me like quite a harsh judgement. I could totally understand if someone would disagree to this one, but I won't change my mind.
For some weird reason, everybody loves Strings. People love to match Strings to objects, and work with the Strings instead of the objects.
For example, we had a thread here some days ago where someone wanted to implement a "Paper-Rock-Scissor" Game. He passed along "Paper" "Rock" and "Scissor" along as Strings to calculate wins and loses, instead of abstracting from the words. This is error prone and clumsy, but I see it over and over again.
> For example, we had a thread here some days ago where
> someone wanted to implement a "Paper-Rock-Scissor"
> Game. He passed along "Paper" "Rock" and "Scissor"
> along as Strings to calculate wins and loses, instead
> of abstracting from the words. This is error prone
> and clumsy, but I see it over and over again.
I agree! Strings are overused. But I'd go even further and say: most basic Datatypes are overused. I've seen too many cases of the following
public static final AN_OPTION=1;
public static final ANOTHER_OPTION=2;
public static final ONE_MORE=3;
Whenever I see such a thing I think that it should be replaced with an enum (even in a pre-1.5 environment you can build your own enum).
> For example, we had a thread here some days ago where
> someone wanted to implement a "Paper-Rock-Scissor"
> Game. He passed along "Paper" "Rock" and "Scissor"
> along as Strings to calculate wins and loses, instead
> of abstracting from the words. This is error prone
> and clumsy, but I see it over and over again.
So you're afraid of the newbies to beat you up? I still have yet to see any of the regulars or almost regulars here suggesting to use String where inappropriate. I think you're preaching to the choir. :)