Skip to content

Commit

Permalink
minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lh3 committed Mar 7, 2024
1 parent 1abc38e commit 266db40
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions _posts/2024-03-05-what-high-performance-language-to-learn.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,26 @@ In the past couple of months, I have been asked several times about what languag
if someone wants to write high-performance programs.
This is a sensitive topic that often triggers heated debate
partly because many fast languages share similar features and are comparable in performance.
My take is that for small research projects only involving a few developers,
My general take is that for small research projects only involving a few developers,
the choice of programming languages is personal.
Nevertheless, if you hold a gun to head and ask me to choose a single high-performance language,
Nevertheless, if you hold a gun to head and force me to recommend a single high-performance language,
I will probably say [Rust][rust].
Here is my thought.

### Why not Python or R?

Python and R are the most popular programming lauguages in computational biology.
However, they are slow unless you can find libraries written in other efficient languages.
How slow? Often ~50 times slower than a C/C++ implementation.
How slow? Often [~50 times slower][benchmark] than a C/C++ implementation.
This means a one-minute task in C/C++ is turned into one hour and
a one-hour task is turned into two days.
When you have a new method in mind,
the inefficiency of Python and R may become an obstacle and limit your stretch.
When you have a new method with the bottleneck falling in to pure Python/R code,
the inefficiency of Python/R may limit your stretch.

Another practical problem, at least with Python, is the deployment of your tools.
To run a Python program, users have to install dependencies on their machines.
This is slow and sometimes problematic when dependencies of different packages conflictive with each other.
With C/C++, it is possible, though takes efforts, to compile portable binaries that run on most machines.
With C/C++, it is possible, though takes efforts, to compile portable binaries that do not require users to install dependencies.
Properly distributed C/C++ tools are easier to install and use.

### Why Rust?
Expand All @@ -39,7 +39,7 @@ Rust is a mature memory-safe programming language with little/no compromise on p
It is as efficient as C/C++ and almost free of memory-related errors.
Unlike C/C++, Rust comes with its own package manager, which greatly simplifies the reuse of existing libraries;
Rust also makes it easy to create portable executables, improving user experiences.
It has been used [for Linux kernel development][linux-rust] and endorsed [by Google][google-rust], [by the CTO of Microsoft Azure][ms-rust] and
Rust has been used [for Linux kernel development][linux-rust] and endorsed [by Google][google-rust], [by the CTO of Microsoft Azure][ms-rust] and
surprisingly, even [by White House][white-house].
You can easily find articles on the Internet about how good Rust is.
I will save some words here.
Expand All @@ -53,15 +53,16 @@ Furthermore, the Rust memory model brings new concepts that are rarely seen in o
I have written five short programs in Rust but I am still at the bottom of the learning curve.

Nevertheless, I want to note that mastering C from scratch might not be easier.
Although C looks much simpler, getting the best out of C without frequent [segmentation fault][segfault] may take years of practice.
Although C looks simpler, getting the best out of C without frequent [segmentation fault][segfault] may take years of practice.
Modern C++ is a very different language from C.
It is a behemoth with a myriad of modern features and decades of legacy packed in one of the most complex languages.
Mastering C++ probably takes more efforts.
Mastering the entire C++ means mastering C and the C++ specific features.
That is a lot of work.

### Other contenders

Rust is not the only language that matches the performance of C/C++ without memory-related bugs.
If you do not need the best performance and feel Rust is difficult to learn, Go may be a decent second choice.
If you do not need the best possible performance and feel Rust is difficult to learn, Go may be a decent second choice.
As to other high-performance languages, some have not reached the v1.0 milestone and are not stable;
some have a small community, which will make learning harder;
some, in my humble opinion, are not designed well;
Expand All @@ -81,3 +82,4 @@ I enjoy the freedom of [shooting myself in the foot][shoot].
[rust-dlist]: https://rust-unofficial.github.io/too-many-lists/
[segfault]: https://en.wikipedia.org/wiki/Segmentation_fault
[shoot]: https://www.stroustrup.com/quotes.html
[benchmark]: https://benchmarksgame-team.pages.debian.net/benchmarksgame/fastest/python3-gcc.html

0 comments on commit 266db40

Please sign in to comment.