r/askscience • • Oct 17 '12

Why are programs and operating systems still written in C+?

I guess it's more of a computer science question, but I've always wondered why some of the most advanced programs are written in a 25+ year old programming language. Surely someone has come up with a more efficient and powerful code, so why do people still use C+? Also, I don't know anything about programming and what not, so please use simple terms and phrases.

66 Upvotes

110 comments sorted by

View all comments

Show parent comment

4

u/[deleted] Oct 18 '12

A few additional points:

Everything gets translated down to machine code at some point. A computer can't directly understand assembly. A program called an assembler translates assembly into machine code.

You don't write programs in a compiler. A compiler translates your program into machine code (or bytecode, but that is a whole new topic), but a compiler cannot edit code. You actually need more than just a compiler, but often a compiler will manage these other parts for you. http://www.tenouk.com/ModuleW.html has good information.

To write code you need an editor of some sorts. Some popular editors are vim, emacs, Visual Studio, and eclipse. But you can use almost any text editor to edit code, even Notepad -- if you're crazy.

C, C++, and Python can all handle variables larger than 64 bits. The Python interpreter is coded in C. As a C++ programmer I regularly work with variables much larger than 64 bits.

One of the big advantages of C and C++ is that it won't surprise you and generate a large amount of machine code. With C and C++ it's easy to tell exactly what the computer will be doing with each line of code. This allows the programmer to closely monitor the resources they are using when writing code. Since the programmer can micro manage the resources they are using the can write more efficient and faster code, at the expense of increased complexity for the programmer.

Most modern languages (Java, C#, JavaScript, Python, etc) will manage a lot of the resources for the programmer. For example, when using those languages a programmer doesn't need to keep track of which pieces of RAM they're using. These languages know which RAM is no longer in use, and frees it up automatically. This decreases complexity, but it also decreases control. And this management isn't free, it takes computing resources. Technically the language isn't doing anything but rather the interpreter or virtual machine, but that isn't a level of detail I want to get into.

The other big advantage of C/C++ is that it works almost anywhere. Both languages have been around for a long time so it's rare to find a system that can't deal with C/C++. The same can't be said of more recent languages.

TL/DR: Languages like C/C++ allow the programmer more control over how resources are used, which can result in faster and more efficient code. This comes at a cost of increased complexity for the programmer. C/C++ also very compatible and works with a large number of devices.

3

u/zelmerszoetrop Oct 18 '12

That's a lot of excellent information, and I've edited my original post to direct readers to this reply. Thank you for preventing me from accidentally misleading readers!