Hacker News new | past | comments | ask | show | jobs | submit
Here is a crazy idea, don’t use operators, just use functions.

Operators cause issues because it is not possible to cleanly express error output from an operator, it is not possible to express the bit-width of the operation, have to understand precedence.

All of these issues cause other downstream issues.

Why not add_u64()?

Because it's ridiculously verbose. Abbreviating extremely common operations makes code far easier to read and understand than not.

> have to understand precedence

Precedence is not in any way an argument against using operators; you could disallow precedence at all (eg. each expression must have at most one operator, or rather two counting the assignment operator) while still having operators. That said, precedence is also very beneficial to readability when not abused.

> Operators cause issues because it is not possible to cleanly express error output from an operator

Incorrect. An operator can simply desugar to functions, and therefore has the exact same error semantic possibilities. If you take issue with a language not returning errors from operators, that is a language design issue, not something inherent to the existence of operators.

The amount of times I've been sad that multiply or sum are longer than + or * is limited to long formulas and even then it's a non issue.

Also, functions can be used as callbacks, and offer overloads to handle partial applications with ease, pipe(2, sum(3), multiply(2)), e.g.

loading story #50377457
loading story #50377494
loading story #50377567
loading story #50377458
loading story #50377395
Personally I think the meaning of + and * should be context dependent.

Though the main reason for infix notation is to signal associativity. Which a lot of these don't satisfy.

A lot of these are just trying to mimic natural language, which can be useful but as lisp demonstrates is not that important if the grammar is clear enough.

Zig sometimes gives you this, for example there are @divCeil, @divTrunc, @divExact, and @divFloor built-ins so that you can be more precise in your intent compared to using "/". It's rather simple to then write a linting rule that fails if you ever have a literal "/" in your codebase.
{"deleted":true,"id":50377479,"parent":50377146,"time":1793874402,"type":"comment"}
...and while at why not also dump the assignment and indexing operators!

    assign(result, add(b, mul(c, sub(d, e)), add(add(f, g), array_get(arr, i)));
(I bet I messed up the parentheses somewhere).

At that point, even assembly code is more readable. Also there's a reason why Lisp and Forth haven't exactly taken the world by storm ;)