News for hackers. Stuff that matters.
Re:Go 2, here we come by drb91 on Thursday November 29, 2018 @02:00PM (#18562810)
People have traditionally wanted to use the maximum sized type that can fit in a register.
Re:Go 2, here we come by Someone on Thursday November 29, 2018 @03:57PM (#18563937)
More precisely: they wanted the integer type that was large enough and ran their code fastest.

On CPUs with 64-bit and 32-bit registers, that typically is the register-sized integer type. Machines with 16-bit registers are a bit of an edge case, as 16-bit integers may both be a lot faster on them then 32-bit integers and, in many cases, too small)

If go chose to use 32-bit integers as default, some users on 64-bit systems would complain that they couldn’t create, say, an array of 6 billion ints. If they chose 64-bit, some users on 32-bit systems would complain their loops were needlessly slow, and code bloated (why waste 4 bytes of almost every integer in a program?)

Not having generics makes this more of a problem. If go had generics, switching between integer sizes could be a matter of recompilation using a different compiler flag)

A sufficiently advanced compiler would help here, but go doesn’t have one (not exceptional), and doesn’t even aim to have one (compilation speed seems more of a goal than run-time speed)

Re:Go 2, here we come by TheDong on Thursday November 29, 2018 @08:03PM (#18565712)
> Not having generics makes this more of a problem. If go had generics, switching between integer sizes could be a matter of recompilation using a different compiler flag)

Isn't it already the case that you can switch between int sizes with compiler flags?

    var i int
That will be 32 bits if I compile it with GOOS=linux GOARCH=386 and will be 32 bits if I swap in amd64 instead of 386 there.

Is there any language where generics are useful for switching between int sizes? None come to mind offhand, so I don't quite understand what you mean.

Re:Go 2, here we come by user5994461 on Thursday November 29, 2018 @03:17PM (#18563545)
Traditionally the register size was too small, it's very common to have numbers above 256 or 65536. It's not true anymore with 32 bits numbers and a limit of 2 billion.