4 ms·
Easy answer: Yes! To first order, it doesn't matter which you pick, because we will all be better off than if you continue producing C code. For production co
by ncmncm 8y ago
Easy answer: Yes!
To first order, it doesn't matter which you pick, because we will all be better off than if you continue producing C code.
For production code, it is probably too early to switch to Rust, most places. Give it five years. But it won't be a mistake, then, to have five years' experience with it.
Rust and C++ will require more learning and adaptation than Go. Don't be fooled by C++'s apparent similarity to C: to get the benefits, you need to code the modern C++ way to reduce the window for low-level mistakes. Rust makes it hard to code the C way, so needs less coding discipline, but the Rust way takes more getting used to.
Both Rust and C++ can be substantially faster than C, for different reasons. C++ is better at capturing semantics in libraries. Rust knows more about what code is allowed to do, and can optimize accordingly.
Go is probably easier to switch to from C. There is not as much to learn. It's garbage-collected, so there are places it won't go, but most people won't need to go to those places.
It is never a mistake to know more than one language. In a sense, you don't have to choose one, you only have to choose what to learn first.
- pcwalton 8y agoI wouldn't claim that Rust is "substantially faster" than C right now. In time, the compiler could be able to do more aggressive optimizations than is generally possible in C. But not yet. Generally, I think the performance differences between C, C++, and Rust are so minute as to be not really worth worrying about. In practice, small differences in the way you write the code makes way more of a difference than anything in the languages. This is not surprising when you consider that the three languages literally share the same compiler backend in many cases (LLVM), and core operations in each language generally map down to the same IR instructions.
- ncmncm 8y agoIt is not unusual for a C++ or Rust program to be 30% faster than the C program it replaces. The reasons are worth studying. 30% may be no great shakes vs the 1000%+ available switching from Python, but in this post-Moore's-Law world, it is nothing to sneeze at.
- dvhh 8y agoMy guess is that these languages (C++, Rust) allow for far more optimizations as it is quite discouraged to reinvent the wheel. Which is a unfortunately a thing in C
- bryal 8y agoOne factor is how simple it is to use an efficient data-structure in Rust vs C due to good polymorphism and easy dependency management. In C, importing and using an efficient data structure can be a chore, and so many implementations use suboptimal but more C-friendly structures instead.
- Zelizz 8y agoI think it’s not unusual for any program to be 30% faster than the program it replaces. So far I haven’t seen any specific examples of the C++ or Rust compiler providing a speedup by leveraging additional information input by the programmer. The main speedup seems to be the ability to easily implement more complicated algorithms, and the ability to speedily replace slow one-off implementations with relatively high-quality standard library ones.
- ncmncm 8y agoYes, the practicality of dropping in use of a well-optimized library is one of the ways that C++ code often beats C. Another is the ability to pass a lambda to library function, and compiled directly into it, where C would need to pass a pointer-to-function to be called indirectly. Both contribute to the showcase sorting example, which is used frequently because it had proven to be understandable, not because it is unique.
- flukus 8y ago> Both Rust and C++ can be substantially faster than C, for different reasons. C++ is better at capturing semantics in libraries. Rust knows more about what code is allowed to do, and can optimize accordingly. People have been saying this for decades about various languages and C is still the standard for performance except for a few specific cases. How many more decades until we can consider this "sufficiently smart compiler" a myth?
- ncmncm 8y ago"Still the standard" among people who don't know that C++ is faster than C. Fortran used to be the language for what we now call HPC. C was too slow. C++ is used now. This did not happen because Fortran got slower. Instead, C++ got faster. The reasons are interesting. It turns out that to get faster Fortran, your compiler vendor has to code optimizations in the compiler. But in C++ you can code them in a library, and not wait on the attention of a compiler developer.
- flukus 8y ago> C is still the standard among people who don't know that C++ is faster than C. Care to share some examples? I know there are a few specific ones like sorting but every benchmark I've ever seen has c coming out ahead in most tests, especially when c++ features are used. > Fortran used to be the language for what we now call HPC Again that was a fairly specific case usually only seen in scientific applications. From your other post: > It is not unusual for a C++ or Rust program to be 30% faster than the C program it replaces. The reasons are worth studying. Citation needed, this is so far off from every benchmark I've ever seen it's laughable.
- ncmncm 8y agoIt is not possible for a C program to be faster than the C++ version. Compile the C program with a C++ compiler, and they are exactly the same. Then, use C++ features anywhere they make it faster. If you knew C++ I could go into more detail, but if you knew C++ we would not need to have this conversation.