Thursday, May 14, 2009

Managed code seems to be catching up …

Warning: This is an article intended only for the geeks, so stop here if you are not one.

I first started writing embedded software in assembly. I would not even term it a language, because, every single instruction was translated into an op-code, 1-to-1, nothing less. The firmware (stylish name for embedded software) developed using assembly was in total control. I mean it, total. There was no abstraction what-so-ever between the programmer and the hardware. At any point of time, every single register, every GPIO (General Purpose Input Output) ports were in our control. All our named variables were global. This control somehow translated into our confidence, sometimes arrogance. Those days we assumed that programmers who lacked knowledge of the hardware developed firmware in C. On one fine day, I got impressed with the compensation offered by another company that was developing firmware in C. Getting impressed with the salary; I quit the holy-assembly, mostly for-ever. But long after that, even today, I think those early assembly days were the best. Or … is it yet to come.

Development in C started badly. I knew C, in mostly like a paper driver who can drive, by the books, obviously I lacked experience. During my job-interview, I correctly answered most (all) of the questions on assembly language and got ~70% for C. The guys who interviewed me thought I would master C quickly. Somehow, I managed to score 4.8-out-of-5.0 in a test conducted by brain-bench for C. Those guys even sent me a certificate, embossed in golden color, now the best part, it was free. But over a period of five years, the golden emboss faded, but I learnt more of C. I started developing applications using C, then wrote some device drivers for windows, and finally after a couple of years of slogging, mostly maintaining others code, I started developing some really cool C code. I heard that C was more portable; it was, to an extent. I also learnt that embedded software is all about creating nice-and-compact-and-fast data-structures, and learning some cool compiler directives that will give you complete control over placing your code and data. In a way, I understood, I was writing some so-called-portable source code, in a high level language. I swear, in those days I never tried its portability though. I realized that for larger embedded applications, C was a good development platform. I always heard from my seniors, and also believed for myself that, c++ and embedded software were enemies. I would have sworn this over a bible, even without any experience programming in C++. I hated the language.

I was told to port the OS and write embedded software using Linux. Back then, I was a DOS-and-Windows guy, who never really understood, that free software, like Linux, will actually work. I assumed that the “Open source Linux”, will never be as cool as windows. When ever I go to the testing lab, I stared at those good looking Mac boxes wondering if, it was an ice box for beers. Man, I hated its mouse. In Linux, there were no MSDN type manuals, mostly not even some basic documentation. One more secret reason I hated it was; there were many junior programmers in my company, who knew more than me. And so, I comfortably termed it as a “not so practical” language. I quit the Linux development, and also the company and moved on to some other RTOS in some other company. For a long time, with the momentum in C, I continued with C, till I was asked to look into an ECMA compiler for a Television set, possibly to re-write it. Back in 2007, the ECMA compiler for Linux was written entirely in C++. For countless number of days, I just read and read the source code. As far as C++, my brain was closed. My gray-cells won’t change, even if I wanted to.

The C++ development continued and after developing in C++ for almost a year I learnt that I was not a C++ guy. I could not think in C++, partly owing to the many abstraction levels between the C++ codes and the converted assembly. When I wrote firmware in C, for each line of the source that I wrote, I could easily visualize the assembly instruction. Essentially I can see through the C code. But in C++ I could not, worse, Frankly, I did not try. And that was the end of C++. In a way, till today, I did not need it.

I thought, I can earn a living writing embedded software using C, till I retire. But my safety net was shattered today when I learnt that “managed code”, like C#, .NET, etc are on their rise. I knew about C# from the time it was released, back then, I had assumed that it was meant only for those application developers. I even picked up a fight with one of the guy who was talking about “boot-loader development based on managed code”. Frankly, I do not understand how, a boot-loader can ever be developed using “managed code”. Worse, I do like the idea of developing a boot-loader in C# or .NET. I do not see any advantage. I am an emotional guy who likes to live close to the hardware, and like less number of abstraction and hence need to write code that can do just that. And as of now, I think C is the one. But it seems that at the end of the tunnel, C#, .NET etc are pushing very hard. I can feel it. Someday, I may learn it, and probably would even master it, if-only I feel it is useful. Oh my gray cells, won’t you please co-operate.

1 comment: