All,
I've been a Java developer for 10 years...when it comes to managing numerical data, for the most part I've stuck with int
and used double
when I need some decimal precision. The reason is we pretty much have a large heap space to work with and exhausting it is pretty difficult for the most part...
I'm starting iPhone development (I do have some C Programming knowledge) and I'm wondering if I should start looking at using appropriate data types given that the device itself has less resources than your typical JavaEE app...
For instance, I have an object with some numeric attribute (we'll call this attribute 'state'). This attribute will only ever have values from maybe -10 to 10. Originally, I defined this attribute using an int
, but now I've decided to use char
. The reason is I don't need that many bits to represent the values from -10 to 10...so char
is the smallest I need. Unfortunately, when someone sees a char
they may think character, but I'm treating it as a number. I'm concerned that I'll probably introduce some confusion if I stick with char
...
So given this code fragment:
-(void)doSomething:(char)value {
state = value;
}
then invoking it such as:
[myObject doSomething:1];
My question is should I even be worried about optimizing the data types in this manner? Do I need to start checking for overflow and throw errors? Or is this perfectly good programming?
Thanks!
EDIT: I think I shouldn't have used the name state
in my question. I don't particularly have an enumeration here as I perform calculations on this value and update the state
as appropriate. It just happens to have a fixed range.