A winning entry in the Intl. Obfuscated C Code Challenge. The source code is in the shape of pi and is full of pi-ity? The program prints the value of e to a number of decimal places.
Am I the only one who noticed that each of the two comments by dbenavidess110 are all one sentence apiece, but without a period (or even a semicolon) at the end? Is there a competition for a one-line (one-sentence) comment?
@yog-sothoth "Now if you teach them how NOT to do things, but how to do them better and more cleanly, then I am 100% in agreement."
That's exactly what we are doing with the code from the contest - using it to teach engineers how NOT to do it. But based on this dicussion here, it sounds like rather than having people do obfuscated code intentionally we have more than enough real-world examples out there to share. The challenge is, of course, finding out how it works and how to fix it.
@BrainiacVI: After I was halfway through my rant I figured that was the case, but continued anyway in case I was mistaken.
It's hard to stop when you are full of righteous indignation and you are in the middle of a good rant ... and then you realize that maybe the other person didn't mean what you thought he/she had meant...
@BrainiacVI I got my satisfaction a year later when one of them had to modify a program he had written and I had to contain my laughter as his expressions cycled between quizzical, astonished, confused, and dumbfounded.
There's that classic old comment: "When I wrote this, only God and myself knew what it did and how it worked... now God only knows!"
BrainiacVI, I was being sarcastic about self documenting code. It was always a joke with my co-workers. Your story makes it clear that documentation is always needed and can save even the author a lot of time and heart ache.
daleetse: Well my code doesn't need them because it is self documenting...
I worked at one place where the "older and wiser" heads told me there was no need to document the code, the instructions told you what it is doing.
I just smiled and keep documenting my code. I had learned my lesson years earlier when I had to throw out about 6 boxes of cards with programs I had written without comments and couldn't figure out what they did.
I got my satisfaction a year later when one of them had to modify a program he had written and I had to contain my laughter as his expressions cycled between quizzical, astonished, confused, and dumbfounded.
Instructions tell the computer what to do, comments tell you why.
Although I must admit I had once written a program in FORTH where I extended the compiler (FORTH lets you do stuff like that) and there was a block that looked like documentation of the OPTO I/O panels but in fact the compiler read it to generate the port addresses and bits within the port I/O byte.
The company I wrote it for brought in FORTH, Inc. to look over the code. FORTH, Inc. told me the majority of the code was vanilla, which I intended it to be, but then they flipped to the I/O declarations and said, "But this was pretty neat."
I think there are a lot of examples of malicious code out there too be counted, but don't quote on that ;), in safe system languages you can tell by module which program behaves well or can behaves bad, honestly saying we write good code anyone can do but in unsafe system languages nobody can proof as unintended acceleration case proves, is a shame we failed to understand that, too bad, people are getting hurt or killed, a shame
I have seen a lot of bad code in my career, but most don't do it out of malice. There may be a few that think it is job security, but they are no longer in the industry... Of course, my code is perfectly readable and maintainable... It's just like writting, why use a big word when a small one will do. And comments? Well my code doesn't need them because it is self documenting...
January 2016 Cartoon Caption ContestBob's punishment for missing his deadline was to be tied to his chair tantalizingly close to a disconnected cable, with one hand superglued to his desk and another to his chin, while the pages from his wall calendar were slowly torn away.122 comments