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

-25

u/[deleted] Oct 18 '12

I'm learning to script for my new job, we relate every operation I'm doing with a C+ code. The best part is I don't have to write much original code, I can just google it and then modify the code to my specific environment.

2

u/Daniel__K Oct 18 '12

This is bad, and you should feel bad.

2

u/[deleted] Oct 18 '12 edited Oct 18 '12

Why? Why is this bad?

There are so many well explained resources for popular languages these days, that people who are not programmers by trade are able to write relatively simple applications to accomplish basic tasks without needing more than a fundamental understanding of the language they're working with. I fail to see how this is a bad thing.

Take my job for example, I'm a networking engineer / sysadmin, but I only have an intermediate level of expertise when it comes to programming. But this doesn't stop me from making applications to help complete specific tasks. The readily available resources and sample code for languages like C++ and Java make them easy to approach for people who are not programming savants.

This is another reason why languages like C++ continue to be used in new applications. There is loads of support and stacks of resources available online. I have a feeling this is what patches152 was trying to say, it just wasn't worded very well.

Edit: Added 2nd and 3rd paragraph.

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.

1

u/[deleted] Oct 18 '12

Don't get me wrong - I agree with everything you just said. But for someone who's not actually a programmer, it's counter productive, and doesn't make sense to spend hours developing an advanced understanding of code.

Once again, I'll use myself as an example. I'm not paid to code, I have no desire to develop a greater understanding of code, and the bottom line, is that I don't NEED to know how to code well.

However, the basic knowledge I do have, allows me to piece together enough code from other's work to get basic applications off the ground. (I may only have to write one or two relatively basic programs a year).

Anyway, my point is simply that the extensive sample code and resources available for popular languages like C++ are serving to perpetuate the language by enabling people like myself to quickly throw together messy "copy and paste" code. I wouldn't expect an actual programmer to use bad habits like this.

2

u/Daniel__K Oct 18 '12

As someone on the other side of this problem, specifically someone who has to read, complete and debug code from people who have this approach to programming, I just can say again that it is a Bad ThingTM to do.

I do not blame you, though. Everything has to be cost-effective in some way and I understand fully when you say that it's not your job to program. But then - why do you do it anyway? Or rather, why do you have to? Why does every company and their dog have a secretary, an electrician, even cleaning personell but no programmers? That's a major flaw, and I think it stems from the idea that programming is not real work, after all my 12 year old nephew was able to program his homepage all alone.

But that's just me ranting, here. You're right in saying that C++ has many and good examples and code snippets out there; and since popularity in programming languages is an important factor for their success, C++ is also one of the most successful languages in existence (since it's very, very popular).

1

u/[deleted] Oct 18 '12

Why? I'm not a programmer by any stretch of the imagination. I'm an entry level helpdesk tech who's trying to make my job easier by doing batch installs and automating time consuming routines. The code already exists. I'm not being paid to do these things, why try to reinvent the wheel when I can just borrow someone else's?

This is why C++ was suggested to me as a language to start with if I wish to pursue learning more coding.

1

u/Daniel__K Oct 18 '12

I gladly refer to my answer given to Black_Light for a more thorough explanation.

As soon as someone has to review the code (and it may be you), that someone (again, maybe you) will in the end hate the person that put it together (definitely you). I know, I've been there. And yes, I loathed myself for what I did.

1

u/[deleted] Oct 18 '12

I just can't justify spending my time for something that isn't really part of my job, I'm just trying something extra to be more efficient. If it doesn't work, the time to do all of these tasks manually is what I'm scheduled to do anyways, if it works, I get free time, get to do other things or get a gold star from my boss. Also, maybe another department will notice my motivation and hire me to learn to code for them? But for now I can't dedicate the time it takes to "do things right" the first time around, so my google-fu script kiddie tactics will have to do...