Suppose a program was written in two distinct languages, let them be language X and language Y, if their compilers generate the same byte code, why I should use language X instead of the language Y? What would make a language better than the other to resolve a problem? What defines than one language is faster than other?

About the language speed... I asked that because often you see people say things like: "C is the fastest language, ATS is a language fast as C". I was seeking to understand the "fast" definition for programming languages.

  • 1
    $\begingroup$ It looks to me like this is a very general computer science question and is, therefore, not appropriate for this particular list. Beyond that, it is unlikely that compilers for two different languages would produce the same binary code for a non-trivial program so the question starts with an unrealistic premise. $\endgroup$ – Bill Greene Mar 8 '15 at 17:12
  • 3
    $\begingroup$ I think it's worth keeping here since computational scientists often must weight the tradeoff between programmer time and computer time. Programming is certainly not solely the domain of Computer Science. $\endgroup$ – Bill Barth Mar 8 '15 at 17:20
  • $\begingroup$ "What defines than one language is faster than other?" If the two have the same byte code then how can one be "faster." You should probably edit your question to cut that sentence or clarify what you mean. $\endgroup$ – horchler Mar 9 '15 at 4:31

Suppose a program was written in two distinct languages, let them be language X and language Y, if their compilers generate the same byte code, why I should use language X instead of the language Y?

Programmer productivity is important. If it's easier to get the job done with language X -- which could be for various reasons, like syntax, libraries, tools -- than language Y, that's a net win. If their compilers generate the same byte code, as far as I know, they'll execute in roughly the same amount of time under comparable conditions (same hardware, same load, etc.).

What would make a language better than the other to resolve a problem?

Performance is usually a limiting consideration; if performance matters, you're almost certainly going to look at a compiled language and exclude interpreted languages. After that, it's usually some combination of personal preference and programmer productivity to maximize useful work done before deadlines.

For an example of a productivity versus performance argument, interpreted languages like Python, MATLAB, and Julia typically lead to shorter programs accomplishing a given task; here's one example of an empirical ranking, but there are others, such as in Code Complete. This phenomenon typically has a number of consequences, like:

  • it's usually faster to write such a program
  • it's usually faster to debug such a program
  • it usually means there are large standard libraries available to accomplish common tasks

However, the cost of this expressiveness is usually performance, which you can see in benchmarks, so the typical pure Python program is usually 2-3 orders of magnitude slower than a typical C program; for Julia, it's supposed to be more like a factor of 2ish, which is why it's popular.

Also, you have to know -- and be good at -- these languages to extract performance from them, and for MATLAB and Python, if a pure interpreted language implementation isn't fast enough, you have to start replacing parts with compiled language implementations anyway. Once you start delving into multi-language programs, productivity goes down, and it's harder to debug. Similarly, if you have to learn one of these languages, that takes time, and when you're not a language expert, you program more slowly than if you are a language expert. So there are a number of tradeoffs.

| cite | improve this answer | |

The questions you ask, in general, are quite difficult to answer because there are just too many languages for so many things. Each language has been built either to satisfy some necessity or for some intended audience. Also, even for general-purpose languages I think these are built in a way it can serve better to a particular subgroup.

Anyway, I don't know what are your expectations about using a programming language in general, so I will try to answer your question in a intuitive (maybe even wrong), and biased, way. First, lets talk about execution speed: speed and size is not directly related to the semantics of a language in particular, but on how its associated compiler translates your source code into processor instructions. In the era of 256kb RAM mainframes, code efficiency was a must, thus most languages tried to stay as close to assembler code (faster, processor-dependent programming language) as possible. Two examples of this era are FORTRAN VI and K&R C. Nowadays, the gears are shifting toward greater levels of abstraction (Java, C++, F2003, etc), and higher performance (F2008, UPC, C++, etc) languages, which intertwine new language semantics with system architectures. I think that we will get into a point in which making one single processor faster would become very expensive due to the appearance of quantum effects, so the future might be going towards massively parallel systems (mainframes, again!) in order to be fast.

About which language is better: it depends. Depends on what field are you, on the existing/previous code you have to work on, and personal taste of course. For example, people on mathematics and/or working on FEM would tend to work more in languages that let have higher levels of abstraction (i.e. C++, pascal), whereas people working on the physics and/or engineering sciences tend to work more with "procedural" (not quite true, but...) languages like FORTRAN, UPC, or C. Why the difference? To be honest I don't know, but some people tend to be really opinionated about this. Of the five languages I have mentioned, you can do whatever the mathematician/physicist/engineer does, with relative ease. How do I know? Well, I decided to do a parallel 2-D Navier Stokes solver in FEM both in C++ and FORTRAN and, from the programming perspective, the difficulty was relatively the same (on the c++ code I got 130 lines more of code, but that’s a different story).

ADVICE: try to pick a language that you know is widely used in the specific realm you are going to be working. Learn all the available programming paradigms (also parallel) in that language. By corollary, moving to another language would be just a matter of learning the "new words"

| cite | improve this answer | |
  • $\begingroup$ Thanks for time. This doubt appeared when I was talking to one of my professors, we were discussing about what language would be better to implement mathematics. We got to the impasse if a functional language like Haskell would be better than an OOP such as C++. $\endgroup$ – Rodrigo Valente Mar 10 '15 at 19:16
  • $\begingroup$ It really boils down to personal taste. Languages like haskell and lisp tend to be more "familiar" with matematicians because of its semantics. I've seen (not worked) a lot of people working on neural networks and artificial intelligence using these languages. If your goal is to work with FEM (DG, LEAST SQUARE, etc), I would recommend to to go with a language that supports OOP and also implements one parallel paradigm (or has libraries). My personal favorite is Fortran 2008, but you can go for C/UPC/C++ as well. There is a new interpreted language called Julia, but is still beta. $\endgroup$ – Kbzon Mar 11 '15 at 9:06
  • $\begingroup$ Thanks, you're being of a great help. I was thinking about the subject of my work for course completion, where would implement some mathematics in two different languages and compare them. But seems that my perspective about the languages subject is to small yet. Think I will have to review my ideas. I'll look up to your suggestions. $\endgroup$ – Rodrigo Valente Mar 11 '15 at 14:13

There are lots of things including clarity of syntax, expressibility (e.g., array slicing, support for whole array operations etc.), availability of of APIs/libs etc. E.g., if you want to use OpenMP then your choice of language is rather limited. Same argument holds for things like MPI, numerical libs etc.

In an ideal world you should be able to use any language that would eventually generate the same machine code. It might be true a few years/decades down the road especially with things like LLVM.

| cite | improve this answer | |

Not the answer you're looking for? Browse other questions tagged or ask your own question.