# Comparison of high-level computer programming languages

#### FactChecker

Gold Member
2018 Award
I think there is a generational divide. I have always considered C/C++ to be "higher level", but that seems very out of date now. People can produce programs using MATLAB/Simulink or MatrixX/SystemBuild that would have been inconceivable long ago. And I am sure that others have similar experience with other 4th generation languages.

PS. I will never forget my reaction when MathCad gave us a language that automatically converted units and helped in dimensional analysis but the aerospace industry turned to Ada, which enforced everything but helped in nothing. IMHO, that was a HUGE step backward from 4'th generation languages.

PPS. I would still consider C/C++ to be an essential language for any professional programmer.

#### Krylov

I think there is a generational divide. I have always considered C/C++ to be "higher level", but that seems very out of date now.
I don't think it's out of date - at least not for modern C++ - but perhaps that just means that I am myself out of date.

#### hmmm27

I'm rather more "out of date" than probably anybody else, but my (pro) experience is in CoBOL (which really does deserve the levied humour, but also really does run rings around anything else in its domain). I tend to use 4GL's as analysis tools to get a grip on the problem, rather than production languages.

On the other hand I worked with a rather more experienced (ie: older, with a previous generation methodology under his belt) programmer who could work wonders with a 4GL in a production environment... granted, by basically ignoring all the "fancy" stuff and concentrating on its capabilities closest to the metal.

Just wondering why I haven't seen any references to ForTran or Algol in the last four pages. Surely they both have OO, advanced libraries and decent graphics capabilities by now ?

Last edited:

#### FactChecker

Gold Member
2018 Award
I think that a targeted language like COBOL has great advantages over general purpose languages. I have some experience with several simulation languages for discrete event, continuous, and mixed models, statistical languages like R and SAS, scripting languages, etc. They are all better in their domain than general purpose languages.
FORTRAN has advantages for engineering analysis that I have never seen matched. I especially like the namelist capability for easily printing and reading large amounts of data in a readable format. Many programmers think that they can duplicate that capability in C or C++, but they never succeed.

#### kroni

AHAH. you cannot compare code with other if it is not optimized.
Try ATLAS (Autotuned Lapack) lib on linux, hard to use but so fast ! People optimize it to death since 30 years.

"The C++ code used simple Gauss-Jordan elimination taken from the book "Numerical Recipes in C" :
I think you can gain a 10 factor with ATLAS. maybe other language like Julia or R use different algorithm like : preconjugated gradient (ultra ultra fast for sparse matrix), decomposition method, etc....

For a easy use, Eigen 2 is the best in C++

#### Klystron

Gold Member
From experience on FORTRAN, C/C++, Pascal, Common-Lisp, smalltalk; within object oriented programming.

[post edited for brevity.]
FORTRAN has advantages for engineering analysis that I have never seen matched. I especially like the namelist capability for easily printing and reading large amounts of data in a readable format. Many programmers think that they can duplicate that capability in C or C++, but they never succeed.
FORTRAN proved an excellent language for real-time data collection, filtering, and storage; CFD and similar computational models. Good performance and internal operations. Largely intuitive flow control. Impressive ability to optimize interrupts and distribute processes. Mature compiler. Little or no language derived internal data loss or corruption that I know.

C/C++ runs like a different animal. When programming master control code where human lives are at risk; e.g., in a full-motion simulator; when high-level iterative code requires direct access to low-level synchronization pulses; when sys-level code needs to flip bits and read/write registers; choose C++.

C++ operated well driving human factor repetition rates around 30 frames/sec. With persistence of vision ~7 frames, a 30hz frame rate provides over 4x margin for visual and audio displays. Conditional operator ( example "if" statements) rates actually assist performance with I/O functions during frames. C++ easily controls other electronic devices.

smalltalk, Common Lisp honorable mention. Simplify language into two objects: variables and functions. Although I rarely used these languages professionally, they taught me much about functions, manipulating objects and led to ideas for adaptive structures such as sparse matrices, data driven adaptations, and error correcting code.

Last edited:

#### eachus

AHAH. you cannot compare code with other if it is not optimized.
Try ATLAS (Autotuned Lapack) lib on linux, hard to use but so fast ! People optimize it to death since 30 years.
Using ATLAS is well worth the effort today if you do a lot of linear algebra. (Matrix multiplication, matrix inversion, eigenvalues, etc.) ATLAS generates a BLAS (basic linear algebra subroutines) that is tuned for the exact machine you ran it on. ISA, cache sizes, cpu speed, memory speed, etc. are all taken into account. Then you can use BLAS directly, or use LAPACK or LINPACK which use the BLAS routines with higher-level interfaces.

Back to another topic, if you are writing a program that you will run once, or a few times, high levels of optimization are a waste of time, even if a compiler is doing it for you. If you are writing code that will be run millions of times, or code that needs to meet real-time execution constraints, the more the compiler can do for you, the better. In particular, the SPARK compiler (different from Apache SPARK which is a web application framework) makes writing real-time code much easier. (Easier than other hard real-time tools anyway.)

What makes hard real-time hard? The difference between your first-cut prototype and the requirements. Have I seen cases where that required a million times speed-up? Yep, and made it too. Some of that speedup came from better algorithms and better optimization, but most of it was taking the best algorithm and coding it to work with very sparse matrices.

#### Alex Petrosyan

Out of personal experience, choosing the right language can have up to several percent speedup, if the language has a decent compiler and you know how to turn on all of its optimisations. Hell even Java which should run infinitely slower runs within 5% of some of the C++ that I've written. If you want to optimise - do so for readability in your programming style/paradigm. Even though C++ has the crown for the highest performance code, it can be outperformed by rust, go and Ocaml, not because the languages are better, but because the paradigm that they enforce requires you to write easily optimiseable code, that you can also more easily understand.

#### Klystron

Gold Member
Out of personal experience, choosing the right language can have up to several percent speedup, if the language has a decent compiler and you know how to turn on all of its optimisations. Hell even Java which should run infinitely slower runs within 5% of some of the C++ that I've written. If you want to optimise - do so for readability in your programming style/paradigm. Even though C++ has the crown for the highest performance code, it can be outperformed by rust, go and Ocaml, not because the languages are better, but because the paradigm that they enforce requires you to write easily optimiseable code, that you can also more easily understand.
Design remains critical not only to optimization but also to operation. Active C++ code runs robustly with attention to error conditions.

C languages produce terse code. Write voluminous comments. The interpreter filters out comments.

#### FactChecker

Gold Member
2018 Award
Even though C++ has the crown for the highest performance code, it can be outperformed by rust, go and Ocaml, not because the languages are better, but because the paradigm that they enforce requires you to write easily optimiseable code, that you can also more easily understand.
For numerical calculations (as in a lot of scientific/physics programs), FORTRAN is reputed to be the fastest. It is targeted at those types of programs and avoids tempting features that tend to slow calculations down. I have not personally done tests to confirm that reputation of FORTRAN, but I have seen a few.

#### Klystron

Gold Member
For numerical calculations (as in a lot of scientific/physics programs), FORTRAN is reputed to be the fastest. It is targeted at those types of programs and avoids tempting features that tend to slow calculations down. I have not personally done tests to confirm that reputation of FORTRAN, but I have seen a few.
I have seen and conducted tests of FORTRAN computation modules including tests while performing real-time I/O. I've seen C++ test results running Mandelbrot sets (functions) on networked SGI's, even Crays. Agree with FactChecker and Alex. The CFD system design comes first. Choose language modules in the system for optimum function performance.

Once removed from the front-end interface which may be reading instruments or inputting data, and the fast computation intensive modules, computer speed measured in operations/time (flops, etc.) may not provide the best metric. Near-time analysis of function reliability and spot-check data integrity provides an "outer, slower" command loop sensitive to error. This outer command structure should not need to run at speeds comparable to computation but at the optimum frame rate for system control.

The statement "C programs call FORTRAN functions" though lacking meaning on a distributed network, captures the essential truth that both languages provide optimizations depending on use.

Last edited:

#### FactChecker

Gold Member
2018 Award
The statement "C programs call FORTRAN functions" though lacking meaning on a distributed network, captures the essential truth that both languages provide optimizations depending on use.
My experience with interfacing C and FORTRAN (and Ada) in scientific applications is that the matrix index swapping between column-major and row-major was a real hassle. Also the different array starting index (0 versus 1) was a problem. Those differences made the interface difficult and error-prone.

#### Klystron

Gold Member
Yes, not only indices. Suppose you have several different platforms performing computations with different significant digits (so to speak). Researcher expects to retain data commensurate with sampling uncertainty and within function restrictions. The programmer offers least significant digits among multiple processors?

Let's consider recursive subroutines. Given the restrictions on recursive functions can the programmer ensure reliable results across the network [here I'm involving "hardware"; i.e., "stack" issues not directly related to language selection.] depending on the computation.

[Edit: Speaking of boundaries, I've exceeded the scope of this thread about language selection. Norm]

Last edited:

#### eachus

My experience with interfacing C and FORTRAN (and Ada) in scientific applications is that the matrix index swapping between column-major and row-major was a real hassle. Also the different array starting index (0 versus 1) was a problem. Those differences made the interface difficult and error-prone.
I'm a bit confused. I used Ada and needed an Ada library to interface with a BLAS written in Fortran. I declared several types with
pragma Convention (Fortran, T_...); the T to indicate Transposed. The parameters of the BLAS routines used these types, and I provided functions to convert from one to the other: function Transpose(Arr: in T_Complex_Array) return Complex_Array; and the reverse. (Fun detail, the bodies were identical--in source). Also there was a procedure version to avoid copying of arrays. My only problem was that I spent the entire project wondering off and on about how to write the transpose functions. They were only called by debugging and test code, so in that sense it was a non-issue. But..

For a large matrix, keeping both locations in L1 cache is a big win, although you expect the writes to overwrite the contents of the cache line, you want the the cache line resident so it doesn't get read for each write. So:

Code:
procedure Transpose(A: in Float_64_Matrix; T_B: out T_Float_64_Matrix) is
-- parameter checking and non multiple of eight handling omitted for clarity.
for K in 1..A'Length(2) loop
for I in 0..(A'Length/8) -1  loop
for J in 1,,8 loop
T_B(I*8+J;K) := A(I*8+J;K);
end loop;
end loop;
end loop;
end Transpose;
is much faster than the naive code--once arrays get large. Dividing the arrays into tiles that fit into 1/2 of L1D and transposing them should be a win, but I've never tried it.

#### FactChecker

Gold Member
2018 Award
Depending on what languages you are interfacing, the matrix transpose and changing the initial array index (0 or 1) may be necessary. There is additional complexity if some logic is looking at the indices and doing something with them. There are also cases where two languages are looking at the same data in shared memory or in a message and passing index information back and forth. It can get messy.
There are also cases where the data has more than two indices.

#### bhobba

Mentor
For numerical calculations (as in a lot of scientific/physics programs), FORTRAN is reputed to be the fastest.
FORTRAN and C are equally as fast. But everyone knows programs spend most of their time in a small amount of code. You write in an easy to write language like Python, then a faster language like LUAJIT for the critical parts found from running the code. For example here is a quicksort in Python:

def qsort(arr):
if len(arr) <= 1:
return arr
else:
return qsort([x for x in arr[1:] if x < arr[0]]) + \
[arr[0]] + \
qsort([x for x in arr[1:] if x >= arr[0]])

Dead simple. But you may need it faster. I have written a quick-sort in assembler so I would hack that rather than use Lua or C - but that's just because I am lucky in having the code. It's not hard in Lua though - and if that isn't fast enough use assembler - but as I said I was lucky enough to have one in assembler anyway so would go for that.

In general you could go to C for the ultra critical bits, but I tend to go for assembler - JuaJIT is mostly as fast as C. And yes you still need a minimum knowledge of C - its excellent for gluing languages together, plus I don't write assembler direct but rather as assembler statements in C.

I learned FORTRAN 35 years ago and avoided it as much as possible since then - never did like it.

Thanks
Bill

Last edited:

#### FactChecker

Gold Member
2018 Award
FORTRAN and C are equally as fast.
That is what I always assumed, but the benchmark results that I have seen had FORTRAN slightly (but significantly) faster. I have no explanation for that and have never done my own comparison tests to verify it.
I learned FORTRAN 35 years ago and avoided it as much as possible since then - never did like it.
IMHO, even by today's standards, FORTRAN has some excellent features for scientific/engineering use that are unmatched in other general-purpose languages.

Last edited:

#### bhobba

Mentor
Even by today's standards, FORTRAN has some excellent features for scientific/engineering use that are unmatched in other general-purpose languages.
It does with tons of libraries to call freely available. But I still reckon for real speed its assembler. No idea why FORTRAN would be bit faster than C, but personally I just use C as glue.

Actually in my degree I had to write some numerical analysis code - I had Pascal or FORTRAN to choose from - for me no choice - I used Pascal. As a professional programmer used a language called NATURAL, but after I retired moved onto Python and Lua. Do not know C that well - just use it for glue and in writing assembler. As usual assembler is a royal pain - but fast - really fast.

Thanks
Bill

Last edited:

#### FactChecker

Gold Member
2018 Award
Actually in my degree I had to write some numerical analysis code - I had Pascal or FORTRAN to choose from - for me no choice - I used Pascal.
When I was writing simulations of air-to-air combat, the ability in Pascal to write code like "ProbabilityOfKill( GoodGuy, BadGuy) = 0.5" where GoodGuy and BadGuy were enumerated types read as text from an input file was extremely appealing. Unfortunately, I was self-taught in experimenting with Pascal and there was no internet back then. I didn't know how to read/write a file of parameters containing enumerated types as text ( like "F16", "Foxbat", 0.5 ). I thought that it couldn't be done and left Pascal in disgust.

#### Svein

Way back when I started programming, the older guys were more or less married to FORTRAN IV. I did not care one way or the other until I had to debug a FORTRAN program - the error was that one instance of one variable was spelled wrong which made it an autodeclared variable which was never initialized but used in one particular spot.

Autodeclaration, three-way IF statements and hundreds of GOTOs - programming in assembly was less confusing.

### The Physics Forums Way

We Value Quality
• Topics based on mainstream science
• Proper English grammar and spelling
We Value Civility
• Positive and compassionate attitudes
• Patience while debating
We Value Productivity
• Disciplined to remain on-topic
• Recognition of own weaknesses
• Solo and co-op problem solving