eli5: How is C still the fastest mainstream language?

872 views

I’ve heard that lots of languages come close, but how has a faster language not been created for over 50 years?

Excluding assembly.

In: 2072

19 Answers

Anonymous 0 Comments

This is a lovely question and I created my account just to answer that.

C is a bare-bones language, putting the 50 years of compiler optimisateons aside, it lets you do everything you want, as you want. Do you want to substract 69 from letter “z” and multiply it with 5 and see which character do you end up with? Be my fucking guest. It fully “trusts” in the developer, it doesn’t check for anything. Doesn’t tell you that “you fucked up something”, it doesn’t say that “oh there is a type missmatch in line 479” or “you are trying to reach array element 498,371 in a 3 element array”. It basically converts your human readible code into machine code, and then executes it. If you fuck up, you fuck up. It doesn’t care if you are going to fuck up, it doesn’t care if you are fucking up, it doesn’t care if you did fuck up. It has one and only one goal; “do as the programmer says”. Which could be the greatest memory leak in the human history, but it does not care.

For other programming languages, you have tons of security schemes, keywords, accessability features etc., which makes the programming language “safer” and “easier to code” but suffers from performance.

Think of it like this; you want to book three rooms in a hotel (memory allocation), in most of the modern languages, you get exactly three rooms. If you want extra rooms, you can get them, if you stop using rooms, they will clean them and empty them, if you want to chect some of the rooms you did not book, they will stop you from doing so. But if you use C, you can do anything you’d like, do you want to access room no 5 without booking it? be my guest. do you want to change who owns room no 19? be my guest. do you want to create more rooms by digging a hole into the ground? be my guest. do you want to seduce the hotel manager and make him transfer the ownership of the hotel to yourself? be my guest. do you want to blow the hotel up? be my fucking guest.

On top of that, most C compilers are optimised for 50 years, meaning that even if your code is not optimised, they will optimise it. For example, if you are trying to sum some values (lets say sum i=1..N) in a loop, compiler will detect this and will replace this code with N*(N+1)/2 formula, which reduces complexity from N to 1.

Optimising your code doesn’t mean that you can’t do what you want, how you want tho. You can turn off all optimisations while compiling.

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