I am considering writing a new software product. Performance will be critical, so I am wary of using an interpreted or language or one that uses a emulation layer (read java).
Which leads me to thinking of using C (or C++) however these are both rather long in the tooth. I haven’t used either for a long time. I figured in the last 20 years someone has probably created something which is reasonably popular, nice to code in and compiled.
What more modern alternatives are there to C for writing high performance compiled code?
If C++ is a different beast than it was 15 years ago, I would consider it, I guess I had an assumption that it had some inherent problems.
Parallelisation would be important, but probably not across multiple machines.
15
There is a language in development called The Rust Programming Language which pursues similar goals as C++ does, notably zero-cost abstractions and fine control over memory management. That said, it is perhaps the most notable upcoming candidate despite being still very young.
Apart from Rust there really aren’t any other popular alternatives which compile to native code. There’s Delphi and D too, of course, but they aren’t as fast, popular or used. Google’s Go language could be a candidate, but it’s still very young and aims for a bit different domain.
However, do note that C#(assuming Microsoft platform) and Java might not be all that slow even though they run on top of a virtual machine; the just-in-time compilation of code can do some optimizations which traditional ahead-of-time compilers aren’t capable of applying due to lack of information of the program state and environment.
Frankly I would personally not consider C to be a candidate if C++ is an option, mainly because of the fact that modern C++ is safer, works at higher level of abstraction, is more expressive and has practically no performance loss over C(in some cases C++ is notably faster). Simply put, C++ provides everything that C provides and more. Most of the C functionality is considered to be “deprecated” and better, safer, faster and more intuitive alternatives are provided by the C++ standard library.
23
If C++ is a different beast than it was 15 years ago, I would consider it, I guess I had an assumption that it had some inherent problems.
15 years ago, there was no C++ standard. The second one has been published last year. C++ best practices changed a lot in the 5 years after the publication of the 98 standard, and they are changing again with the publication of the 11 one.
There is also Ada, which compiles to native code, and is portable across various platforms within the limits of its standard library. The language is alive and well, with the most recent language standard update currently underway (known as Ada 2012).
Quick summary for those unfamiliar with Ada:
- Strongly-typed
- Built-in support for concurrency
- Object-oriented or procedural, depending on your requirements
- Supported by GNU toolchain (GCC contains Ada frontend)
- Excellent also for software development, i.e. when you need to directly interface with hardware
- Supports generic programming (generic packages, procedures, functions)
- Features support large-scale software development (packages, child packages, separate compilation, strict distinction between specification and implementation)
4
C/C++ is rather long in the tooth…. this is a good thing. It implies that they were designed well enough (ahem) that they are still very usable, that many people use them for everyday tasks, and that you will find a large body of developers whop are experts in them. Maturity is something to be treasured.
If you spend all your time looking for something new, just because its new and think therefore that is must somehow be better, you’re in for a lot of disappointment. This applies to software languages, GUI systems (take note, Microsoft and Gnome) and lovers (take note, young ladies 🙂 )
Now admittedly, if your experience of C++ is 20 years old, when C++ code was generally coded like C, then maybe its time to re-evaluate the language, all the features that were there in the day that were never quite used are used a lot more today, and a few standardisation efforts have expanded the language a little to make it appear much different from those old C-style developments. Not that C is bad too – its a perfect language for many types of coding task too!
5
Why people always insist on looking for new languages?
C++:
- Is the number 4 language by TIOBE, but stomps all competition if combined with C
- Has lots of frameworks
- Is very easy to code in
- Is very easy to tune
- Is very performant
- Is very safe
- Has a very good industry support
- Is cross platform
- Doesn’t need extra VMs/Frameworks/deployment mess if done correctly
- Will easily land you a job
- Has all the necessary stuff to build .so/.dll to launch on very old systems
- Easy to troubleshoot
- Very expressive
- Very dynamic
- and bunch of other interesting stuff
The only downside of C++ is that you have to learn a bit. That’s it.
Compare that to other languages which are one or more of:
- Narrowly supported (OCML, Fortran, …)
- Slow (Java, Javascript)
- Experimental (Silverlight)
- A moving target (.NET 1/2/3/4/5? which one is the last one now?)
- Platform locked (.NET)
- Have poor framework support (Fortran)
- Has small communities (anything outside top 10)
- Are nightmare to troubleshoot (Anything with high-level fool-proof concepts and stuff)
- Needs 500MB of preintallation on customers machine (JVM/.NETVM)
IMHO, the less languages we will use and support, the better the situation will be.
This causes automatic improvements in frameworks for the language, support, documentation, standardization committees work, better books, more knowledge, easier to support software, better patterns, longer language support cycles and more skilled code written in the language.
I know people will downvote this, but think about it, really.
24
I am not a big expert of this language, but I think OCaml could be an interesting option to look at.
OCaml is a compiled, functional / object-oriented language.
For a performance comparison with C++ see C++ vs OCaml: Ray tracer comparison.
Of course, this is a very specific example and one should do more extensive testing to have a better feeling of OCaml’s performance.
1
Current standard of C++ is C++11, which was published in 2011. So it’s not 20 years old standard. And there have been numerous standards in between. Each of them introducing numerous performance improvements.
Compilers also have been constantly improving. They are far better at optimizing, than they used to be.
Executable formats have also improved, 20 years ago you had a.out, now you have ELF.
Overall, suggestion that C++ didn’t change in 20 year cannot be further from the truth.
Also, keep in mind, that C and C++ are very different languages.
6
When you say your project is performance sensitive, do you mean every line of code of it? Or, like normal, is there a smaller percentage that is performance criticial while the rest of it is your ordinary run of the mill business code?
After you answer that, what is the bigger risk for your project: that the end result is too slow, or that you never finish it in the first place?
Assuming you answer the second for both, you should develop in a higher level language that supports native interop (Python, Ruby, the .Net Family all have this). First, finish the project. Then profile, optimize, rinse, repeat. Only after that, consider reqriting choice segment of your application in native code and integrating that native code with your finished product.
2
Depends on what your product is going to do. If performance is really critical, then the go-to language of choice is still FORTRAN. I also wouldn’t rule out Java — it’s used in many high-volume financial trading applications. Erlang is worth a look if your problem domain requires high concurrency. Objective-C is nice, although I don’t know how well supported it is outside the Apple ecosystem (beyond compilers and basic runtime). I’ve also heard good things about Haskell’s performance, but I’m not sure whether that’s absolute performance or just performance relative to other functional languages.
2
I’ve never used it, but a friend of my swears by Cython which lets you use C style primitives in performance critical parts of your code while keeping the general python syntax and being able to take full advantage of pythons higher level constructs to reduce development time everywhere else.
Vala is similar to Java and C#, compiles to native code (or C source code if you prefer), and is very fast. It does require GLib for its object-oriented bits, and it’s written by Linux hackers for Linux hackers, so if your domain is Windows it may not be very good.
Objective-C is modern, compiled alternative to straight C and C++. It has both garbage-collected and deterministic memory management and the message-passing OO runtime has been optimized for performance.
It is available through GCC and CLang and there are application libraries such as GNUStep and Cocotron which work on various platforms.
If you’re doing high-performance work, I’m going to assume that’s kind of number-crunching or other divide-and-conquer work instead of UI, so that means you could do the UI in whatever language is easiest for you, e.g. HTML via a mini http server.
0