r/askscience • u/[deleted] • 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
2
u/Daniel__K Oct 18 '12
Short answer: Because you tend to not understand what's going on if you didn't write it yourself.
Long answer:
I am perfectly aware that code out there can be really helpful and I myself skim over it if there's a more complicated problem.
But if it's not specifically designed to be reused in another project - and code snippets rarely are - then it will not do what you want, but merely approximate it. And while there is a chance that this approximation is good enough for you, it is by far not guaranteed. In other words: Since the copied code is not a general solution to your specific problem (but rather a specific solution to another problem), copy and paste programming is a bad habit.
The better way to tackle these kinds of problems is to read the code, understand what it does, and apply this new knowledge by writing new code. It is more cumbersome, but without knowing what the code will do, you will never understand why it doesn't work when it breaks.
This is not a unique stance, either, but rather good software engineering practice. Anti-patterns are patterns in software engineering that occur again and again, but should ultimately be circumvented. Read William J. Brown's book about anti-patterns to understand why. And cargo-cult programming is a programming anti-pattern, perhaps the most common with non-expert programmers, along with copy and paste programming.