Tuesday, May 27, 2008

Does knowing C make you a better programmer?

Joel and Jeff had a conversation about the merits of knowing how to program in C.  Joel's take was knowing how to program in C makes you a better program.  I'm in that camp, with some other people (Darren and Eric).

After college, I did mostly C programming.  That was back in the days when 640K wasn't the punch-line to a joke, but a real limit that drove you nuts.  Having a good working knowledge of C gave you a better understanding how memory was allocated and how it was used.  Pointer arithmetic was part of the natural order of programming.  It made you a careful with what you allocated and how you managed it.

There's a still a place for unmanaged code, whether it's C, C++, Delphi, or some other language.  You get a lot functionality with managed code (more ways of accessing data, garbage collection, etc), but there's no free lunch and there's a substantial footprint for each process that uses the .NET Framework.  I'm typing this with Windows Live Writer, an app that's written for the .NET Framework.  It's using 54MB right now as I type.  That's a lot of memory for a WYSIWG blog tool.  Just because you have a garbage collector doesn't mean that it's being used effectively.  It's still good to clean up after yourself and a good C/C++ programmer does that.

Eric Sink compared knowing C with knowing Morse code.  It's a flawed argument in that Morse code is not the underpinnings of the technology that came after it, but it's close enough to the spirit of the argument to have some merit.  My dad learned Morse code 30+ years ago when he got his ham license.  It was a big deal back then and you couldn't get your ham license with being able to demonstrate your proficiency with Morse.

Once he got his license, he rarely if ever used Morse to send out a message.  But every now and then, he would pick up a faint signal that had bounced around the ionosphere and it would be in Morse.  He would sit at his radio and pick out the words that of the dashes and dots.  

But how can you use that analogy to demonstrate the value of C to a managed code programmer?  For many programmers, I'm sure it doesn't mean anything to them.  If you are just doing web programming for some giant LOB app, only knowing VB.NET or C# probably isn't much a of a liability.

On the other hand, If you do any P/Invoke work, you'll calling DLLs that were mostly written in C or C++.  Having a knowledge of those languages makes it a little easier to understand the data structures and calling conventions used by the DLL.  If you working with binary data that came from unmanaged code, knowing how that data is represented in it's native environment will make it easier to understand what it is and how to use it.

Darren Stokes made the assertion that programmers who know C seem to solve complicated problems faster than those who don't know C.  I don't know of you can make that case.  With the push to teach only managed code at school, the programmers that came up knowing C are a bit older than the programmers who don't know C.  That programmer who has the C experience is probably someone who has been around longer and has that much more experience to draw from.  I wonder if anyone has down any actual studies that compare the level of productivity from programmers with C experience compared with programmers that only know only managed code.

3 comments:

  1. it is useful to know C as it is also useful to know compilers. It isn't mandatory and not that much use, but a better understanding of whats actually going on is good in my book. Helps me debug things better

    ReplyDelete
  2. Hi Tim,

    Did you mean how a compiler works in terms of how is parses the source code, or did you mean how it generates the compiled code?

    The former is good know if you have deal with text parsing. The latter is probably more important if you are trying optimize your code or determine why production code is behaving differently than the code in your debugger.

    ReplyDelete
  3. I think your right in both cases. I remember one incident where 3 of us were trying to optimise some code and one of us hadn't done compilers. They were just voodoo to him, so he didn't get it when we were discussing the heap vs local variables.

    ReplyDelete

Note: Only a member of this blog may post a comment.