(Couldn’t help putting a picture of a very old C++ compiler … it popped up when searching C++ and I’ve actually used it..alot)
People ask us why we chose to use C++ as the main programming language of our system, especially the central parts. The argument is that many newer and “beautiful” languages could have been chosen instead, being Erlang, Java, Python, Haskel (and before the religious warm-up to start an argument, I don’t mean anything by the order or leaving some other good choices out it was just the names that popped out of my head sitting down writing this, after the next coffee-break something else had been presented).
When I just funded Nabto I actually left a Java environment (The company Logiva who market Signflow), so Java could have been a good choice. But the environment I left was mainly administrative web and cloud-based software (Businesss Procces Management with a main focus on invoice and procurement handling) and Java was chosen for this reason, speed and memory footprint was not the main concerns (well the reason for the choice done around 2003 probably was a lot more complex and random than that, but in retrospect this sounds nice).
I’m not trying to put Java down, you can definitely create small and fast programs, but as a programmer/architect (call it what you want) the layout and management of memory is something that Java tries to hide and abstract. From start on in Nabto we wanted to create a system that was very scalable. Everybody who works in the Internet of Things industry knows that everybody is talking billions of devices, and we set out with a vision to be the ones who could support that kind of data without having to build supercomputers. I can remember an assignment at University on trying to create the fasted algorithm for multiplying large matrices and even try to do it in parallel. The naive implementation is just to create two arrays [n][m] and start multiplying and adding the rows times the columns. One of the surprising (well at that time) issues to me was that rearranging the memory layout of the second matrix so that the elements in columns was right next to each other meant a factor 2 to 4 depending on architecture. The reason is that a CPU cache miss is expensive and multiplying large matrices so big that the rows cannot fit in the cache memory will cause that iterating through columns (in the naive implementation) will amount to a cache miss every time, and a cache miss is equal to reading a chuck of second level cache memory (or worse) a the position of the column. Rearranging the columns so that they are aligned linear in memory will only create a cache miss and chuck load when all the elements has been used. Maybe a lot of stuff has changed since then… but being close to the bare metal and have control of memory layout probably still mattered. C++ seemed like a choice where we still had some abstraction and powerful tools/libraries but still to some extend had control over memory layout and what actually would be running i.e. the machine code.
Currently it has proven to be an okay choice… we are starting to handle a lot of devices and resources begin to be an issue. Yes we could just throw more servers and more memory at the problems, but why if we don’t have to. We can run a lot of devices on a small simple setup with a few C++ servers.. and still we are able to scale with more CPU power etc. (probably more on that in a later blog)
Our software has to work with both PC browsers, Tablet and mobile phones setups, and normally if you want to incorporate something into these kind of environments C++ is a good choice.
Another issue we havn’t thought much about is compiled programs are harder to reverse-engineer. We are starting to have customers and partners that are quite loosely connected to us. Transferring non-compiled (interpreted) programs could be an issue. Yes it could be handled with the appropriate lawyer stuff … but I’ll rather send a compiled somewhat obfuscated program… and yes everything can be reversed engineered… but it’s nice to know that if somebody wants to give it a try, they need to really invest a lot of time doing that.
The big mistake we did was to think that the embedded device industry had moved or would move to C++ soon… bummer… we actually had to rewrite most of our early C++ device and convert it to raw C… why you will find some of your software is called uNabto (micro-nabto) … basically that’s the BIG Nabto C++ code rewritten in C (hence micro)… I might write more on this subject later on…