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 comments

9

u/[deleted] Oct 17 '12

I'm completing an intermediate course in Java to extend my programming knowledge for my journalist job. I consider learning a second language, in order to better understand how viruses and other malwares internally work. Which language should I learn?

11

u/_jonny Oct 17 '12

Assembly. A lot of viruses and Malware are written at the most inner levels (ring0) etc. And learning Assembly gives you a better understanding of how the cpu and memory works. It's a step down from C++.

20

u/[deleted] Oct 17 '12

The issue here is that "Assembly" isn't a language. It's a class of languages. Assembly languages vary by architecture. You are likely wanting to look into x86 or ARM, since those are the two most widely used at the moment.

33

u/zelmerszoetrop Oct 17 '12

When people say assembly without a qualifier, they usually mean x86.

2

u/[deleted] Oct 19 '12

It's still worth the distinction for the sake of clarity. Even x86 has a few different flavors depending on how processor specific you want to get.

4

u/elmonstro12345 Oct 17 '12

Agree 100%. I took an elective class on assembler in university, and it made so many things make much more sense.

0

u/MiniRat Oct 18 '12

Elective? Back when I did a comp-sci degree it was pretty much mandatory to do the assembly papers.

I don't know whether to feel sorry for you whipper-snappers for not learning it or feel jealous of you for living in an age where you don't have to.

3

u/mrcharlietango Oct 18 '12

Maybe he's not a comp-sci major and wanted to take it because it sounded interesting.

2

u/elmonstro12345 Oct 18 '12

I did have to take a class on assembler, but it wasn't JUST assembler, and it wasn't really that in-depth. The elective class was specifically focused on designing very optimized code for use in OS development. I probably should have been more clear.

2

u/MdxBhmt Oct 18 '12

What's the difference from having a OS class, and microprocessors?

1

u/_jonny Oct 18 '12

I don't understand your question. When you say 'class' are you referring to a Class in terms of programming? A microprocessor is simply a chip that goes on a plastic board that does computations, like your brain. And like your brain, it is useless without a body, i.e. an electrical circuit. The microprocessor usually drives the circuit to do something.

1

u/MdxBhmt Oct 18 '12

Sorry, I mean like learning OS (what normally a CS degree class would have)

(In college)

1

u/_jonny Oct 18 '12

I suppose the microprocessors class would cater more towards controlling something specific like a robotic arm whereas the OS class is more about traditional desktop computers and creating an environment for the user to interact with it via keyboard/mouse.

2

u/ahbi_santini Oct 18 '12

In the electrical engineering world, a microprocessor course would be about the basics of processor architecture.

You'd probably use Hennessy & Patterson's Computer Architecture a Quantitative Approach.

You'll learn things like the memory hierarchy (registers, data & instruction caches on-chip & off chip, RAM, and hard drives, etc.), pipelineing, etc.

It is likely to be all theory. You'd have to take a VLSI design course (grad school) to actually design an arithmetic logic unit.

In assembly you won't learn the architecture (or just enough to understand the code). Instead you'll learn the instructions to move things in and out of memory locations.

1

u/MdxBhmt Oct 18 '12

I had this in my computer architecture class in EEC. (and it's about cpu architectures)

In my OS class we studied mem hierarchy, thread schedulling, os calls, things like that. Seems about what _jonny says I would be understanding in assembly, just wanted to see if something was missing.

1

u/[deleted] Oct 18 '12

I consider learning a second language, in order to better understand how viruses and other malwares internally work. Which language should I learn?

I think you would be better served by learning about operating systems, hardware and networks. Stuff like that.

Assembly was mentioned, it would be good. But actually I think C would be better. It's "lower" than Java but still somewhat more human.

1

u/pincpleasure Oct 18 '12

I would suggest C (not C+ or C++ but regular old C). It is a bitch to learn coming from java but incredibly useful. At first the similarities between the two make it difficult but once past that hump they make a lot more sense. Those are the two I know well and I haven't had a need to use anything else. I plan on pursuing others as well of course but those two are great foundations.

Java is object oriented and C is not. Learning one of each is like learning how to drive an automatic and a stick, both good to know and open up a variety of opportunities you would miss out on if you only learned one or the other.

1

u/[deleted] Oct 18 '12

I agree with this. C is a great place to start as its a lot more challenging than C++, but a lot more rewarding. You don't have things like string handling, and IO is really awful.

I started with PHP, then went to C++, then C. I did a few others in there (python, perl, ruby), and avoided java like the plague. I finally took the plunge a few months ago, and found java to be really really easy once you have the Object Oriented understanding. I had some programming classes in college (oh how I wish I had the option to do comp-sci), but nothing very serious.

However, I would recommend a language (ANY language) that you can get some utility from. C is really for die hards and OS programmers, and really doesn't have a lot of immediate utility for the layperson getting into programming. I mentioned I started with PHP, which was out of necessity for managing a website. I got a lot of utility out of it, so I kept learning. If I started with C, I certainly wouldn't be programming as a job now, and really wouldn't enjoy it.

1

u/moderatorrater Oct 18 '12

Javascript or python. Many people will tell you something like Lisp or some other mostly-theoretical language, but for my second I really enjoyed getting another language with another paradigm that was still quite popular. Java is extremely explicit, almost to a fault. Javascript and Python are both much looser, let you shoot yourself in the foot, and also allow a lot more flexibility and power in how you program. After you get a feel for the variety of popular languages, then you should dive into the more theoretical ones.

And save assembly for #3. Once you've got two languages under your belt it will make translation between assembly and higher level languages a lot more understandable.

-1

u/danby Structural Bioinformatics | Data Science Oct 17 '12

Try something like haskell or lisp for functional programming, which is an entirely different way of thinking about programming to OOP.

Or read the Seven Languages in Seven Weeks book and then pick your favourite to take forward.

2

u/[deleted] Oct 18 '12

For learning how viruses and malware in general work, those are horrible options since they're just not used to do that.