News for hackers. Stuff that matters.
Re:"14 Years of Go" by Rob Pike by campbel on Tuesday February 27, 2024 @01:16PM (#39527443)
I'm really not a fan of small qol features like this. I think it really hurts readability for the general audience. The function itself is minimal overhead and is clearer to the reader.
Re:"14 Years of Go" by Rob Pike by anonymoushn on Tuesday February 27, 2024 @01:43PM (#39527838)
That's true, we should get rid of operators for primitives too.
Re:"14 Years of Go" by Rob Pike by campbel on Tuesday February 27, 2024 @01:50PM (#39527941)
Operators for primitive types are fine, they are well defined by the language and consistent across programs. Operator overloading is going to change behavior between programs which puts extra cognitive load on the reader.

That said, Go sticks to the most basic operator implementation (strings, numbers etc...). Go doesn't support `+` on slices for instance.

Re:"14 Years of Go" by Rob Pike by coldtea on Tuesday February 27, 2024 @02:06PM (#39528198)
In better languages they don't exist except as sugar, they're functions themselves.
Re:"14 Years of Go" by Rob Pike by ogogmad on Tuesday February 27, 2024 @01:18PM (#39527472)
The world seems like it's moving to ML. That needs matrices, complex numbers, autodiff, different fixed/floating point types. All four of these need operator overloading.
Re:"14 Years of Go" by Rob Pike by campbel on Tuesday February 27, 2024 @01:22PM (#39527517)
Could you explain _why_ they need overloads and functions don't work? That does not immediately follow for me.
Re:"14 Years of Go" by Rob Pike by ogogmad on Tuesday February 27, 2024 @01:43PM (#39527839)
Autodiff requires interpreting the same piece of code using "dual numbers" that would normally expect "real numbers". This needs operator overloading combined with generics.
Re:"14 Years of Go" by Rob Pike by yangl1996 on Tuesday February 27, 2024 @01:24PM (#39527555)
Your last sentence seems fishy to me. Are you suggesting that support for C++ like operator overloading is a necessary condition for, say, autodiff? I thought Go is a Turing complete language.
Re:"14 Years of Go" by Rob Pike by ogogmad on Tuesday February 27, 2024 @01:44PM (#39527846)
Operator overloading is about syntax and type safety. Brainfuck is Turing complete.
Re:"14 Years of Go" by Rob Pike by campbel on Tuesday February 27, 2024 @01:52PM (#39527979)
I agree it is about syntax. But how is it about type safety?
Re:"14 Years of Go" by Rob Pike by ogogmad on Tuesday February 27, 2024 @04:42PM (#39530409)
You might want the same piece of code to work correctly under different numerical types. Answer: Op overloading + generics.

E.g. Dual numbers for autodiff; 2x2 matrices of quaternions for texture mapping; matrices of differing floating point types for machine learning. Why should I implement the same matrix operations a million times over?