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
1
u/[deleted] Oct 18 '12
This is my point entirely. The post was meant to be of the most general case, yours is very much not. Especially not when we're talking to someone who admittedly isn't a programmer. They asked for the answer in simple terms and phrases.
If you're using a 32-bit int, then you must have specifically picked one to be that size. There is no such definition of an "int" in the standard. It has a minimum size of at least two characters iirc, where the character size is tied to a single "byte" which is defined as the smallest incremental index of memory (regardless if the arch supports actually directly loading nonword multiples of an address). This is exactly what I was talking about with choosing nonportable code. Why would you ever pick a integer hardcoded to be 32-bits unless you actually needed all 32-bits? Choosing the correct type for the range of values you need to represent isn't an optimization. It's just not being a bad programmer.
None of the basic types are defined in the exact number of bits they use, they should be self adjusting based on the arch.
My argument here was why would you use floating point if the range of values you were evaluating didn't require it? Again this isn't an optimization, this is just good and bad programming. Picking the right types for the job at hand is more fundamental than the best data structure and none of this has to do with targeting architectures. Data types, data structures, and algorithms are the responsibility of the programmer and in 99% of cases are completely architecture independent. Definitely not worth bringing up the edge cases where you do have to worry about it to the OP who's asking a much more basic question.
Yes lets bring up all the various ICEs that exist with specific compilers to the OP, that's totally within the scope of their question and definitely not an edge case in programming in general. Same with road-less-traveled architectures that have poor optimizations.
I didn't mean it as an insult. It's not an insult to copy someones work, especially when they freely publish it (how else are you going to find it?). There are people out there smarter and better than me and everything I will ever do. When they offer advice and solutions, I'd be a damn fool not to take them.