2 ms·
Would you advocate getting rid of operators altogether? 3.times(2).plus(7) Some things just lend themselves to being expressed in terms of simple operator
by AndrewStephens 3y ago
Would you advocate getting rid of operators altogether?
3.times(2).plus(7)
Some things just lend themselves to being expressed in terms of simple operators.
(*smartPtr)->methodOnWrapperClass();
That is still using the overloaded SmartPtr<>::operator*() method.
I understand the viewpoint that operator overload is syntactic sugar for things that can easily be done another way, I just disagree that costs outweigh the benefits.
- coldpie 3y ago> Would you advocate getting rid of operators altogether? Of course not. It makes sense for built-in types, as everyone reading the code can be assumed to know them. > That is still using the overloaded SmartPtr<>::operator*() method. Good catch ;) > I just disagree that costs outweigh the benefits. Yah, I think that's the disagreement. My feeling is there's a teeny, tiny handful of appropriate places for it (almost entirely math) and it opens up a pandora's box of terrible decisions that programmers clearly find irresistible.
- JonChesterfield 3y agoAre you suggesting 3.times(2).plus(7) as a good thing or a bad thing? I see a.equals(b) occasionally from the first argument is magic crowd but 3.times is novel here. I'm really unsure what the order of operations is for that expression.