Question in mail: Do you need assembly language?

From: sandusergiu1984@...
Sent: Friday, August 18, 2006 2:12 AM
To: Eldar Musayev
Subject: (Random Thoughts and Hints on Software Development) : Hello
Importance: High

Hello Eldar, I've read somewhere that every developer who want to write great efficient code need to learn assembly language? Is it true? If have time, please, write the answer in the blog. Thank you.

Well, do you? One thing for sure, you will almost never use it at work. In most cases, you will never use it. Period.

Even if you develop hard real-time OS, like I did in the past, you never normally go below straight C.

So, do you need to know assembly language? Normally, I would say “no”, but a few encounters convinced me otherwise. Let me tell you about it.

It was many years ago, I worked for a huge well-recognizable MidWestern manufacturing company. We did software for their dealers, sort of a custom mix of CRM and SCM with a fat Java client (yes, fat, it was supposed to be thin, but over the time it become really, really fat without any sort of rich functionality of thick clients) and C++/C backend on AS/400 (now this midrange machine from IBM is called somewhat differently, but still around). We used DCE (IBM variety and granddaddy of CORBA) and a middleware server to deliver calls from the client to the server. It was a royal pain. Seriously. If something did not work, you started from checking if IDLs on the middleware server are the same as the current build. In 90% of cases, it was not.

So we decided to replace the communication architecture. Me and two other guys were charged with the task. One of them was our lead and – beyond writing the code – took care of selling the idea and pacifying the management. Both were great to work with as well as to have a beer or two after work in a pub across the street which proudly called itself “An Irish Embassy in Peoria”. But enough with memoirs, let’s get back to business.

To send data over network we had to serialize them. Fortunately, the only thing we dealt with were simple structures of primitive types. How do you serialize a simple structure in C/C++, if you are allowed binary serialization? Right, the pointer to the structure is also a pointer to a byte array. That’s it.

On the Java side it was a little more tricky. We had to get them byte by byte from the byte[] array, and push into the individual data fields. Even with IBM library doing a lot of work for us, the picture was complicated with the fact that AS/400 uses Big Endian and alignment (the old concept of always putting a four-byte integer at the address ending with two binary zeros and similar practice for 2- and 8-bytes words to improve the performance). On top of it I used a hack or two of a reliable sort to smooth the things.

And then I had to explain it all to Brandon, because he had to write such code too. He was a bright smart guy, but his first language, unfortunately, was Java, that carefully hides such meagerly details from the developer. Each time I tried to explain it to him, his face went blank. I think that until the first call went through, he firmly believed that I am feeding him with tons of crap to boost my personal ego. And when the first call really came through, it was a shock for him. The world shuttered, turned inside out and showed it’s alien reverse side. It was both exciting and frightening experience for him, like if a person experienced first-hand with his own eyes the bizarre wild dance of elementary particles in a quantum mechanics of everyday things.

Well, he was a bright smart guy, so today he does not have any of such problems anymore, but the experience was painful to both of us. Did I managed to answer the question?

Don’t learn it as a professional language, you are not likely to need it, and even if it does exists somewhere (compiler writers have to deal with it), it’s a niche market. But learn it as a curious puzzle, a toy, figuratively speaking – a way to tinker individual electrons and atoms in your morning cup of hot tea. Not very useful practically, but a completely new level of understanding why you should not spill it on yourself. Makes sense? ;-)