language agnostic - When to use unsigned values over signed ones? -
when appropriate use unsigned variable on signed one? in for
loop?
i hear lot of opinions , wanted see if there resembling consensus.
for (unsigned int = 0; < something.length(); i++) { var = something.at(i); // idea. }
i know java doesn't have unsigned values, , must have been concious decision on sun microsystems' part.
i glad find a conversation on subject, hadn't given thought before.
in summary, signed general choice - when you're dead sure numbers positive - if you're going arithmetic on variable (like in typical loop case).
if you're going bitwise things masks, unsigned starts make more sense. or, if you're desperate positive range taking advantage of sign bit.
personally, signed because don't trust myself stay consistent , avoid mixing 2 types (like article warns against).
Comments
Post a Comment