This maybe related to any programming language I guess, I need your ideas about this. Who is correct? Check the following.
Mr. X says -> Capacity of the variable should be determined carefully. E.g. To capture a person's age, using an integer is a waste of memory. byte would be an ideal size for such purpose.
Mr. Y says -> No, I do not agree. For PC applications, we do not need to care about resource (memory) so much. Integer is always the best choice for a number type, because they are fast when processing. Integer is the size of CPU register (32b or 64b). So I think this is unnecessary.
Note: I should have put this in a programming forum but I feel yahoo answers are much more quick and gets lots of answers. :D
2007-01-22
19:53:59
·
7 answers
·
asked by
slperera
3
in
Computers & Internet
➔ Programming & Design
Maybe Mr. X is correct when it comes to handheld devices.
2007-01-22
20:29:04 ·
update #1
Well, I totally agree with Mr. X; even if we don't need to care about resources any more, it would be a good programming practice to care about them; neglecting resource consumption may lead to memory leak, system failures,..etc
For example, take the Java language, Integers are 32bit, even if you are running on a 64bit machine, thus it has no relation here with the WORD size of your processor/OS.
After all, it's Language Dependent, but generally in programming, it's a good programming practice to watch for resource wasting.
2007-01-22 21:10:52
·
answer #1
·
answered by Fox 3
·
0⤊
0⤋
If you are writing a very small application which is going to run on a PC would you really post this question here, or be bothered? Its not only about just Integer or float. The choice of variable(though you should have used the term type, because that is what we really program for and not for variable, variable is just another pointer to a memory location, which in Java would be inaccessible, lack of pointers) would matter when you extend your class, or you make use of composition to construct coarse grained objects out of fine grained objects. So making wrong(or being reluctant) choice of variable in fine grained variables (fields in Java) would lead to serious issues once your code breaks in an advance development stage. You realize the basic composition POJO has an obvious flaw of type.
With kind of processing speed available these days. We don't really care about the size a particular type would eat. In fact int in Java is 32 bit long, though in some other programming language it is even 16 bit length. So true benchmarking for Java is a ridiculous thought(JAVA runs in JVM, and processors could have address line which are 16,32, 64 hell who knows about future).
--
Ck
http://www.gfour.net
2007-01-26 16:42:31
·
answer #2
·
answered by KingPin 3
·
0⤊
0⤋
In Java, it doesn't matter. Using type "byte" gets stored in 32-bits by the JVM anyway (unless in a byte array - go figure).
When working in a language where you have complete control of memory addressing, then yes, using byte will be more efficient. This is the typical case when working with embedded systems.
As an aside, you seldom should work with "age", but rather "birthdate". Age should be calculated (since it changes with time!). Storing birthdate will allow you to do more meaningful calculations (differences/comparisions, projecting back/forward in time (e.g., add 3 months), etc.
2007-01-23 20:14:26
·
answer #3
·
answered by vincentgl 5
·
0⤊
0⤋
Maybe I'm a purist but I agree with your Mr X. Any good developer should consider the efficiency of their code at every opportunity. Specifying the correct variable type should be considered the baseline for this. Not only will application code and memory usage be more efficient, but it also can prevent mistakes in assigning out-of-bounds values (ever met someone aged 9,999,999???).
Try to be the best at what you do, write smart, efficient, reusable code!
2007-01-23 04:27:45
·
answer #4
·
answered by Duff 3
·
0⤊
0⤋
It doesn't really matter anymore nowadays since computers have a lot of RAM and a few extra bytes don't matter, it would be different once you would be programming embedded software that needs to run on systems with not much RAM. Or when you work with big arrays of over a million objects.
2007-01-23 04:01:13
·
answer #5
·
answered by john_ven24 2
·
0⤊
0⤋
It's all well and good if you're storing just one age, but if you're storing millions - you are suddenly wasting potentially gigabytes of storage space. It's a case of "use some common sense". There isn't one magic rule for all situations - a bit like in real life!
2007-01-23 04:28:51
·
answer #6
·
answered by Anonymous
·
0⤊
0⤋
If using huge array or database "bye" is better than "int" and otherwise "int" is better than "byte"
2007-01-23 04:05:50
·
answer #7
·
answered by roooya 2
·
0⤊
0⤋