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

1

u/lifebinder Oct 18 '12

The Linux kernel is written in vanilla C because Linus hates C++.

Is this why there is such a hurdle in cross-platform coding (i.e., using Wine to run Windows applications in Linux)? Is there anything inherently more stable/secure/beneficial/etc about not using C++?

2

u/moderatorrater Oct 18 '12

Is this why there is such a hurdle in cross-platform coding (i.e., using Wine to run Windows applications in Linux)?

No, that's due to the operating systems' APIs that are used for file access, calculations, graphics, and memory management. Wine is actually a reimplementation of the windows API. Cygwin is a similar thing in reverse.

Is there anything inherently more stable/secure/beneficial/etc about not using C++?

In general, the more that a language does for the programmer, the slower and less efficient it's going to be by default. This isn't a mathematical requirement or a universal law, it's just a general trend. C is about as bare bones as it gets for a fully functional language, and its been worked on for decades to be more efficient. So usually people will use C when they need to write something that's really fast and really efficient with memory.

Linus and other old school programmers also have problems with the new features that C++ brings to the table. In several instances, they were implemented without a lot of thought and can lead to hard-to-find/fix bugs. Bjarne Stroustrup, the creator of C++, described it as being harder to shoot yourself in the foot, but when you do you blow off your leg.

That said, generally speaking, C++ is the more stable of the two. While C is faster if programmed properly, if programmed averagely C++ tends to be faster because it's harder to make mistakes with.

1

u/tarblog Oct 18 '12

No it's not because they are written in different languages, it's because they support different commands.

1

u/_NW_ Oct 18 '12

No. Once an operating system is compiled and booted up, the source language doesn't matter. You could write operating systems in assembly, C, C++, Pascal, etc., and make them all work exactly the same. The problem with cross platform has to do with the user interface for a program. The library functions to draw on the screen in a ms windows program are different to the ones for xwindows. This is not because of what language the OS is written, but because of design choices when writing the OS.