Hacker News new | ask | show | jobs
by ogogmad 18 days ago
Sure. But doesn't it still lack autodiff, quaternions, etc?
2 comments

In C++, the practical AD approach for large existing code-bases is operator-overloading. Swapping double for an active class, overload all math operations for this type, recording the computational graph on a tape, and then run the tape backwards for computing derivatives. This only works because operator-overloading and templates are language features.

Zig has no operator overloading, so tape-based AD means rewriting arithmetic as functon calls. Its compile-time code gen could instead do source transforamtion (like Enzyme / Tapenade, etc), which is a different trade-off.

Concrete example: With operator-overloading in C++, the Black-Scholes d1 expression, a statement with 5-inputs and 10 math operations, can be recorded with 10 nodes and operand links on tape. If adding expression templates, this reduces to a single tape entry function call, the rest is handled by the compiler. And the code is still readable like the original with double type.

Yes, there are definitely other use cases that Zig doesn't support (which some may view as a good or bad thing). I just wanted to respond to the comment about basic SIMD since the example was U8x32 and operator+, which Zig can do.
Point wasn't about SIMD, but defining my wrapper for it and giving it operations I needed.

Which seems to be something Zig can't do.

Hell, you can define operators for generic length SIMD lane.

It's not that Zig can't do it; Zig has been carefully designed to prevent it from being done as one of its core values, which is something that's important to some people just as the ability to do it is important to some other people. Supporting it or preventing it both have pros and cons for different users and different uses.
Sure Zig is pre-1.0 it can do anything but it's not going to do anything (e.g. add a borrow checker that closes the possible memory unsafety issues. They will add a runtime checker via Fil-C though)

The issue is the mindset, "I (Zig creator) don't need it nobody else does."

That's not what I wrote. I said Zig is carefully designed to disallow overloading because that's what some of us want (and there are Zig-specific reasons to want that even more). You, however, seem to be of the mindset that if some set of people want a feature, every language should have it, but that is clearly untrue. Something many of us value (especially in low-level programming, but not just there) is simplicity, which is the one feature you can never add to a language once you lose it. In every product, including programming languages, what features you don't allow in is just as important as the features you have. What made the iPhone the iPhone wasn't that it had a touchscreen, but that it didn't have a physical keypad.

In the case of Zig this is especially glaring and a core aspect of its design. In my low-level work, partial evaluation (or "compile-time code generation") is very important, and both C++ and Rust have it, albeit inelegantly. The problem is that they both bring with them the complexity I try to avoid. Zig is special because it offers all that power in a simple language, which is what many people want.

Different programmers want contradictory things out of programming languages, and it's impossible to satisfy all of them. Some people want to use a language with operator overloading, while others want to use a language that doesn't offer operator overloading. They can't be using the same language.

> Something many of us value is simplicity

Simplicity is a good metric but a lousy goal. If simplicity was a good goal, Brainfuck dialect would be the most used language.

> Different programmers want contradictory things out of programming languages

True to an extent but there are universal qualities every good language shares.

Ease of use; good performance even in naive cases; good safety/security even in naive cases; expressivity; fast compile times; conciseness.