Useless use of goto
Someone showed me some beautiful code, that happens to be procmail's. I'm really impressed :
goto jiasc;
do
{ *++to= *++from;
jiasc:;
}
while(--count);
I suggest anyone to take a look at procmail's source code, it's really a thrill.
2008-01-23 08:59:19+0900
Both comments and pings are currently closed.
2008-01-23 09:41:47+0900
don’t understand this “goto” statement?
2008-01-23 09:46:42+0900
I fail to see how it differs from:
while (–count) {
*++to = *++from;
}
Not to mention that the code does not do what one would expect with count of 1 (or worse, 0). Nor do I see the logic behind not using memcpy.
2008-01-23 09:50:47+0900
It’s equivalent to:
while(–count) { *++to = *++from; }
Which is the same as:
to += 1;
from += 1;
memcpy(to, from, count);
to += count – 1; // may be negative if count = 0
from += count – 1;
count = 0;
Why anyone would write such a thing is beyond me.
2008-01-23 09:53:32+0900
My mistake, the original code does nothing sane if count == 0. Add a count–; to the top of my code.
2008-01-23 09:59:38+0900
and the to–; from–;
With all the register keywords being thrown about, you’d think that the writer is attempting to achieve performance. A saner implementation is in lib/string.c in the kernel.
2008-01-23 10:17:46+0900
Yes, the procmail source code is really horrible… until a year ago or so, GNU indent crashed on it trying to indent it.
2008-01-23 12:08:03+0900
I looked at the procmail source code in about 1997 and shortly afterwards I stopped using it in disgust.
2008-01-23 17:16:37+0900
Speaking of beautiful code, I kind of like apt’s way of using booleans:
if (match.filematch(f) == true && fixed[f->id] == false)
Reminds me of first year computer science students.
2008-01-24 04:14:47+0900
The last time I looked at the procmail source code (also about 1997) I came away with the impression that it had been mechanically translated from assembly language.