4 ms·
Nim had this same problem a couple of years ago, and it's very annoying. I just checked some stdlib functions and it's still there: https://github.com/nim-lan
by prirun 4y ago
Nim had this same problem a couple of years ago, and it's very annoying. I just checked some stdlib functions and it's still there:
https://github.com/nim-lang/Nim/blob/devel/lib/std/varints.nim https://github.com/nim-lang/Nim/blob/devel/lib/std/varints.n...
For example, in readVu64:
18: proc readVu64*(z: openArray[byte]; pResult: var uint64): int =
24: pResult = (uint64 z[0] - 241) * 256 + z[1].uint64 + 240
28: pResult = 2288u64 + 256u64*z[1].uint64 + z[2].uint64
31: pResult = (z[1].uint64 shl 16u64) + (z[2].uint64 shl 8u64) + z[3].uint64
33: let x = (z[1].uint64 shl 24) + (z[2].uint64 shl 16) + (z[3].uint64 shl 8) + z[4].uint64
I get that there has to be some indication to the compiler to distinguish between doing 8-bit unsigned math vs 64-bit unsigned math to evaluate these expressions. But having such a mish-mash in a stdlib function makes new users think, "There must have been a good reason to do it like this since it's in stdlib, but dang if I know what it is!"
I ran into this myself a couple of years ago when looking at Nim and agree it is annoying, verbose, and ugly to be forced to specify types for obvious integer things.
- SemanticStrengh 4y agoThis is a big reason on why I loosed interest on rust