Code Shock

The first time I ever saw code written in Java, it scared me.  The code looked awful.  I mean it.  There was no way this stuff could be for real.  The source code I saw looked as bug prone as anything I could imagine.  There were 'new's flying around everywhere, no clean up code, no error cases, no asserts, no assumptions, no sanity checks what so ever.  I wondered what kind of novice wrote this stuff.  I mean, it looked like something that was written by a computer science prof.   

You obviously couldn't ship code like that.  But even as a sample it was so flagrantly bad it was dangerous.  I had downloaded the code to take a look at it.  (Those were my pre Microsoft days.)  I thought it sounded cool and new and I'd give it a look, yet after wading through the quagmire of source for only a few minutes I was certain that I'd never give it another look again.  So I walked away from it that day, turned of the PC and left it behind.  

Fortunately, I changed my mind.

You see, what had happened was that I looked at that source through the eyes of a professional C programmer, and everywhere I looked I saw all the rules being broken.  The language looked like C, sort of, so it had to behave like C, right?  Wrong!  I had let all my assumptions get in the way.  There were new things going on that I had not even considered.  The next time around I dove into the language spec and learned about the garbage collector, the exception handling, the pcode validator, etc, all these things that when added together gave you something quite different.  That code I had scoffed at on first inspection had in fact been abiding by all the rules.  The rules had just changed, that's all.

Years later, with lots of experience working in managed environments, Java and .Net, I've grown accustom to all those services and practices that at one time seemed not only alien, but flat out wrong.  Now, I find myself completely on the other side of the fence.  I find myself now looking at C code, unmanaged, raw, savage, and I cringe.  Not because the code is poor or violates any rules, it's just running without the safety net.  Whenever I see a fixed sized buffer on the stack, a flurry of asterisks or even an innocent looking 'new', I get a bit nervous.  I start to wonder if the code was written correctly, if all the cases were handled, and if some errant state in a far off function will suddenly go astray, launching the processor into a tantrum, wreaking havoc across the codescape, a whirlwind of destruction that will quickly lay waste to even the cleanest lines of logic.

Matt