Strings in DWT

DBloke DBloke at nowhere.org
Mon Feb 25 13:44:22 PST 2008


> It's a completely different operation that has different semantics. 
> Addition is commutative while concatenation isn't; i.e. a + b == b + a 
> for any numeric type, but a ~ b is not generally interchangeable with b 
> ~ a.
> This comes into play in D's operator overloading as well: if the 
> compiler can't compile a+b as a.opAdd(b) or b.opAdd_r(a) it then tries 
> a.opAdd_r(b) and b.opAdd(a) (i.e. it tries to compile as b+a instead). 
> This transformation wouldn't be correct for concatenations, so that has 
> a different operator that isn't commutative and will therefore skip the 
> second step.
> (see the section "Binary Operator Overloading" on 
> <http://www.digitalmars.com/d/1.0/operatoroverloading.html>)

This makes sense, but not if you are used to Java or C/C++ though not a 
huge problem I admit, it just takes a bit of getting used to. :)
> 

> Does template instantiation also remind you of negation? 
Yep
> Does multiplication remind you of pointer dereferencing?
Nope ;) I always format my code to be readable and understandable now 
and for the future.
> Does bitwise-and remind you of taking an address?
Nope, as above :)
> 
> I don't see the problem with unary and binary use of an operator doing 
> different things as long as the unary meaning doesn't make any sense for 
> binary use and the binary meaning doesn't make any for unary use.

True but the context and formatting of the code should give more than a 
clue, unless you are one of the few people who believe that removing any 
form of unnecessary white space will somehow make compilation faster ;) 
no I kid you not some people I have encountered (usually briefly) 
believe this in C/C++ code and better still we had some guy believing 
that removing every other binary digit in assembly language would make 
the code smaller and lighter for portability ;)


More information about the Digitalmars-d-dwt mailing list