Design Con 2015
Breaking News
News & Analysis

Celebrating, Not Cursing, Convoluted C Code

6/12/2014 02:15 PM EDT
26 comments
NO RATINGS
View Comments: Threaded | Newest First | Oldest First
DrFPGA
User Rank
Blogger
Double Prize
DrFPGA   6/12/2014 4:40:46 PM
NO RATINGS
I think you should shoot for a double prize and submit here too:

http://columbiaspectator.com/multimedia/arts-entertainment/2013/11/16/bad-poetry-contest 

Wnderer
User Rank
CEO
The Spoiler Explains It? LOL
Wnderer   6/13/2014 5:41:24 AM
NO RATINGS
That spoiler gives somes hints but not an explanation and the spoilers point 2 is just confusing.

Here's an explanation.

http://www.cprogramdevelop.com/1448772/

 

 

Yog-Sothoth
User Rank
Freelancer
Re: The Spoiler Explains It? LOL
Yog-Sothoth   6/13/2014 10:17:36 AM
NO RATINGS
What a pointless waste of time! A competition to write the best readable code would be better than one to write deliberately unreadable code.

kfield
User Rank
Blogger
Re: The Spoiler Explains It? LOL
kfield   6/13/2014 10:42:25 AM
NO RATINGS
@yog-sohoth: I don't view it as a waste of time, as the article points out, the winners are incredibly talented programmers and if this content is used as a teaching tool (which we plan do to at our event next year) it's an extremely powerful way to learn: By seeing how NOT to do things and why. Plus, we'll teach programmers techniques for fixing poorly written code, which I'm sure we've all run into at some point in our careers!!!

Yog-Sothoth
User Rank
Freelancer
Re: The Spoiler Explains It? LOL
Yog-Sothoth   6/13/2014 11:05:37 AM
NO RATINGS
@kfield: If you teach people how to write obfuscated code just for fun, chances they will use it one day - maybe they are being taken off a project, maybe they are getting fired, who knows?


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.

I have seen some code where a subsequent maintainer added the comment 'the f*****r who wrote this should be shot', and indeed it was truly unreadable. And also the opposite, where the code was elegantly written and comments just enough to it was simple to understand, and also admire. I know which coder I would hire.

daleste
User Rank
CEO
Re: The Spoiler Explains It? LOL
daleste   6/14/2014 5:48:54 PM
NO RATINGS
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...

dbenavides110
User Rank
Rookie
Re: The Spoiler Explains It? LOL
dbenavides110   6/14/2014 9:34:16 PM
NO RATINGS
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

BrainiacVI
User Rank
CEO
Re: The Spoiler Explains It? LOL
BrainiacVI   6/14/2014 11:55:14 PM
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."

Made my day.

daleste
User Rank
CEO
Re: The Spoiler Explains It? LOL
daleste   6/15/2014 12:21:52 PM
NO RATINGS
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.

BrainiacVI
User Rank
CEO
Re: The Spoiler Explains It? LOL
BrainiacVI   6/16/2014 1:01:18 PM
NO RATINGS
daleste: I was being sarcastic about self documenting code.

After I was halfway through my rant I figured that was the case, but continued anyway in case I was mistaken.

But yeah, pretty funny.

I used to point out to my colleagues the end of my S/370 Assembly compiles where it would say, "No errors found." as to why I knew my code was bug free. :-)

Max The Magnificent
User Rank
Blogger
Re: The Spoiler Explains It? LOL
Max The Magnificent   6/16/2014 1:12:35 PM
NO RATINGS
@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...

Max The Magnificent
User Rank
Blogger
Re: The Spoiler Explains It? LOL
Max The Magnificent   6/16/2014 1:09:55 PM
@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!"

kfield
User Rank
Blogger
Re: The Spoiler Explains It? LOL
kfield   6/23/2014 10:59:21 AM
NO RATINGS
@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.

Max The Magnificent
User Rank
Blogger
Re: The Spoiler Explains It? LOL
Max The Magnificent   6/13/2014 11:08:54 AM
NO RATINGS
@Yog-Sothoth: What a pointless waste of time

Hi Yog, what's one of the Outer Gods doing here on EETimes. The last I heard, you were described as: "congeries of iridescent globes, yet stupendous in its malign suggestiveness" -- and this was from someone who liked you.

I was going to say one can only hope that time has tempered your disposition ... howrever, reading your comment, I fear this is not so.

Personally, I think that anything that makes people think is a good idea -- and this type of thing certainly makes you think. Actually, when you do come to think about it, doing something badly when you know how to do it well is pretty difficult, like a brilliant singer trying to sound like someone who can't sing ... it's not as easy as it sounds (no pun intended).

Similarly, it's easy to write bad code if you don't have a clue (like me), but writing truly bad code when you are a good programmer takes some effort -- we're not talking about ordinary bad code here -- we're talking about code that would cause another good programmer to cringe at its awfulness.

mhrackin
User Rank
CEO
Re: The Spoiler Explains It? LOL
mhrackin   6/13/2014 4:47:41 PM
NO RATINGS
Gee, Max, I thought the reference to beer and bacon would have you as the very first to sign up!  I'm completely disqualified in any case, as I gave up trying to master C syntax back in the mid-'80s.  I can read it, but no way can I write any C code!

Max The Magnificent
User Rank
Blogger
Re: The Spoiler Explains It? LOL
Max The Magnificent   6/13/2014 5:10:28 PM
NO RATINGS
@mhrackin: I can read it, but no way can I write any C code!

We were made for each other! I can write it, but no way can anyone else understand what I have written! LOL

mhrackin
User Rank
CEO
Re: The Spoiler Explains It? LOL
mhrackin   6/13/2014 5:31:11 PM
NO RATINGS
Serendipity!  You just connected a couple of things in my head and inspired another entry in the June Caption contest!  You can likely figure out which one.....

Max The Magnificent
User Rank
Blogger
Re: The Spoiler Explains It? LOL
Max The Magnificent   6/13/2014 5:38:28 PM
NO RATINGS
@hrackin: You just connected a couple of things in my head...

What? My hands never left the ends of my arms!

Max The Magnificent
User Rank
Blogger
No experience could be worse...
Max The Magnificent   6/13/2014 10:53:00 AM
NO RATINGS
No experience could be worse, except maybe sticking pins in your eyes.

Hmmm -- have you tasted my ex-wife's cooking?

BrainiacVI
User Rank
CEO
Got to look at that >stuff< everyday
BrainiacVI   6/13/2014 2:57:27 PM
NO RATINGS
A company I worked for had finally brought in-house the software that some consultants had written. We used to joke that all the developers there were regular contributors to the C Obfuscation Awards. Most of the code was unreadable. The first thing you were taught was "Names mean nothing", just because the subroutine was named "Print", does not mean it would ever get around to doing any. My favorite piece of code I had to unravel was named "DoSomething" with parameters A, B, C, D, E, F, G, H and no comments in the alphabet soup that followed. Subroutines would do 10 different things, but would be called because they were only interested in 2 of them, and hoped the other 8 did not have any adverse effects. A colleague and I traced one subroutine down 25 levels of calling such garbage and never hit bottom. By then we had absolutely no idea what the intent of the function was at all.

Sorry for the rant, but some people see this as being "clever" when they are coding.

betajet
User Rank
CEO
Re: Got to look at that >stuff< everyday
betajet   6/13/2014 3:40:33 PM
NO RATINGS
Brainiac VI wrote: some people see this as being "clever" when they are coding.

I would venture to say that some people regard this as "job security".

It's like Car Talk's director of guaranteed repeat business "Lucinda Boltz".

BrainiacVI
User Rank
CEO
Re: Got to look at that >stuff< everyday
BrainiacVI   6/13/2014 4:58:40 PM
NO RATINGS
Yeah, we always thought their argument before management wised up was whenever anyone complained about the code being unreadable that they would counter that it meant the complainers were not geniuses like their programmers that could understand it.

After my team cleaned up the code, one of the vice presidents had to call us to ask how to logout. In the previous seven years of development, it had never stayed up long enough for him to need to do that.

dbenavides110
User Rank
Rookie
Re: Got to look at that >stuff< everyday
dbenavides110   6/14/2014 10:57:00 AM
NO RATINGS
I think this celebration degrades the value of intelligibility of code, either by another human of an agent like a checker, in terms of beautifilness it looses to attractive solutions like Algol-like familiy of languages, the value is in succinteness, and I perceive due VLSI developments this is relevant only to microsystems, like embedded market, but as the number of devices that govern our lifes depend on those products we must make sure we make the right choices to program a device so if anything happens and then you have a crash that kills a passanger, you are able to tell what war with exact detail the issue and who was responsible of that piece of code, if not this is not engineering and just bad art

Stargzer
User Rank
CEO
Re: Got to look at that >stuff< everyday
Stargzer   7/24/2014 11:09:11 AM
NO RATINGS
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?

dbenavides110
User Rank
Rookie
Re: Got to look at that >stuff< everyday
dbenavides110   8/5/2014 10:00:55 PM
NO RATINGS
I think would be redundant at the end, so is the semicolon just needed for lame compilers If I'm not mistaken, which means this convoluted line is one piece out of place of code, cheers ;)

betajet
User Rank
CEO
A clear case of "APL Envy", IMO
betajet   6/13/2014 6:19:49 PM
NO RATINGS
I think the IOCCC is a clear case of C programmers' envy of APL programmers, who get to write obfuscated code all the time in what is widely regarded as a write-only language.  In APL, you can write a prime number generator in 17 characters -- some of them pretty peculiar -- or generate Pick Six lottery numbers in 10 characters.

I like to write clear, easy-to-maintain code most of the time.  When I need a write-only thrill, my language of choice is sed.

Radio
NEXT UPCOMING BROADCAST
EE Times Senior Technical Editor Martin Rowe will interview EMC engineer Kenneth Wyatt.
Top Comments of the Week
Like Us on Facebook

Datasheets.com Parts Search

185 million searchable parts
(please enter a part number or hit search to begin)
EE Times on Twitter
EE Times Twitter Feed
Flash Poll