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.


Comments (11)

  1. Alan Yeung says:

    When I own a big enough house, it’s always good to have a wife/maid/housekeeper/mom? to clean up for me. Though they may not put things where they should be or at the right time, I have more time to do other things (web surfing, watching baseball, etc.).

    Of course, I have a complete control where the things go (especially in my room) if I clean up myself, but that’s not cost effective and is time consuming (plus I may end up doing nothing good).

  2. I just started working for a company that makes an ERP system for Mac and Linux. Windows is also supported, but since *everyone* within the company i against *everything* Microsoft, it is not working very well. This product is coded in pure Ansi-C. What you describe is the exact opposite of what I am experiencing right now; for 6 years I’ve been working with ATL and Java, creating a Web Services platform for another (much larger) ERP system. Now I’m facing the crude, raw, Metallica-like C, after being really accustomed to the safe, comfortable Java (and, in comparision to pure C, the easy and productive ATL). It is really fun to experience this. To convince everyone that there are easier things than C. To show there are more productive environments. To prove there are safer ways of coding out there. Is is kind of cool – and easy – to show off high-quality stuff, when the bar is set at C. (Just imagine showing off the full application running on top of the CLR, after 30 minutes of work! Why *oh WHY* isn’t the switch called /IJW any longer?!) What really amaze me though, is that there are people out there, in 2004, thinking unmanaged code is better than managed (be it Java or .NET or whatever) for these kinds of systems. I simply don’t understand how anyone can believe that. It’s just wrong. Evil, almost.

  3. Matt,

    ansolutely the same thing over here. we’ve got some large portions of c/c++ in our codebase, and looking at that makes me shiver. there’s a strong urge to drop it altogether and rewrite….


    thomas woelfer

  4. Matt says:

    Uh.. sure.. you know.. it stinks.. 🙂

  5. Matt Warren has a good post on his journey from being an unmanaged to managed code developer. His description of looking back into the unmanaged world describes my feelings exactly:Years later, with lots of experience working in managed environments, Java…

  6. tim scarfe says:

    "But even as a sample it was so flagrantly bad it was dangerous."

    Hillarious! I wish I had your gift with words.

Skip to main content