x.sizeof vs typeid(x)

Tom S h3r3tic at remove.mat.uni.torun.pl
Fri Feb 8 06:30:56 PST 2008


bearophile wrote:
> Tom S Wrote:
>> Well then, the whole C++ committee is following bad practice as well, by 
>> making << and >> work with streams.
> 
> Right, a committee too can take bad choices, that operator usage is very unnatural, and it will always be for a C-based language.

But perhaps there was no way to make it look better?


> Operator overloading is useful, but like with all the situations where you have more power, you need more control too (this will become very clear when D will have macros. They will require a very strong self-discipline from the programmer, otherwise they will lead to big problems, mostly at the level of *language community*, and not at the level of single program. I have explained this in my 4th post of notes).So you have to use them avoiding to change their original semantics too much. Otherwise code becomes a jungle that a different programmer can't read well.

You've also stated that the programmer doesn't have to understand what's 
going on inside a standard lib (as long as it reads well and is 
consistent across its span). The code of mine which spawned this 
discussion is to be used like a standard lib for interfacing with 
OpenGL. Same situation. And it doesn't abuse operator overloading 'too 
much'. It's just one specific construct.


> As far as I know Java outlaws operator overloading essentially to avoid that class of problems. Java success comes from it being good for the *community* of Java programmers, and not just for the single programmer. Making the language simple and regular allows everyone to understand code written by others, and modify it, share it, etc.

Disclaimer: I don't like Java.
// It also is a total PITA to write.


> It also allows firms to take young programmers and use them to manage legacy Java code, etc,

// I'm grateful for that. Otherwise thedailywtf.com would lose half of 
its sources.


> it allows to *lot* of less good programmers to use the language, like most of the people that today are using Processing, a graphics processing language that is essentially Java with few libs and some added sugar.

If Java was so great, why did Processing need the extra sugar? 
Similarly, I don't want to use something different from D to write my 
code because just I feel like having more sugar. D can provide it as well.


> You can also read this section, it says right things:
> http://en.wikipedia.org/wiki/Operator_overloading#Criticisms

It also highlights that there are two sides in the debate. And it 
doesn't seem like the discussion ever ends, so I'd rather leave this 
thread as is and not let it turn into a complete flame war ;)


> Note that DSL (Domain Specific Language) isn't something mostly for scripting languages, they come from Lisp (and Forth too, probably) that can be compiled into a normal executable. D with macros will be fit for that too.

That was also my point


-- 
Tomasz Stachowiak
http://h3.team0xf.com/
h3/h3r3tic on #D freenode



More information about the Digitalmars-d mailing list