

Ask HN: What's wrong with procedural programming? - wenchuan

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?
======
noonespecial
Try this:

So 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.

~~~
roundsquare
I think its best summed up by a quote from some Perl book I read (sorry, don't
remember which one).

"Programming languages differ not in what they allow you to do, but in what
they make it easy for you to do."

------
chanux
You need to read this
[http://web.mac.com/jimbokun/iWeb/Site/Blog/AB35C167-7755-411...](http://web.mac.com/jimbokun/iWeb/Site/Blog/AB35C167-7755-4113-938C-968F65256D76.html)

------
scorpioxy
Nothing wrong with it.

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.

------
humbledrone
The fact that C is the most popular programming language is not a good
argument for procedural programming, because it is quite common to use OO
techniques with C. In fact, most of the C projects that I have worked with use
OO techniques in some form. For instance, look at the Linux kernel. There are
plenty of structures that include function pointers, which in practice is very
similar to inheritance. Also, consider the UNIX concept of a "file"; that's OO
design, pure and simple.

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.

------
subud
C is probably better for writing cross-platform (Win, Mac, Linux) code than
C++. See Linus Torvalds comments:

<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>

------
pmccool
It's not just C. A lot of procedural code is written in perl, for example.
It's true that languages that force you to write procedural code are
relatively rare, but languages that force you to write OO are by no means the
rule.

IME, OO sometimes works, sometimes not. It's not necessarily about getting
close to the hardware, either.

------
DanielBMarkham
Instead of going down this same road yet again, I've got a better question for
you:

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++?

