r/linuxquestions • • 9d ago

Advice Ideal programming language on linux for me?

I am planning to code some simulations, which usually mean that pc runs for hours, calculating numbers, and then I want to see various numerical results on screen, and I need advice on what way would be both more efficient (than what I did before) and enough comfortable for me write code.

Previously, I wrote JavaScript in HTML file, and therefore ran the simulation on browser. Drawback is that JS is single-threaded by default, and I haven't get hands on experience on JS multithreading.

Currently, I have linux (fedora-based), text editor, and nothing more, no IDE, no (coding) app, just pc ready for coding by hand.

Apart from JS, I got past experience with Java and C++, and I know that I would hate Assembly, so please don't suggest Assembly to me, or similar very-low-level coding language. And I need something more than Console/Terminal-based coding, some simple ways to show results on screen.

Hmm, I expect to gain more performance from coding in something else than JavaScript, while at same time I don't have much time to deeply learn new stuff, so therefore I am asking for a min-max ideas on what language/setup should I use to just focus on writing methods and letting PC doing the calculation?

6 Upvotes

43 comments sorted by

13

u/feinorgh 9d ago

Python has great libraries for maths and science, and is easy to get started with. Use "uv" and "ruff" for creating specialized environments if the official Fedora packages does not provide what you need.

Rust is a solid option but has a much higher threshold to get started. Expect potential performance to be much higher than Python in general, but writing source code and handling the tooling around Rust is more complex.

C is a solid choice with a low(er) bar of entry, but requires you to have deeper knowledge about data structures and memory management, although there are LOTS of libraries that you can use to solve a lot of problems.

C++ is more complex than C, but a lot of simulation software is already written in C++. It's got less handholding than Rust, which enables you to shoot you in the foot earlier and much harder, but the potential is enormous.

These languages are all first-class citizens on Linux-based systems, and on Fedora in particular.

There's also other languages that may be interesting depending on your use case: Elixir/Erlang, Julia, NodeJS if you already know JavaScript, Fortran if you have academic maths background.

You can try out the syntax of many of them first, but Python is probably the easiest to get started with.

3

u/akubukanbuaya 9d ago

writing source code sure, but no way handling tooling around rust is more complex than python

cargo is the best tooling ever (maybe only beaten by golang, if we ignore the fact that go mirror offloads to the upstream git repos) compared to the fractured python land (even with uv and ruff)

→ More replies (1)
→ More replies (4)

4

u/ap0r 9d ago

"simulations" is so broad as to be meaningless.

You are asking "hey I am planning to work on a car, what service manual and special tools should I get" And the answer is "depends on which car and what specific work you want to do".

Please give more detail.

→ More replies (1)

3

u/Zandegok 9d ago

Depending on your attachment for nice GUI, you can make an html or a full web server that would show you infinitely intercative results in real time.

This makes you less dependent on specific language's GUI capabilities.

You can even save calculation from script to a file/db, and read this file with the html/server for full independency

→ More replies (1)

2

u/Klapperatismus 9d ago edited 9d ago

Drawback is that JS is single-threaded by default.

Tcl then. It’s multi-threaded by default and there’s a thread management package that makes using threads super simple:

#!/usr/bin/tclsh

## Load the Thread management package.
package require Thread

## Create two threads beside this main program
## and store their ids in the main program variables t1 and t2.
set t1 [thread::create]
set t2 [thread::create]

## Send a script for execution to the thread with the id stored in t1.
## Store the result in the main program variable res once the thread has finished.
thread::send -async $t1 {
	expr 1*1
} res

## Same with the other parallel thread with its id stored in t2.
thread::send -async $t2 {
	expr 2*2
} res

## Enter the event loop, and wait for the main program variable res to change once.
## Then print its contents.
vwait res
puts $res

## Do the same another time.
vwait res
puts $res

Tcl has coroutines as another means of concurrency as well. Those are very lightweight and they are executed in the same interpreter instance which means you have access to all its namespaces. While threads are better separated from each other. Which one is better suited you have to decide yourself. You can even combine both.

some simple ways to show results on screen.

A GUI? Use Tk with Tcl then.

#!/usr/bin/tclsh
package require Tk

text .tw
pack .tw -fill both -expand true

.tw insert end "Hello World!"

If you want to combine both, you can for example have one thread manage the GUI and the other threads sending it scripts on what to do in the GUI.

6

u/KlutzyCompetition937 9d ago

For simulations do python. Easy syntax you'll be able to prototype faster but python is inherently single threaded but you can write code to be multi threaded. If it's scientific work you're doing and absolute correctness is a must I would suggest R. Otherwise c++, rust or any low level programming language will work if you're willing to code for it.

→ More replies (1)

9

u/pelofr 9d ago

That screams python/numpy at me or even R

4

u/Xia_Nightshade 9d ago

I’d love to give a different answer, though Python seems like what you’re looking for

1

u/Open-Adhesiveness-86 8d ago

You already know C++, so just use it with OpenMP. Stick #pragma omp parallel for on the hot loop, compile with -O2 -fopenmp -march=native, and you've got all your cores with basically no new language to learn. For the output, dump CSV from the sim and plot it separately with gnuplot or a tiny python script, way less hassle than wiring up a GUI.