- Feature Articles
- CodeSOD
- Error'd
- Forums
-
Other Articles
- Random Article
- Other Series
- Alex's Soapbox
- Announcements
- Best of…
- Best of Email
- Best of the Sidebar
- Bring Your Own Code
- Coded Smorgasbord
- Mandatory Fun Day
- Off Topic
- Representative Line
- News Roundup
- Editor's Soapbox
- Software on the Rocks
- Souvenir Potpourri
- Sponsor Post
- Tales from the Interview
- The Daily WTF: Live
- Virtudyne
Admin
Articles like this make me think:
IF ONLY I, TOO, WERE PAID BY THE LINE !
Admin
I like how the code draws a huge arrow. Also, this code shows that Fred needs to be beat senseless with a copy of the printf(3) man page... at least he didn't create some monstrosity that would result in #include <cobol.h> though!
Admin
You can imagine Fred muttering "Stupid C, why doesn't it have PICs" as he wrote this !
Admin
But that piece of code looks beautiful, it's almost poetry!
Admin
Yes, the arrow is good. Too bad nobody shot Fred with it...
Admin
Nine character fixed width columns, hm. I say Fred was innocent of being a COBOL programmer; he was worse.
He was a FORTRAN programmer.
Admin
Let's see... the <= from 0 onward should be < instead. There also seem to be some missing commas near the end. I won't try to find the other bugs, unless I actually want to get a headache.
Admin
That wouldn't be thick enough to do any damage. Better make it a copy of The C Programming Language, preferably in hardcover.
Admin
fix'd
Admin
Fabricated story? Possibly - specifying "char NinecharString[]" instead of "char[] NinecharString" yields a compilation error in my world at least.
And what about those "embedded minus signs"? Where?
And why would passing a zero to the function yield nulls? There's a "<= 0" test right there...
Admin
The true WTF is php.
Admin
Compilers which don't emit errors when two function names longer than 32 characters clash are an additional WTF.
Admin
On reflection it occurs to me that there's probably an additional bug - how many of the places which call it give a 9-char buffer which will be overflowed by the null terminator?
Admin
Hey! Fred's neighbor and best bud Barney is a programmer too! Who'd'a thunk it?
Admin
Admin
Then your world is not the world of C as was clearly stated in the article.
Admin
Edit: I get it! My name in a nine char string!
Admin
I would have liked to see the fix. :P It's most fun picking apart the "fixed" code. :P
Admin
the char[] NineCharstring statement is C++ specific... unless recent C standards have back ported it from C++
Admin
Admin
The posting makes fun of the long names. Would it be better if this were called "cls" or "cls9"?
Certainly there's a lot better way to write the code. But I thought the comment on long function names to be a cheap shot. Having done some maintenance programming pouring through listings, seeing a meaningful identifier is a blessing, rather than having to go external to the routine I'm studying to figure out what 'cls9" does.
Admin
Also, while the code is awful, it does look beautiful. If you make the font size really small, then turn your head on one side and squint, it looks like the Delta Airlines logo (and you'll look really silly). Perhaps The Daily WTF has started accepting subliminal advertising?
Admin
Admin
You know what I've always liked about a lot of the CodeSODs?
The fact that they (usually) make symmetrical or interesting patterns and in some cases can double for those Magic Eye pictures that were big in the 90s.
Perhaps that's a new determining factor of potentially bad code? Is it symmetrical/does it form some kind of visual pattern or not?
Admin
So his solution didn't include the risky:
I'd love to see what he wrote!
Admin
The char name[] syntax is C and C++, and precisely equal to char * name, just slighly more confusing.
Admin
You mean you write code like the guy in the article. WTF Shame on you :P
Admin
Depends on the font. Where here's a will, there's a 384-point way.
Admin
Admin
Are those negative numbers going to come out looking like 00-12345678
Admin
*/ extern char * Comment( char *Name, char *Poster, int MaxLen, char *Buffer );
Admin
Surprised no one else found the other bug yet.
HINT: It has something to do with formatting 10 with the same number of leading zeros as (and formatting 100 with the same number of leading zeros of as 99 (and formatting 1000 with same same number of leading zeros as 999 ( add additional recursive comments here)))
Admin
Admin
Maybe http://thedailywtf.com/Comments/Fred-Code.aspx#258426?
Admin
That would be a neat trick, since it's the linker that has to detect that two identical 32-character strings from the compiler aren't actually referring to the same thing.
Admin
Probably none. People who write this kind of code live in a universe of fixed-size strings.
I'd imagine the code is used like this:
In other words, the null at the end just gets overwritten by the first character of the next field, except for the null after the last field which is the end of the line anyway.
Admin
Admin
printf ("%.9d\n",1);
Admin
You know, any sensible COBOL programmer would use a library function, eg: printf or one of its equivalents - have you ever programmed in COBOL?
In fact, I strongly doubt a COBOL programmers would have ever written such a piece of rubbish...
However, like many others I'm constantly surprised by the degree of idiocy I see...
...and if this guy was ever a COBOL programmer, then he never got his hands on any real projects...
Admin
Risky indeed! Sprintf only guarantees minimum size, not maximum. You really want snprintf(buf, 9, "%09ld", n). This way instead of memory errors, you'll just get truncated digits. You can even check for truncations by looking at snprintf's return value! (if return value > 9)
Admin
BUT IT LOOKS SO PRETTY!
Admin
Admin
As yanman remarked...it is 'pretty', just not 'smart'. Hey, if pretty DID = smart then Hollywood would have an IQ over 42.
Admin
I don't think that's it. If the output of CLTS gets treated as a C-style string, then his embedded NULL bug will result in output truncation. Since the problem is embedded NULLs in the output file, he has to be treating it as an array of individual characters and assuming it's already the proper length.
So it might look something like:
Admin
camelCase
NotCamelCase
Admin
A decent COBOL programmer would have saved the file with some sort of separator between the numbers (eg commas to create a traditional CSV file).
Then they'd read the lines back and use COBOL's equivalent of PARSE (the COBOL verb is UNSTRING) to collect the individual values into an array.
Simplicity itself. The guy clearly did not know how to do a simple task in any language.
Admin
I'm worried about this line in the article.
Does this say that Bruce wrote a routine that did the same thing as Fred's routine? Why?Admin
Who said Fred couldn't teach him anything?
Admin
Fred's routine would render -10 as "000000-10" instead of "-00000010". Bruce kept that behavior just in case other code was dependent on it.
Admin
Yeah, I buggered up my own example at the last line. Call it memory loss due to PTSD due to having to work with that kind of crap... ;)
Maybe something like:
although the examples I'm thinking of actually used writev(2).