dmd 2.029 release

Don nospam at nospam.com
Wed Apr 22 06:12:32 PDT 2009


Georg Wrede wrote:
> Don wrote:
>> Georg Wrede wrote:
>>> Walter Bright wrote:
>>>> Lutger wrote:
>>>>> what the hell...this code can't be human.
>>>>
>>>> I was replaced by Colossus years ago.
>>>
>>> Michael A. Jackson wouldn't approve 1175 gotos in 113 files.
>>
>> It'd be really funny to pass it through one of those "code quality" 
>> metrics, one of the ones with a ridiculously heavy penalty for using 
>> goto. I think it'd tell you that DMD source is almost the 
>> lowest-quality code on the planet. <g>
> 
> Yeah. But now I'm getting a bad conscience, this is beginning to look 
> like Walter-bashing... :-)

I think those code quality metrics are ridiculous. The prejudice against 
'goto' is really just brainwashing and totally without basis.

Here's a recent link from Andrew Koenig, who really should know better.

http://dobbscodetalk.com/index.php?option=com_myblog&show=What-Dijkstra-said-was-harmful-about-goto-statements.html&Itemid=29

Can you see his fundamental mistake? He talks about "the program" (just 
as Dijkstra said), but it's just not relevant for C/C++/D/Pascal/...
or any other structured programming language. Wherever he says "program" 
you should substitute "function". And then the force of the argument 
totally disappears.

The problem with goto in an unstructured language is that when you see a 
label, you don't know where it came from. It could be anywhere in the 
entire program (maybe a million lines of code!) And that's a complete 
disaster. But in a structured language, you know it's from somewhere in 
the function.
And this is no different from any other control structure. You ALWAYS 
have to look at the whole scope you're in.

void foo(){
  int n;
bool b = true;
   while (b) {
     if (n==4) {   /* when do we get here? You have to read the whole 
function to find out. Where does n get modified? */ }
:
:
:
   }
}

Heck, even in inline ASM in D, you can't write the kind of spaghetti 
code Dijkstra was complaining about. You always have local scope.

Yet, I personally have been so affected by anti-goto brainwashing that 
I've never used goto in C, C++, or D. But I gradually realised that it 
was just brainwashing. I've never experienced any problem with goto in ASM.

>> Actually, looking through the DMD source it becomes obvious that goto 
>> is really not a problem at all. The lack of comments is much more of a 
>> problem. (Especially with files with names like "e2ir.c". What the 
>> heck is "fltables.c", "cdxxx.c", "elxxx.c" ?). Even so, it's mostly 
>> not that difficult to understand.
> 
> I guess Walter has to keep alternating between ASM, C and D. And a lot 
> of ASM coding is nothing more than a bunch of MOV and JMP stuff. And 
> file naming conventions here look like what one typically finds in 
> development code (before some pre-publishing guy has tidyed it up with a 
> lot of global search&replaces). And, after all, the C files never were 
> meant to be public anyway.
> 
> Actually, the one interesting question might be, would rewriting this 
> code in a structured fashion (I mean, removing the gotos) make it 
> slower? (Not that I'd be suggesting Walter should do it. Just an 
> academic question.)

I doubt it'd affect the speed at all. It'd probably make it longer. 
There are cases in DMD where it seems to make the control flow simpler.


More information about the Digitalmars-d-announce mailing list