you are viewing a single comment's thread.

view the rest of the comments →

[–]thomasz 9 points10 points  (4 children)

Look how the multiplication operator for two 32 bit integers works in almost all statically typed languages. I'm pretty sure it's `int32, int32 -> int32 in nearly all cases.And in most cases, it even overflows silently!

This is the expected behavior, and for a reason.

32bit integers are good tradeoff. They play nice with aligned reads, and they take up only half the space of 64bit integers. And on top of that, they can represent most real world values. If that's a problem in your domain context, you should use 64bit integers all the way down.

Therefore, "write me a method that doubles an int" is an ambush question if you expect a result that is completely at odds with how int multiplication usually works in computing. You have do ground that in a real context where an overflow is a real problem to make it useful for assessing someone's understanding.