Re:Swift: Madness of Generic Integer
by tedajax on Tuesday March 03, 2015 @08:22PM
(#9142118)
Because you're writing code for a computer and sometimes it's expected that you actually care about what the computer is doing with your code.
[ Parent
| on HN ]
Again, would you say the same thing about registers versus stack allocation (or heap allocation)?
"The CPU handles it differently" isn't by itself a legitimate argument against abstraction.
This code is converting a bunch of bytes into an integer by bit shifting. So it's specific to the binary representation of ints in your language, and how types of various sizes and signedness interact.
Note that this doesn't depend on your CPU, but rather on how integers and their byte representations are specified in the language.
I think it's quite reasonable to expect the programmer to know what that means assuming they are writing bitfiddling code like this.