Home arrow Blog arrow Embedded arrow Real Men Program in C
Real Men Program in C | Print |
Written by Akiba   
Monday, 03 August 2009

I stumbled upon an interesting article from Embedded.com today called "Real Men Program in C" . It highlights one of the biggest paradoxes occurring in the embedded space, which is that the embedded field is growing, C is becoming the dominant language, and the amount of programmers that can program in C is shrinking. The reason for this is that C is rarely taught in universities anymore, most likely due to the fact that C requires understanding of both the hardware and memory architecture as well as computer science constructs such as data structures and algorithms. In short, C has become the new Pascal in university education.

The interesting thing is that I can actually see this problem in real life now since I've become part of Tokyo Hackerspace. The majority of the techies involved in hackerspace program in languages like Python and PHP and want to get more involved in programming embedded projects. While there isn't anything wrong with those languages, a lot of the low level details are abstracted away, which is great for learning the computer science part of things, but horrible if you every want to program embedded systems. 

I've recently set up the hackerspace webshop and had to do some PHP hacking to get things working like modifying the shipping cost tables for the Japanese postal system. Since it has a C-like syntax, it wasn't a real problem writing the simple PHP functions required to implement the cost tables. However I was a bit shocked to see that the language doesn't require strong typing. You don't even need to declare a local variable. You can just instantiate one anywhere in the function and it will hold strings, integers, floats, or anything else. There's also not a strong concept of scope that I could see (ha ha ha...get it?). The variables were either local to the function or global, and by global, I mean visible to all files in the project. Any C programmer would cringe at the use of global variables because they lead to problems like non-reentrancy, random errors, and really weird behavior in general.

My first thought was..."wow, this language is pretty simple and easy to use". But in thinking about it, it's a big handicap if a PHP programmer goes in the opposite direction and wants to move to a language like C. C requires a lot of discipline about data types, scope, and memory usage. That's not to disrespect PHP programmers since they have to deal with all sorts of nastiness like tracking down bugs from a PHP file included in some random file located within the 500 or so files that come with whatever content management system they're using. And I don't seem to see a good debug infrastructure for PHP other than logging error messages (although I could be wrong).

I think this is one of the reasons why the Arduino has become quite popular. It's a good way to introduce people to embedded systems and projects without having to deal with a lot of the dirty details like chasing wild pointers and memory leaks. And of course, you can say you program with Arduinos and still maintain a certain amount of dignity. It's more difficult if you're using a language like PICBASIC. 

But the eventual barrier that I see a lot of Arduino users running into is that projects are limited to the AVR processor. Normally, I like AVRs but in terms of the embedded space, you lose a lot of the richness and variety of the different flavors of MCUs if you stick with just one processor.There's the integrated signal chain and low power of the MSP430s, the infinite amount of variations in the Microchip PICs, the configurability of the Cypress PSOCs, and let's not forget playing around with the ARM-based SOCs that are dotting the chip world these days. In order to harness the rich variety of all these different chips, you would need to learn how to program in C. Otherwise, you'll end up with Arduino shields piled on top of each other like the Leaning Tower Of Pisa and still be limited to the Arduino API. 

Anyways, this post isn't really to rail against the Arduino, which I think did a great job of introducing an entirely new generation to the embedded world. Nor am I trying to complain about PHP, Python, or any other scripting language which is doing a great job of powering content-driven websites and even making this site's creation and maintenance possible by a complete web n00b. The main issue is that the embedded field is expanding and there's a huge interest in combining embedded technologies and web technologies. This can be seen by the growing popularity of publications like Make Magazine, numerous hackerspaces popping all over the world, and of course my involvement in Tokyo Hackerspace. However there isn't a whole lot being done about the paradox that C is a dying language in the academic world, but very alive and kickin' in the real world.

Hmmm...I guess this counts towards my quota of one rant on the lack of C education per year...

Hits: 36772
Trackback(0)
Comments (2)Add Comment
...
written by Kevin, August 05, 2009
I've never really understood the whole PHP thing either. It's easy to learn, I suppose, and everyone needs to start somewhere, but it just seems like such a mess to debug and you can see it's non OO roots everywhere (I'm biased, though ... I'm an OO junkie). Life PHP ... JAVA and C# both offer very rich pre-built frameworks that can do almost anything you might want, but they remain strongly-typed and very well structured languages. In the case of Visual Studio you also have an incredibly rich and easy to use integrated build and debugging environment. (Think what you want of Microsoft, but life has never been easier or more productive for me than with Visual Studio, even though I rarely find the time to develop for PC software anymore.)

It's a bit the same for me with Arduino. I never really understood the appeal, except ... again ... that everyone needs to start somewhere, and maybe the genius of Arduino is it's ease of use. Like Visual Basic, though, that's also it's downfall, since after a certain point you're bound to hit a wall (if you want to access the hardware directly, for example, or do anything low-level ... or just have code with clearly defined boundaries, etc.) It's a great starting point, but there's definately no replacement for C (which is actually a lot easier to learn than something like C if you have no experience with OO languages).

Even the best C#/Java developpers today, though, have no idea what something as fundamental as a hexadecimal number really is (or how to use them). No one ever has to think in terms of bits when making web pages or Windows apps, which makes the learning curve getting into embedded development a lot steeper. It's the fault of modern education, I suppose, but even on the web there is a surprising lack of clear explanations for those fundamental concepts. (Again, Arduino's success is probably simply because they were one of the few 'platforms' that bothered to try to make it easy or at least accessible for newcomers.) Writing C code for ARM isn't really any harder ... I think there just isn't the same kind of community out there willing to bring it down a notch and try to open things up to the hundreds of thousands of competenty C#/Java/PHP developpers out there who would love to work on embedded devices.

It was a bit rough when I first switched to C from C and C# (though easy since both of those languages are based on C), and I still struggle with keeping very large projects organized (did I mentioned I'm an OO junkie?), but there definately isn't a replacement for the clean, lean, concise efficiency of C. The sad thing is that it's the easiest of any 'C' language to learn, and yet it's the given the least amount of attention outside the (GROWING at 25% a year in Europe I believe!) embedded space. It's a sad and strange irony indeed.
report abuse
vote down
vote up
Votes: +0
...
written by Kevin, August 05, 2009
It seems all the C ' ' ' ' tags are getting converted to just C? I'll have to use CPP in the future. :-)
report abuse
vote down
vote up
Votes: +0

Write comment

busy
  No Comments.

Discuss...
< Prev   Next >