logoalt Hacker News

stousettoday at 4:08 PM2 repliesview on HN

All this just to prevent people from using + - * / and ^. Why?


Replies

AnduCrandutoday at 8:16 PM

It's appealing to people who want to understand and control everything they're doing. When I'm using pandas or SQLAlchemy, I have no idea what the code is actually doing. Most people don't care about such implementation details, but some people do.

smj-edisontoday at 4:47 PM

Andrew talks about it because it introduces hidden control flow where you're expecting simple operators. In Zig anything that deals with control flow is a keyword (including short circuiting and, which is `and` instead of `&&`).

I'd argue though that the real disadvantage to having overloadable arithmetic is that you're limited to one implementation. This is actually my biggest beef with Rust, namely traits/type classes. It locks you into a single implementation when you may want to do something different based on the context. Zig pushes the dispatch decision to the callsite, not a trait subsystem (see how Zig implements hash mays for example). So I'd personally prefer to use a DSL, since it lets me specify what type of dispatch to use.

show 1 reply