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.26K 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

Each programming language has different properties, making it better at some things, worse at others – and in the end, it also boils down to the programmer’s preference.

An awesome language that few people can code may be useless because you won’t be able to find people able to work on your program.

There are already existing pieces of code (called “libraries”) that help you do certain common tasks – e.g. downloading files from the Internet, or talking to a specific device. If there are libraries for doing what you want in one language but not another, you will likely choose the first one because otherwise you’d have to re-create those.

Some of these libraries come with the standard package that you get when you download that language, others you have to find yourself – that can make some languages with bigger “standard libraries” more convenient.

A big part is static vs. dynamic typing and compiled vs. interpreted.

Compiled means you write your code, then run a program to turn it into an EXE file, then run that EXE file. Interpreted languages often let you run each line by itself easily, which makes experimentation a bit easier, but they also tend to be much slower. But for a small tool that doesn’t do anything complex, that doesn’t make a difference, and interpreted languages can be easier to write.

Interpreted languages tend to be dynamically typed, while compiled languages tend to be statically typed. When you program, you have variables – boxes that you can put data into. In a statically typed language, you have to write on the box what kind of data goes inside, and you can only put that type inside. In a dynamically typed language, you just do whatever.

That means you may have to write

string a = ‘abcd’
int b = 123

in one language (string means text, int means number), and in another, it’d just be

a = ‘abcd’
b = 123

Much more convenient! But what if you do “a + b”? A statically typed language might decide “that doesn’t work, you can’t add text and a number, silly!” and if it’s a compiled language, it will tell you when you try to compile (build) your program. A dynamically typed language may start running the program, and only when it hits the “a + b” part crash.

As a result, statically typed tends to be better for large complicated programs, because such mistakes are easier to catch. For example, if you do

a = “1234”
b = 2

and try to add them, python will crash and say it can’t do that. Javascript will helpfully decide “ah, the second thing isn’t a text, let me convert it” and give you “12342” (it’ll join the two texts). Which is convenient for example if you want to do

alert(“Your number is: ” + b)

but very bad if you didn’t intend the first number to be a text.

Go will tell you “you can’t do that” as you try to build your program (not wait until you run it) so you can fix it early.

C… C is special. It is storing the text “1234” as the address of the memory where it is stored. And an address is a number. So you can add 2 to it… which means the result is “34” (a good compiler should warn you about it, but you may miss the warnings among the many other warnings programs tend to generate).

If the number you were adding was 5 instead, C would conveniently open a gate to hell for you. (The new address would point to a random piece of memory, and then random things might happen – and if someone else gets to choose both values, they may be able to use that to trick your program into downloading and running a virus – when you read “buffer overflow vulnerability”, that’s basically what happened!)

In C, you have to be a lot more specific about what you want done – it’ll take you a lot of time to write something that would be two lines of code in Python – but it will run much faster and what the computer does internally will be much more under your control.

And regarding the adding numbers to text thing… if I remember correctly, PHP will try to guess. That’s great, because `”12″+3` is `15` but `”Your number is: ” + 3` is `”Your number is: 3″`. But it also sucks because if i remember correctly there was something like PHP thinking that `1` is equal to `1abcd` (because the first is a number, so the second gets converted to a number, and it’s a 1 followed by garbage, so it’s a 1…)

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