News for hackers. Stuff that matters.
Re:Why Zig over C for Systems Programming by bunderbunder on Friday November 13, 2026 @12:43PM (#50487009)
I’ve also experienced some unnecessary shenanigans related to blurring the distinction between primitive operations, and stuff that happens dynamically at run time such as method calls.

For a somewhat different example of the same general idea, look at how Java handles primitives and their boxed counterparts. = on two ints always compares their value. = on two Integers compares their pointers. But it uses flyweight instances for values up to 256, so in Java, whether two Integers with the same numeric value are equal according to the = operator depends on what that value is.

Then throw autoboxing and generics into the mix, and it suddenly becomes very easy to do refactorings that work fine in the unit tests (which tend to use small numbers) but fails in confusing ways in production.

This isn’t an example of operator overloading, of course. But I hope it more simply illustrates why, at least in certain problem domains, there’s value in being able to visually tell when surprising runtime shenanigans are and are not possible. And also to make it impossible to cross that boundary without touching all code that falls within the blast radius of that change.

Re:Why Zig over C for Systems Programming by wpollock on Friday November 13, 2026 @01:25PM (#50487640)
> But it uses flyweight instances for values up to 256, so in Java, whether two Integers with the same numeric value are equal according to the = operator depends on what that value is. ...

I believe Java caches Integer objects for values -128..+128, not 256. But that may be an implementation detail, and not something to count on.

Re:Why Zig over C for Systems Programming by gf000 on Friday November 13, 2026 @01:34PM (#50487779)
And since java 28's value types, == will work identically for all Integers, finally.
Re:Why Zig over C for Systems Programming by wpollock on Friday November 13, 2026 @03:08PM (#50488943)
[delayed]
Re:Why Zig over C for Systems Programming by bunderbunder on Friday November 13, 2026 @01:43PM (#50487894)
No, you’re right. I misremembered.
Re:Why Zig over C for Systems Programming by wpollock on Friday November 13, 2026 @02:59PM (#50488846)
> No, you’re right. I misremembered.

We both misremembered. I found where this is documented and the range is -128..127 inclusive: <https://docs.oracle.com/en/java/javase/27/docs/api/java.base...>