Hacker News new | ask | show | jobs
by skylabmelody 321 days ago
I would suggest to never use unsigned int for values that will involve any sort of calculations on them (health, damage, speed). This is considered bad practice due to overflow and should be avoided, with the exception of values that are used for UIDs, indexes, bitfields, mask and flags.
1 comments

Nah it's just whatever is most appropriate for your implementation. Overflow and wrap around is possible whether you use signed or unsigned.

As I say to some more junior devs, check whether the maths is correct and then do it, don't do it and then check if it was wrong

My suggestion is straight from the C++ guidelines by Bjarne Stroustrup and Herb Sutter (ES.102: Use signed types for arithmetic), for reasons that you don't seem to grasp.
There's a reason they're guidelines and not rules. Use whatever is most appropriate for your use case