Feature request: Path append operators for strings

Jonathan M Davis jmdavisProg at gmx.com
Tue Jul 2 16:06:06 PDT 2013


On Wednesday, July 03, 2013 00:55:59 TommiT wrote:
> So no wonder I was under the impression that we're allowed to
> overload the meaning of operators.

Well, of course, you _can_ overload them to do different stuff. It's trivial to 
make most overloaded operators do something completely different from what they 
do normally. The argument against it is that doing so is bad practice, because 
it makes your code hard to understand. And for some operators (e.g. opCmp and 
opEquals), D actually implements the overloaded operator in a way that giving 
it an alternate meaning doesn't work. You _could_ do it with / though. It's 
just arguably bad practice to do so. But since you can get the same 
functonality out of a normal function without the confusion, it really doesn't 
make sense in general to overload operators to do something fundamentally 
different with a user-defined type than what they do with the built-in types. 
However, some people are really hung up on making everything terse or making 
it look like mathh or whatnot and insist on abusing operators by overloading 
them with completely different meanings.

- Jonathan M Davis


More information about the Digitalmars-d mailing list