News for hackers. Stuff that matters.
Re:Lies we tell ourselves to keep using Golang by SeanLuke on Friday April 29, 2022 @10:27AM (#31205595)
I don't know nothin' about Go. But this complaint really surprised me:

> Go not letting you do operator overloading, harking back to the Java days where a == b isn't the same as a.equals(b)

Does this guy really not understand that in a mutable language, (eq ...) is not the same as (equalp ...) and should never be confused with it?

Also: operator overloading is the spawn of Satan.

Re:Lies we tell ourselves to keep using Golang by WalterBright on Friday April 29, 2022 @10:35AM (#31205701)
> operator overloading is the spawn of Satan

I used to agree with you, because of the abuse of operator overloading like iostreams and making DSLs with it. D does support it, but in a way that discourages non-arithmetic uses (such as it won't allow < <= >= > to be overloaded separately).

Operator overloading allows for things like complex numbers, arbitrary precision numeric types, etc., to be done with a library module.

Re:Lies we tell ourselves to keep using Golang by nemo1618 on Friday April 29, 2022 @11:16AM (#31206224)
> Operator overloading allows for things like complex numbers, arbitrary precision numeric types, etc., to be done with a library module.

Why is this desirable vs. implementing those types in the language itself?

I think we've gone down a weird path where implementing things "in userspace" is seen as an inherent good -- why?

Re:Lies we tell ourselves to keep using Golang by WalterBright on Friday April 29, 2022 @11:24AM (#31206332)
> Why is this desirable vs. implementing those types in the language itself?

That's a very good question.

1. It's simpler. In D, we transitioned from a builtin complex type to a library type. It was a happy experience. The simpler the compiler, the easier it is to deal with.

2. Most any programmer can create a library type. Relatively few can modify a compiler to add a new type.

3. It takes the pressure off the compiler team to develop more arithmetic types.

4. Users can add arithmetic types without needing anybody's consent, and can do it right now.

5. It tests and verifies the metaprogramming abilities of the language.

Re:Lies we tell ourselves to keep using Golang by joshuamorton on Friday April 29, 2022 @11:50AM (#31206712)
Elaborating on 3/4: the domain experts don't need to be compiler experts too.

There are always going to be more numeric-like types (int, float, complex, bigint, rational, symbolic-comp types etc.). Numeric vectors that act like numbers are useful (see: numpy), and trying to stick those all into the language is far harder than allowing extensibility.

Re:Lies we tell ourselves to keep using Golang by kaba0 on Friday April 29, 2022 @05:44PM (#31210903)
This is probably the best talk ever on the general topic: https://m.youtube.com/watch?v=_ahvzDzKdB0 [Growing a language by Guy Steele], seriously give it a look if you have the time and do put up with the seemingly strange start.

But at around the end it asks this (paraphrasing): Should a language have complex numbers implemented natively? Should it have numbers module n implemented natively? What about intervals, or rational numbers?

I also dislike the ridiculous overloading of cryptic symbols, but neither extreme is good. Not allowing overloading will give you BigDecimal.of(3).add(BigDecimal.ONE).divide… , while allowing it unrestricted will give you things like msg #!! something. But perhaps a sane middle ground is to allow only basic operators (+,-,*,/) to be overloadable.

Re:Lies we tell ourselves to keep using Golang by delta64 on Friday April 29, 2022 @10:44AM (#31205833)
The author definitely understands that. The point is: when you don't have operator overloading you get stuff like that which does demonstrably confuse many people

In languages with operator overloading this just isn't a concern at all because == does the obvious thing

Re:Lies we tell ourselves to keep using Golang by SeanLuke on Friday April 29, 2022 @01:31PM (#31208235)
> In languages with operator overloading this just isn't a concern at all because == does the obvious thing

And what is the obvious thing? It varies wildly among languages, even within C++ itself.

Re:Lies we tell ourselves to keep using Golang by delta64 on Saturday April 30, 2022 @09:11AM (#31215810)
The obvious thing is to check if the contents are equal. I don't know what cursed C++ you're looking at if you're finding a ton of string implementations not doing exactly that...
Re:Lies we tell ourselves to keep using Golang by AnimalMuppet on Friday April 29, 2022 @01:00PM (#31207708)
== should do the obvious thing. But with operator overloading, it's not clear that it does, unless you need to read the implementation of == very carefully.
Re:Lies we tell ourselves to keep using Golang by delta64 on Saturday April 30, 2022 @09:13AM (#31215837)
How is that any different to some opaque method call? By the same logic `a.equals(b)` might be doing something funky under the hood
Re:Lies we tell ourselves to keep using Golang by AnimalMuppet on Saturday April 30, 2022 @12:51PM (#31217333)
True. But people think about it a bit differently. People don't always expect == to be a function call.
Re:Lies we tell ourselves to keep using Golang by delta64 on Saturday April 30, 2022 @04:03PM (#31218802)
Sure, but I think '== might be a function call' is a lot less confusing than '== sometimes compares for equal value and sometimes doesn't'
Re:Lies we tell ourselves to keep using Golang by jeroenhd on Friday April 29, 2022 @12:09PM (#31207018)
I don't get the problem with operator overloading. Yes, it can be implemented badly, but so can the equals() override. You can't even call a.equals(b) safely in many programming languages because either a or b could be null. I've run into so many null pointer exceptions in Java because someone wrote a.equals(b) when they clearly meant a!=null && a.equals(b).

Every time I have to write `BigDecimal sum = one.add(two).add(three).minus(four)` I cry a little. This is effectively no different from operator overloading and it's what special number implementations in all languages without operator overloading seem to end up doing out of necessity.

Re:Lies we tell ourselves to keep using Golang by josephcsible on Friday April 29, 2022 @10:52AM (#31205940)
Usually you do want to compare by value, so it should get the obvious syntax. When you want to compare by reference, you should write if(&a == &b) or ReferenceEquals(a, b) or something.
Re:Lies we tell ourselves to keep using Golang by ak217 on Friday April 29, 2022 @12:24PM (#31207234)
Without operator overloading, it is basically impossible to adapt a language for numerical computing/data science applications. Yeah, operator overloading is a powerful tool that's easy to abuse; no, it's not optional if you want the language to succeed at all in a whole bunch of applications.
Re:Lies we tell ourselves to keep using Golang by SeanLuke on Friday April 29, 2022 @01:37PM (#31208343)
Mathematica works just fine without user-defined operator overloading.
Re:Lies we tell ourselves to keep using Golang by SubjectToChange on Saturday April 30, 2022 @10:52AM (#31216498)
> Also: operator overloading is the spawn of Satan.

It's necessary for "powerful" generic programming. In fact, the entire reason user-defined data types can be easily used in C++ libraries like CGAL, Eigen, fmt, Kokkos, ranges-v3, etc, is because of operator overloading.

Re:Lies we tell ourselves to keep using Golang by zigger69 on Sunday May 01, 2022 @06:28AM (#31223768)
> Also: operator overloading is the spawn of Satan.

It is. And I'm glad Zig has none of that. `==` only works for primitives and you will never be confused.

Re:Lies we tell ourselves to keep using Golang by oxnrtr on Sunday May 01, 2022 @10:51AM (#31225472)
Not sure that's a good idea. The concept of some types being special should not be something exposed to the user.