Modern object-oriented programming languages

What the world needs is a modern, object-oriented, garbage-collected, type-safe programming language that performs well, and is usable anywhere.

Published on Tuesday, 18 December 2012

So, I've been thinking lately (probably because of the embedded development I've been doing) that what the world needs is a modern, object-oriented, garbage-collected, type-safe programming language that performs well, and is usable anywhere. I've been developing full-time in C# for my employer for a long time (since the language has been publicly available, in fact), and I've become accustomed to having an extremely powerful library, along with highly convenient language features available to me. I did some hobbying in C long ago, but never very much, because the memory management just didn't feel "clean" to me. Having to manage everything as hunks of memory and passing around "void *" everywhere just doesn't strike me as type-safe.

A couple years ago, I did a short stint at an outfit that used C++. I had no previous experience in C++, understanding only that it was the anti-Java, in that it was low-level, complex, and unfriendly. Not that Java is particulary friendly. I managed, but the C-ness of it continued to leave a bitter taste in my mouth.

I looked at the D programming language, which is pretty much everything you'd want it to be, except widely-used. It also didn't seem to be straightforward (if even possible) to use in an embedded context.

Then, one day (and I don't remember how), I remembered that the committee had been working on a new version of C++ (C++0x, they called it, because they didn't know when it would be done). I looked in on it, and wow, had things changed. Now, it was called C++11 (because they'd run out of 0x years), and they had done extremely considerable work with this thing. Among other things, there are now:

  1. Lambda expressions. This is a biggie, I use them all the time in my C# development.
  2. "Smart" pointers, i.e. automatic memory management. It's not a generational mark-and-sweep GC (which, I hear, is coming eventually), but it's usable, and it works.
  3. Reference types. No more having to manage pointers and addresses and whatnot in function calls. I don't think these are new, but I defintely didn't know about them.
  4. Type-safe enums (or "class enums"). If you've used an enum in C#, then these are what you'd expect an enum to be (the non-class enums are just a bunch of consts, as far as the programmer is concerned).
  5. Initializer lists. Again, if you've used these in C#, you know how convenient they are, and it's nice to have them.
  6. Type inference. It's not "var", it's "auto", but the convenience and type-safety is the same. This one is big, I believe it makes for nice, pretty, readable code.
  7. Constructor delegation. Constructors can now call other constructors. Useful.
  8. Null pointer constant. Didn't like "NULL"? Now you have "nullptr", which is more pretty, and more type-safe.
  9. Multithreading, tuples, hashtables, regular expressions, among other things.

C++ is still complex, and the syntax, being C-derived (and backwards compatible), isn't always as clean and nice as what you're used to in C# and Java, but this is definitely a modern object oriented language that is usable pretty much everywhere C is (which is pretty much everywhere!)