News for hackers. Stuff that matters.
Re:Announcing The Zig Software Foundation by banachtarski on Saturday July 11, 2020 @06:23PM (#23806663)
Maybe an unpopular opinion among Zig programmers, but the lack of operator overloading is/was the true buzzkill for me as someone that tends to do a lot of math/science work in C and C++ both. Getting operators in C++ is one of the biggest productivity boosts compared to when I work in C.
Re:Announcing The Zig Software Foundation by olodus on Saturday July 11, 2020 @07:40PM (#23807202)
I can understand the annoying part of it if that is the way you would do it elsewhere. Don't you feel that it would to some degree go against zig's goal of as little hidden control flow as possible?

And wouldn't it be possible to create something very close to what you are asking for with a bit of comptime coding? Have the function work on a comptime decided type. I mean I get that you won't be able to use the operator symbols as names and you would lose infix syntax. Is those what you are after?

Re:Announcing The Zig Software Foundation by banachtarski on Sunday July 12, 2020 @10:00PM (#23816467)
I don’t understand that goal I think is the issue. I have no issues with understanding control flow with just... functions and operators? Sure you can’t glean it from a glance at the textual representation of code you aren’t familiar with, but day to day that’s literally never a problem. We have tools for that.

A control flow problem worth solving is understanding async and multithtreaded code.

And yes the expressiveness of actual infix operators is, to me, a strict requirement. The language is for humans, not machines after all, and stuff like add(mul(add(a, b), mul(a, c))) for, say, dual quaternion a, b, and c is a non starter. Most of my code would unfortunately become unreadable and there are often no sensible variable names for those intermediate results.

Re:Announcing The Zig Software Foundation by vanderZwan on Saturday July 11, 2020 @06:46PM (#23806828)
I think it's fine to say why Zig doesn't work for you as long as you make it clear what the limitation is and why, and don't use that as an argument to say it's a bad language - just a bad fit for your particular use-case.

Out of curiosity, aren't there other languages designed with more appropriate expressiveness for your needs then? Julia, for example?

Re:Announcing The Zig Software Foundation by banachtarski on Saturday July 11, 2020 @07:18PM (#23807069)
C++ is actually the sweet spot for expressiveness and complete control needed for the work I do on consoles and embedded devices. I was excited for zig because in many respects it really does feel like a better C, but I think philosophically, it’s more oriented around building particular types of systems. Disclaimer, I’ve sunk only about 35 hours into Zig so it’s possible it would be different with more experience but that’s about all the time I can realistically afford for a trial run of a new technology these days.
Re:Announcing The Zig Software Foundation by meheleventyone on Saturday July 11, 2020 @07:35PM (#23807178)
Personally having done a bunch of mathy things both ways you get used to expressing thing without overloading. On balance I would opt for overloading because it feels natural to me but it’s a niggle rather than anything serious.
Re:Announcing The Zig Software Foundation by matheusmoreira on Saturday July 11, 2020 @07:45PM (#23807236)
Operator overloading leads to a complex binary interface. Avoiding complexity in this area is important given that simple binary interface is a huge reason why reusable software is still written in C.

https://youtu.be/Gv2I7qTux7g?t=2m

Re:Announcing The Zig Software Foundation by asdfasgasdgasdg on Saturday July 11, 2020 @09:16PM (#23807770)
I'm puzzled. Operators in C++ are just function calls. How do they lead to a complicated binary interface? I only watched three minutes of the video but he doesn't talk about operators during that period.
Re:Announcing The Zig Software Foundation by pirocks on Saturday July 11, 2020 @10:10PM (#23808103)
Because you need to specify the types of the operator in the symbol name as well.
Re:Announcing The Zig Software Foundation by tapirl on Saturday July 11, 2020 @10:21PM (#23808177)
But isn't the name is still needed if you define a function instead of overloading the operator?
Re:Announcing The Zig Software Foundation by thayne on Sunday July 12, 2020 @02:41AM (#23809373)
that just means you need a mangled name in the symbol table. I don't really consider that part of the "binary interface". The big problem with this in, for example, c++, is that the name is mangled in an implementation defined way. If the way the operator name is mangled is well specified, there's no reason it couldn't be used as a C function from another language.
Re:Announcing The Zig Software Foundation by matheusmoreira on Sunday July 12, 2020 @08:20PM (#23815882)
> that just means you need a mangled name in the symbol table

That alone is already enough to stop most if not all foreign language interfaces from resolving a symbol to a function pointer. That's the simplest hurdle to overcome. There are also complex mechanisms to deal with such as virtual method tables that figure into the calling conventions of overridable methods. Not even C++ compilers manage to keep the ABI stable between every compiler version: sometimes libraries compiled with a new version cannot be used with software compiled by an old version. Rust doesn't even have an ABI specification yet.

Re:Announcing The Zig Software Foundation by thayne on Monday July 13, 2020 @01:40AM (#23817503)
virtual method tables and operator overloading are orthogonal problems. Sure in many languages operator overloading is done using virtual methods, but it doesn't have to be. Operator overloading can dispatch based on static types rather than dynamic types.

That said, I do wish that there was a standardized way to expose vtables across foreign language boundaries. Although, I understand that differences in how vtables work across different languages, or even different implementations of the same language (cough cough c++ cough cough) would make creating a useful standard difficult.

Re:Announcing The Zig Software Foundation by dnautics on Saturday July 11, 2020 @09:30PM (#23807862)
Ok so (seriously), as an experiment, compile a c++ code file that overloads, say, "+" into a .so file (let's keep it to elf format then) and let us know what the "true" name of the corresponding function is by hexdumping the .so
Re:Announcing The Zig Software Foundation by asdfasgasdgasdg on Saturday July 11, 2020 @11:44PM (#23808622)
Many non-extern C++ names are mangled in .so files, not just operators. I don't see how that affects the ABI (i.e. the calling conventions of the functions). It just means you need to use a library to demangle in order to call the correct function.
Re:Announcing The Zig Software Foundation by dnautics on Sunday July 12, 2020 @02:12AM (#23809273)
Yes, and it is a choice to not support any of them due to complexity. And as a result, you don't get operator overloading.

Zig supports C ABI, not C++ ABI.

Re:Announcing The Zig Software Foundation by asdfasgasdgasdg on Sunday July 12, 2020 @08:21AM (#23810804)
You are confused. Supporting the C ABI and operator overloading are orthogonal. One is about conventions for saving registers and such. The other is about the naming of functions. Zig probably has a principled reason to not support operator customization, but ABI concerns aren't it.
Re:Announcing The Zig Software Foundation by dnautics on Sunday July 12, 2020 @03:07PM (#23813854)
You were the one that brought up C++, so if I'm confused, it's because what you wrote.
Re:Announcing The Zig Software Foundation by asdfasgasdgasdg on Sunday July 12, 2020 @09:39PM (#23816352)
I did bring up C++, but I did not bring up operators. The question at hand is whether ABI concerns prevent operator overloading. Plainly, that is not an issue.
Re:Announcing The Zig Software Foundation by weinzierl on Sunday July 12, 2020 @06:12AM (#23810283)
Just run the hexdump as it is through c++filt and be done. Yes, name mangling is an inconvenience and sometimes it is annoying, but it's not as bad as you make it sound.
Re:Announcing The Zig Software Foundation by dnautics on Sunday July 12, 2020 @03:06PM (#23813841)
and so now you have to add another tool to your toolchain, and if you want to become self-hosting, you have eventually refactor the whole thing, etc... And Zig doesn't generally have plans to support the same types that are available in C++ so realistically the only thing you get is operator and basic function overloading.

And in the C++ community, doing exports for interop as "extern C" (in general, because many other languages prefer it) is accepted anyways. Would you make the choice to add that complexity?

Re:Announcing The Zig Software Foundation by banachtarski on Sunday July 12, 2020 @10:02PM (#23816478)
Very familiar with myriad abi issues and tbh, I don’t care. The compiler managing the mangling means that I the programmer do not. Also, I can easily expose a stable c extern abi from a c++ library but use overloading internally.
Re:Announcing The Zig Software Foundation by nemo1618 on Sunday July 12, 2020 @10:05AM (#23811358)
Part of Zig's core philosophy is that you can readily assess the "cost" of any particular expression is doing. There are no hidden function calls. If an expression doesn't contain (), you can be completely confident that it's not jumping away to some other piece of code.

btw, I know it's not as nice as first-class operator overloading, but Zig's comptime might enable writing DSLs for e.g. vector/matrix math: https://www.reddit.com/r/Zig/comments/g83h12/comment/foleoa8

Re:Announcing The Zig Software Foundation by banachtarski on Sunday July 12, 2020 @10:06PM (#23816494)
Comptime is certainly nice but not usable in this context I’m afraid.

Also I’ve heard that argument a ton. It’s total complete rubbish as far as I’m concerned. Extrapolating, if you see a function call, what really can you say about the “cost” of that function? To me, without actual investigation, the answer is zilch. The function might be inlined, in the i-cache, referencing a lazily loaded symbol. It might be a small function, it might be huge, it may flush the cache, idk. If the goal was to be able to estimate the performance at a glance, well, we should use assembly, and even then the performance isn’t always clear.

Re:Announcing The Zig Software Foundation by networkimprov on Saturday July 11, 2020 @11:00PM (#23808412)
This is a good point.

The right way to do this is to support arithmetic operators for types that implement a specific interface.