What makes different programming languages “better” than others? Or more powerful? Why have different languages developed over time? Are they all based on the same thing?

1.21K views

What makes different programming languages “better” than others? Or more powerful? Why have different languages developed over time? Are they all based on the same thing?

In: 187

78 Answers

Anonymous 0 Comments

It depends on what you mean by “powerful.”

If you mean “Can some languages do things others can’t?” then it may help to understand a bit about how a program works and what a programming language is.

For a computer to do anything, certain circuits have to have voltages set in exactly the right way, which causes other voltages to be set in other ways. Here’s a mechanical one you can see operating with levers:

In your computer, it’s done with electrons, so it’s much faster (and also a lot smaller).

In the early days of computing, you had to flip switches to get the initial voltages set up the right way; you can watch the first minute or so of this: https://www.youtube.com/watch?v=Sr9mmsLQmYs

Eventually there were punched cards, which worked because electricity flows where there’s a hole and doesn’t flow where there’s no hole, and again you’re setting voltages in hardware.

The problem is that writing a program that looks like a page of 10010101010010010100101001010100101 is hard to read,
so “assembly language” was created. It looks like this: “add $t2, $t0, $t1”. So you can put values in the various registers and add the result to another register. But it’s not good for long or complicated programs.

To make this more readable, compilers were created for more readable programs, and now you can write “a = b + c” and hand it to the compiler, which will turn it into “add $t2, $t0, $t1” and then give it to the assembler to turn into “10010101010010010100101001010100101” and then it goes on the hardware and runs.

So, whatever language you write in, in the end it’s a bunch of voltages in circuits that actually runs the program. (Some languages are not compiled, they are run in a program called an “interpreter” that executes them directly, but the interpreter is itself compiled.) All modern general-purpose programming languages are equally powerful in terms of “what they can do.”

However, different languages have different strengths and weaknesses. For example, in C, if you have a space to hold someone’s name, you have to give it a size, writing something such as “char lastname[10]” because you have room for ten characters. BUT: (1) in C, a string of characters always ends with a NULL, so really that’s only room for 9 letters, and (2) it won’t ever get bigger. So if someone named “Fitzpatrick” comes along, it’ll get chopped off to “Fitzpatri” which isn’t good. In a language like Python, you can just have a space called “lastname” and it’ll hold however many characters somebody puts in, automatically growing as needed. And you might be thinking “Well, Python is clearly better!”, but in the actual hardware of the computer, it can’t make space get bigger like that. Python has to do a lot of stuff behind the scenes: it will make a space for a name, and if it doesn’t fit, it has to make a new space that’s bigger, and then move everything from the old space to the new space, and that takes time. So while Python is easier to write programs in, programs written in C often run faster.

And there are other things, too: in many languages, you have an “integer” type, which you can use to hold counting numbers. But you can make a programming mistake, such as “day = get_month”, and accidentally put the value for the month in the space for the day. In a language like Ada, you can say “day holds an integer of the day_type, and get_month returns an integer of the month_type,” and then if you make that programming mistake the compiler will stop and return an error message: you just stored a month where it expects a day. That makes writing the program even harder, because you have to declare different kinds of integers, but it also means that when you’re done, there are likely to be way fewer bugs, because the compiler can do extra checking. If you’re in a situation where “if this program doesn’t work right, people will die,” then you’re likely to want a language like Ada, which the extra effort is justified because people might die.

If by “more powerful” you mean “I can write more programs to do something in less time,” then a language like Python is obviously better than assembly language. But using a language like Python means you pay a bit of a speed penalty as compared to C, which maybe isn’t a problem if you have to do 100 things but what if you have to do a trillion things? And using a language like Ada will mean you write your program slower, but if people are going to die for mistakes you *should* be as careful and methodical as possible.

You are viewing 1 out of 78 answers, click here to view all answers.