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 figure in the last 20 years someone should have created something which is reasonably popular and is nice to code in and is complied.

What more modern alternatives are there to C for writing high performance code compiled code?

edit in response to comments

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.

edit after giving tick

given the tick to zxcdw but thanks for all the c++11 is worth a look answers.

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
If this question can be reworded to fit the rules in the help center, please edit the question.

15

Modern C++ is radically different than C. It's much more comparable to something like Java or C# than it is to C, except it features deterministic destruction instead of garbage collection, and also has undefined behavior since it doesn't run in a VM or managed environment. Your other alternative is D, which is a decent language, but still very immature in terms of libraries and support.
–
Charles SalviaAug 28 '12 at 13:44

10

Can you elaborate on the "performance will be critical" part? Why will it be critical? Have you measured anything yet?
–
JesperEAug 28 '12 at 14:32

2

15 years is an eon in computer terms and for as long as that, people like Ericsson have been using functional languages like Erlang to support distributed, fault-tolerant, soft-real-time, non-stop applications in their embedded systems! Don't assume only C++ can give you the performance you want, you may be better off throwing more hardware at the problem and saving yourself a lot of implementation time with another language.
–
Mark BoothAug 28 '12 at 14:38

12 Answers
12

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.

I wouldn't say the C functionality is "deprecated", in an official sense - just that there's almost no reason to ever use C library functions, raw pointers or C-arrays in C++.
–
Charles SalviaAug 28 '12 at 13:54

17

+1 for talking against the 'compilation is required for performance' false assumption.
–
TelastynAug 28 '12 at 14:11

3

@gbjbaanb try to compile with Visual Studio and with MinGW under Windows and good luck with that :| try also to convince a person that gives you a compiled library compiled with one of this tools that doesn't know nothing about ABIs that he is wrong and he should give you the source of that library or learn how to recompile and give the right specs. the horror, sometimes.
–
user827992Aug 28 '12 at 14:52

5

@paxRoman: you can write small programs in C++, and write them more safely than you can in C.
–
kevin clineAug 28 '12 at 17:22

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.

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.

C++ “is very easy to code in” is just ridiculously wrong, sorry. It’s an incredibly hard language to learn and even if you use modern C++ idioms and eschew pointers you will be faced with tons of puzzling compiler and runtime errors before getting the hang of it. And even after you’ve mastered it, the syntax gets in the way quite often. Safe C++ often uses a mess of nested templates which generate huge amounts of boilerplate code.
–
Konrad RudolphAug 29 '12 at 10:02

10

Very expressive and very dynamic do not sound like typical C++ traits, comparing to dynamic languages.
–
vartecAug 29 '12 at 11:34

18

@gbjbaanb “slightly more difficult to learn” is, once again, ridiculously off the mark. Sorry. I’ve been programming all those languages for years, I clearly prefer C++ (and do most serious programming in it) but saying that it’s easy is just totally misleading. And I’m not talking about fancy metaprogramming stuff, I’m talking about compiler errors produced by run-of-the-mill code, caused by name hiding, ADL, const correctness issues and stuff like that. Anybody who has read Effective C++ (as Coder claims to have) and maintains that C++ is easy has a mental disconnect.
–
Konrad RudolphAug 29 '12 at 13:56

10

@gbjbaanb I’m a C++ programmer. Once again, I don’t think C++ is easy. And this comment thread got some frowns from the C++ chat as well. So it’s not that. And the difference between C++ gotchas and other languages’ gotchas is that if you don’t know about them in other languages, you’ll probably be fine. In C++, you’re toast. And even if you know about them, you can still get several screen pages of compile errors for a single error (happened to me again today). And even though the error was simple to fix (a typo), it takes time to parse through all that.
–
Konrad RudolphAug 31 '12 at 18:58

5

When has a popular language ever been good? PHP is hugely popular and no serious person thinks it's a "good" language, even for its niche. The only "good" thing about popular languages are that there are lots of libraries to make certain domains easier to program in. C++ itself is fraught with frustration.
–
weberc2Jul 2 '13 at 14:37

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!

I think C and C++ exemplify Hoare's comment on software design: either make it so simple there are obviously no deficiencies, or make it so complicated there are no obvious deficiencies.
–
TMNAug 28 '12 at 14:50

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

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.

My assumption was that something that was first conceived 20 years ago would have inherent architectural limitations which could only be improved with a blank slate. I think this assumption may have been wrong.
–
Jeremy FrenchAug 28 '12 at 15:50

The original x86 architecture was a nasty compromise between backwards compatability with the 8080 and a set of features to compete with the 68000 and NS32032. Segmented memory (with "far" and "near" pointers), only 4 general-purpose registers, variable-length instruction encoding, over 50 flavors of JMP instruction, a multiplexed tri-state system bus... And yet today, that same basic design is going stronger than ever, after many "superior" clean-slate designs (Alpha, MIPS, PowerPC) failed to displace it.
–
TMNAug 28 '12 at 17:27

1

@JeremyFrench nope, your assumption was not wrong, at least in the case of C++. C++ 11 features are definitely useful; however, at this point they are just more crap on the crap pile. They try to build in features of modern languages, but to cope with the existing C++ mess, they must have exceptions, and those exceptions will have exceptions and so on and so forth.
–
weberc2Jul 2 '13 at 14:43

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.

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.

@Coder Java has a FFI (JNI) which allows you to 'wreak havoc' in your language of choice. So if you have designed the interfaces well, you can just replace a Java implementation with a native one. The Java platform is well thought.
–
K.SteffAug 28 '12 at 23:38

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.

every finance job I've looked at want C/C++ developers, not Java. From experience with Java, I can't see any that are high performance unless you throw masses of hardware at it.
–
gbjbaanbAug 28 '12 at 14:47

There are a lot of Java trading systems in operation on Wall Street and at various investment banks in the US and UK. It's also used pretty heavily at the Chicago Mercantile Exchange.
–
TMNAug 28 '12 at 15:04

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.

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.

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.