Selecting a Programming Environment

If you program long enough, you come to realize that there is no “one language to rule them all”.  Over the years, I have learned several languages, frameworks, development environments, etc.  For a while Pascal was all the rage, along with C, if you can believe that.  Assembly, of various forms was popular when DOS roamed the earth.  Then along came the new fangled C++, Objective-C, Python, Java, C#, JavaScript, and of course my current favorite, LuaJIT.  I’m sure there will be more in the future.

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.

Recently I’ve been looking at going “cross platform”.  Of course, LuaJIT is the answer, so what’s the question really?  Well, sometimes the decision is more about what other programmers will feel comfortable maintaining, and not what I myself like as a programming tool.  So, this begs the question, what’s the best way to work across multiple platforms?  One answer might be to simply switch to JavaScript, but that’s just jumping from one pot to the next really.  I think the answer is still “C” as a cross platform language.  And by “C”, I mean pick a standard version that is easily supported, and don’t use any fancy stuff.  How about ISO C99?  Then of course you need to pick a ubiquitous compiler.  You could go with GCC, or LCC, or whatever you can get out of CLang/LLVM.  But, basically pick one that covers all the places you’re likely to want to go.

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.

That is of course if you don’t want to use something like LuaJIT, or JavaScript, or one of the other ‘managed’ languages.  It might just be that the absolute killer combination is using these standard C toolchains at the very bottom, with a managed language on top, as the sort of ‘glue’ to bring multiple disparate things together in a seamless and coherent way.

This is the landscape I am looking at today.  I’m sure tomorrow it will be different.

 

 


6 Comments on “Selecting a Programming Environment”

  1. assy cron says:

    Lua has a threadsafe hash table?

  2. […] There is a kind of clarity in a model that simplifies things this much. 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. […]

  3. rad says:

    There’s a language called Vala which is a higher level language that source to source complies down to C, which is then fed through GCC. The higher functionality (objects, assisted memory mangement etc.) is implemented in C.

    It is compatable with C libraries and works with gtk+

    http://en.wikipedia.org/wiki/Vala_(programming_language)
    https://live.gnome.org/Vala

  4. Abby says:

    very informative post indeed.. being enrolled in http://www.wiziq.com/course/6314-learn-c-programming-language-low-priced-student-edition was looking for such articles online to assist me.. and your post helped me a lot

  5. Tran CE says:

    Hello, sir i would like to ask that what is the scope of c programming, what all topics should be covered and it is kinda bothering me … and has anyone studied from this course http://www.wiziq.com/course/2118-learn-how-to-program-in-c-language of c programming language online ?? or tell me any other guidance…
    would really appreciate help… and Also i would like to thank for all the information you are providing on c programming.


Leave a reply to williamaadams Cancel reply