Selecting a Programming EnvironmentPosted: August 31, 2012
What I have found to be useful is to have a set of things that are fairly constant across time, space, and the varying landscape of languages and frameworks. I was recently having an exchange about language choices, and came to the conclusion that there are a couple of things that have been constant for me over the past 25 years of programming.
1) Need a robust string class
2) Need a fast thread safe hash table
There are a vast number of other things that I might need for a particular programming task, but these two have been consistently required across all environments and programming tasks that I have embarked upon.
For me, those places include everything from lowest level microcontroller devices such as Arduino, to SoCs like Raspberry Pi, all the way up to multi-core X86 and ARM machines. GCC is usually available on all those different machines. Although I prefer programming on Windows, unfortunately, the Windows C compiler is not available across as wide a swath of devices as GCC or other compiler solutions.
Besides the compiler, you have to choose a “standard C library”, and there are multiple to choose from. How to choose? I want a library that meets the following criteria:
- Runs on all the platforms I want to be on
- Can be compiled easily using the compiler I choose
- Has all the modern functions I desire (net, crypto, compression, string manipulation)
- Is as small as possible
- Can easily be pruned to meet the constraints of my target system
These seem simple enough, and you’d think any library would do the trick, but the world is a complicated place, when it comes to standard ‘C’ libraries. Recently, I’ve been taking a look at the musl library. This library has some good goals. It specifically targets Linux environments, so it’s not necessarily the place to turn for a Windows programmer, but for everyone else on the planet, it’s a fairly good deal. If their criteria and benchmarks are to be believed, it comes out fairly well in comparison to other libraries, such as uCLibc, dietlibc, eglibc.
The library has all the standard stuff like stdio, alloca.h, crypt.h, ctype.h, etc. As well, it has all the networking interfaces as well. Of course it’s taylored to work with Linux/POSIX, but even Windows supports a fair amount of POSIXisms, at the system level.
Alright, so let’s say I choose musl as my lowest level C library. I still need some things it might not supply, like my beloved string and hash table. If you were programming in C++, you would just use the STL and call it a day. But hold on a second. I want to use straight C, because C++ brings a lot of love, but also a lot of bloat and complexity to a party. So, I need some small tight functions that give me to juice I need, without all the bloat.
There are literally thousands of functions, libraries, frameworks, and whatnot that could be applied to the problem space. There is one that I found that is very interesting. KLib is a library of stuff written for C (not C++) which performs a number of tasks. In the library, among other things, can be found my beloved string and hash table. In addition, there is a vector, btree, list, some higher level math functions, and the like. What’s really cool about it is the minimal approach taken. In many cases, the functions are implemented in header files. I’m personally not a huge fan of deep programming by #define, but in some cases, it truly is the best thing. Some things about the ‘libary’. It’s small and simple. In some cases, there might be two functions, one with bounds checking, and one without. That sort of thing is valuable when you want to control the performance of your code.
Of course, you could go with some of the more popular libraries, such as Boost, but once you go down that path, you’re going to blow your memory budget, and not likely to find your code running on microcontrollers or other very constrained devices.
So, what do I conclude?
Compiler: CLang, or GCC
Standard C Library: musl
Support Libraries: KLib, and others, or from scratch
With this setup, I believe it is possible to create just about any code, for any task, for just about any environment in modern usage today.
This is the landscape I am looking at today. I’m sure tomorrow it will be different.