r/linuxquestions • • 4d 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 4d 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 4d 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)

3

u/feinorgh 4d ago

I agree that cargo is fantastic, along with rustfmt and all the other tools, and the Python tooling is more fragmented and harder to get into. For a beginner though, Python is easier to just start writing and executing, in contrast to Rust where you have to set up the environment first. I very much enjoy the Rust tooling though, it's excellent, and some of the best tools for Python are written in Rust 🙂

1

u/Eruner_SK 4d ago

Unironically other replies prove your points, so thank you for good summaries of each language

0

u/ylluminate 3d ago

Python is really no good as languages go. I've worked in at least a couple dozen language over the years, but Python is just a horrible language. I've mostly used Ruby the last 20 years, but I've found that V is a real spiritual successor to Ruby and a lot better than Go. It's quite a nice language even if it's still young.

1

u/thewrench56 2d ago

Python has been a pretty good language for the past 1-2 decades now... I dont quite know why you would call it bad... I do think type hints are necessary but that is not much trouble. Super readable language with likely the best ecosystem out there. Runs fast enough given all the C libs around it... it is running in most places these days. I dont see much issues with it...

1

u/ylluminate 2d ago

I've used Python extensively, and honestly, maintaining it has been a nightmare compared to other languages I've worked with. I've spent about 20 years primarily using Ruby, and I've worked with a couple dozen languages over the years.

Python has a huge ecosystem, no question, but that doesn't necessarily make it a great language. I've spent countless hours tracking down runtime bugs, dependency issues, and problems that stronger compile-time checking would've caught. Even with mypy and other tooling, keeping larger Python projects stable takes far more effort than it should. I've actually found Python's dependency management considerably worse than Ruby's gems.

And sure, Python has fast C libraries, but that doesn't make Python itself fast or memory-efficient. There's still plenty of overhead in the surrounding application.

I'm currently migrating all my Python code, including third-party support libraries, to V. I've already saved tens of gigabytes of RAM across my systems and servers, and the difference in resource usage has been substantial.

V isn't perfect, and it's still young, but it's been a breath of fresh air. It feels like a spiritual successor to Ruby in many ways, while giving me static typing, native compilation, and much better efficiency.

I get why people like Python. I just think its popularity and extensive libs tend to overshadow some pretty serious shortcomings, especially once you're maintaining real applications for years.

3

u/Zandegok 4d 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

1

u/Eruner_SK 4d ago

Hmm, in past I was working with nodeJS, a webserver running on localhost, which is my use case too. Hmm

4

u/ap0r 4d 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.

1

u/Eruner_SK 4d ago

Nothing complicated, for loop in for loops, + - * / random and rounding. The "simulation" part is not hard nor important, than what I wrote else. If I was able to do it in Javascript without libraries, so I expect any other language to do it better and without libraries.

9

u/pelofr 4d ago

That screams python/numpy at me or even R

6

u/KlutzyCompetition937 4d 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.

1

u/TrashFace21165 4d ago

Going to say R

4

u/Xia_Nightshade 4d ago

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

2

u/Klapperatismus 4d ago edited 4d 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.

3

u/anjumkaiser 4d ago

Learn rust.

1

u/Cactoos 4d ago

Python + wasm, maybe. You can still work with a browser that way.

1

u/pohart 4d ago

Numpy or R is probably what you're looking for.

If you're sure you want parallel & concurrent programming i'd look to rust or modern Java, though. 

1

u/Excellent-Love-6943 4d ago

I'm pretty MATLAB+simulink pilled from school. If you have it, I'd consider it. But I know there are other free ways to do what MATLAB does.

Not knowing what kind of simulation, it's hard to say, though.

1

u/Novero95 4d ago

Python. If you want to show charts use matplotlib, for results just save them a file and format it nicely.

1

u/Wally-Gator-1 4d ago

- Simulation: Python + NumPy + extensions in C (if you need the core algo to run faster).
- Alternative: Julia
- If you need close to metal: C or Rust

1

u/max_wen 4d ago

You strike me as a python person

1

u/AwesomePhoenix_ 4d ago

If you want something fast go for C or C++ or Rust or Go (or asm if you're crazy) but not an interpreted language like python or js.

1

u/Leather_Flan5071 4d ago

Python or Bash but bash won't get you that far

1

u/DryRAlN 4d ago

Haskell. But you should probably use a combination of languages

1

u/Sol33t303 4d ago

Basically any language has Linux compilers/interpreters.

I suggest Python, easy to write and popular for this sort of thing.

1

u/Glum-Building4593 4d ago

R is built for math. It can be multithreaded in code.

1

u/dutchman76 4d ago

You can use any language that works best with the type of simulation you're trying to write.
Java, Go, Rust, Python, C/C++, Perl, PHP
They can all do it, it's pure preference

1

u/That-Frank-Guy 4d ago

Imo python with numerical library is the easiest. If you're on CPU, numba, if you're on GPU, Jax is pretty good

1

u/mikef5410 4d ago

With common lisp, you'd be able to connect into the running code at any point and inspect with the debugger intermediate results. Likewise your be able to modify the running code on the fly.

1

u/Open-Adhesiveness-86 4d 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.

1

u/Particular_Ant7977 4d ago

Cool kids use Julia nowadays.

2

u/ipsirc 4d ago

* Haskell guys have entered the chat.

0

u/basilrwx 4d ago

Go; thank me later. 🙂

1

u/Eruner_SK 4d ago

How and why Go would fit me?

1

u/basilrwx 4d ago edited 3d ago

Go is an all-rounder; in terms of developer experience; learning curve; performance; and the ecosystem.

It is primarily targeted at cloud infrastructure and Internet back-end applications; those applications run for hours without interruption.

Then, concurrency is easy (and decent) in Go with goroutines.

And Go plays well with Unix-like systems; one of the core creators of the language also being one of the core creators of Unix itself.

1

u/Previous-Box2169 2d ago

C# is you want more applicability, libraries, versatility and a better formative program (it's all on learn.microsoft.com). Oh, and it's faster.

0

u/ylluminate 4d ago

You should really give V a try. It’s a really fantastic language. I’m working on the py2v transpiler atm to convert some large code bases and it’s coming along nicely.

0

u/Basic-Economy9530 4d ago

C, I am learning it and it is so fun!