Ask HN: What's wrong with procedural programming?
Without these OO stuff, C is still one of (if not sole) most popular programming language, and numerous complicated projects are written in C. So what's wrong with procedural programming? Is C++ really better than C?
9 comments
[ 597 ms ] story [ 355 ms ] threadSo what's wrong with assembly? Is C really better than assembly?
Each has its place for certain task. Languages let you abstract away different things and therefor think different kinds of thoughts while programming. Procedures add a whole new dimension to subroutines. OO adds a whole new dimension to procedures. Closures and functional programming add a whole new way to structure thought and code.
Would it be a good idea to use C to write a timing routine for a micro controller? Or to use assembly to write a gui?
You use the right level of abstraction (through the use of the right language) to think the right thoughts for the task at hand. Experience teaches you when to use what.
If you stubbornly stick to a non-object oriented approach when you should have used one, you'll likely end up reinventing a subset of object orientation anyway, probably badly.
"Programming languages differ not in what they allow you to do, but in what they make it easy for you to do."
I am not sure you're asking the right question. If you need a language that is close to the machine(but not assembly), then you go with C. If you need the OO concepts, you go with C++. Mind you, whenever you start using abstractions such as OO, you start to get away from the machine.
You can still use C++ to do procedural programming. So that's not the problem. Just that for some projects, using OO concepts to model the problem domain makes more sense.
Use whatever is right for the problem at hand.
IME, OO sometimes works, sometimes not. It's not necessarily about getting close to the hardware, either.
I can pull out my C++ compiler and write straight C (mostly)
What do you call that? C? C++? If I don't use classes in my C++, is it C? Or, conversely, if I develop a complicated module structure in C, does that make it C++?
http://harmful.cat-v.org/software/c++/linus
On the other hand, large corporations probably prefer OO programming. Paul Graham has some good quotes:
"Object-oriented programming offers a sustainable way to write spaghetti code. It lets you accrete programs as a series of patches. Large organizations always tend to develop software this way"
http://www.paulgraham.com/hundred.html
"At big companies, software tends to be written by large (and frequently changing) teams of mediocre programmers. Object-oriented programming imposes a discipline on these programmers that prevents any one of them from doing too much damage."
http://www.paulgraham.com/noop.html
I wouldn't say that C++ is "better" than C, but for certain tasks I think it is easier to use. Consider the C++ inheritance model; sure, you can do the same thing in C, but unless you choose a common convention, each new developer will have to learn your way of doing it. With C++, inheritance works in a uniform way, so a new developer doesn't have to guess at how you did it.
With that said, I think that there is something to be said for the simplicity of C, versus more complicated languages like C++. It is a bitch to learn C++, and some of the most unreadable messes I've seen were written in C++. So I think there's certainly an argument for C, but it doesn't have anything to do with whether it is OO or not.