Remix.run Logo
throwawaymaths 2 days ago

$ operator. great idea! i believe the only contender is julia (with "end" but that is a SUUPER awkward keyword since end also closes functions)

> Structs and classes can even overload this operator

nope. fuck, now it's a terrible idea

sedatk 2 days ago | parent | next [-]

> i believe the only contender is julia

C# has "^n" notation that means "length - n". For example:

Take the last element of an array or any other structure that supports indices:

    var a = ar[^1];
Take the last three elements of an array or any other data structure that supports ranges:

    var lastThree = ar[^3..];
bachmeier 2 days ago | parent | prev | next [-]

I don't see why it would be a terrible idea. It's pretty convenient if you're slicing a multidimensional array.

throwawaymaths 2 days ago | parent [-]

except are you sure that's what it's doing? it could have been overloaded. you have to ask yourself that every time.

Doxin a day ago | parent | next [-]

Or you can assume it's implemented sanely. Yes if someone overrides $ and does something wildly wrong with it that'll get confusing. That's the fault of whoever wrote that code though, not of $ itself.

You can also overload +, imagine the mayhem if someone did something weird with that. should we ban overloading operators altogether?

throwawaymaths a day ago | parent [-]

> Or you can assume it's implemented sanely

excuse me, have you spent any time in tech? people fucking love to do clever shit that gets people in trouble. using NULL as a not-pointer value signalling absence (without safeguards) is probably the most notorious -- but at least useful, but if you want to get brain meltingly annoying and pervasive, we dont have to stray too far from the idea of operator overloading; c++'s << operator can just go to hell.

1980phipsi a day ago | parent | prev [-]

I've looked at a lot of D code, and I can't recall it ever being misused.

WhereIsTheTruth a day ago | parent | prev [-]

I'll take this:

    Vec2 result = translation + (rotationMatrix * (scalingMatrix * point));

Over this:

    const result = vec2Add(translation, mat2MulVec2(rotationMatrix, mat2MulVec2(scalingMatrix, point)));
Anytime

And that's a very simple example, in Zig, that kind of equations doesn't scale well, when it comes to readability

ioasuncvinvaer a day ago | parent [-]

A problem that I always run into with code using * for multiplication of matrices is which operation they use. Is it element wise or a matrix multiplication?