共用方式為


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

Comments

  • Anonymous
    September 17, 2004
    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).
  • Anonymous
    September 17, 2004
    The comment has been removed
  • Anonymous
    September 17, 2004
    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....

    WM_MY0.02$
    thomas woelfer
  • Anonymous
    September 19, 2004
    fragrantly ?
  • Anonymous
    September 19, 2004
    Uh.. sure.. you know.. it stinks.. :-)
  • Anonymous
    October 05, 2004
    muahahahhaahhaahhahah
  • Anonymous
    October 07, 2004
    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...
  • Anonymous
    October 16, 2004
    "But even as a sample it was so flagrantly bad it was dangerous."

    Hillarious! I wish I had your gift with words.