top | item 44743780

(no title)

skylabmelody | 7 months 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.

discuss

order

ChrisRR|7 months ago

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

skylabmelody|7 months ago

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.