Re:Metaclasses: Thoughts on generative C++
by seanwilson on Friday July 28, 2017 @05:43AM
(#14873092)
I agree tools and workflows exist to make it easier to write good C++ code but it's still an order of magnitude harder to do this compared to other languages. I'd only use C++ if there was no other practical choice. It's simply far too much effort to make your code robust.
So what is your alternative when you need C++ like features for systems coding, C?!
Because as much as I would like to use a safer alternative like Swift, D or Rust, as an ex-Pascal/Oberon user, they aren't there yet.
There is always Ada if newer languages are not there yet for your application.
Ada is only a solution if it can fulfill the project requirements regarding the libraries, tooling, supported CPUs, OSes and IDEs.
Sure. But now you're retreating to a rather small set of applications. Ada has nice tooling and supports a pretty large number of platforms. I don't think you'll find many niches where not one of Rust, D, Swift, Ada, Java, Go, or the dozens of other memory safe(r) languages could do the job and only C or C++ are adequate.
Practical example, we use C++ as systems language for projects done in Java (Standard, Android), .NET (WPF, UWP, Xamarin), Swift/Objective-C (iOS).
There isn't much Ada tooling available for those environments, and even using GNAT would be increasing project costs regarding having to implement ourselves stuff that we get for free with the SDK tools that support C++ out of the box.
However, the mechanisms for safer code are there, if one cares to use them in first place.
The usual set warnings as errors, CI build with static analyzers that break on failure, unit tests with sanitizers that break on failure.
But many companies don't care to set this workflow.
They also don't care for doing that for Python, Java or JavaScript as well.
JavaScript might have automatic memory management, but it has its own collection of WTF moments and implementation issues across browsers.
Java is way better, yet there is a reason why Java Puzzles are so entertaining.
While a tracing GC is much more productive than RAII/smart pointers, sometimes you also need to track down those references that prevent the collector to do its job.
Android developers have lots of "fun" doing that regarding context and activities.
One should not forget that safe languages only get us free from memory corruption, regarding safe code. There is still the whole spectrum of logical errors, specially bad in dynamic languages.
In any case, until we finally get a mainstream OS written in Swift, .NET Native, Rust or D, we need to make the best use of our tooling for low level system coding activities and in this regard C++ is so much better than C.