Why do people still use C ?

Started by
121 comments, last by Oluseyi 19 years, 6 months ago
Hi, I was quite curious why people still use C, if C++ is just as fast , has backwards compatibility and has OOP capabilities. As at my friend's uni, the are currently teaching them that, im not sure what course he's doing, ...forgot to ask. Also apart from updating existing c programs. Thanks
Advertisement
Your friend is probably being taught that because C programs are programmed differently than OO C++ programs. It's best to have experience with a wide range of programming paradigms.
Disclaimer: "I am in no way qualified to present advice on any topic concerning anything and can not be held responsible for any damages that my advice may incurr (due to neither my negligence nor yours)"
Some reasons to use C are:
- Existing applications
- The platform you are developing for has no C++ compiler (embeded systems)
- You don't need te features of C++, since you need maximum speed. Low level code, like drivers, operating system stuff...
Some people simply like C more than C++. They do usually use a modern C++ compiler to code with though, which is backwards compatible as you said.

If I'm writing a small program I usually code in classless C++, using just functions but making use of features of the C++ language like new/delete. If I'm writing a larger program I use OO code.
I would say it's because no matter what platform you have to work on, there is most likely a C compiler for it. The C runtime library is small, fast, and relatively easy to implement compared to the C++ runtime library. Often times the first thing done for a new platform is writing a C compiler and runtime for it.

C is good to know so that one day when you have to work on platform XYZ that doesn't have a C++/"insert favorite language here" compiler, you can be pretty sure it has a C compiler.
"Is life so dear, or peace so sweet, as to be purchased at the price of chains and slavery?" - Patrick Henry
Why are you still using C? (pdf)
If you us ANSI C it is much easier to port your application to other platforms, because (as was said earlier) most platforms have a C compiler. Also some people (myself included) prefer structured programming as opposed to OO. At work I use C to program for an embedded system.
I love whiskey
C is not often used by new programmers or many hobbyists because it requires dicipline, and that's no fun! ;-)

But once writing code is about getting the code written, C is

1. Clean. Super clean. Diciplined C code is a dream to read.
2. Fast. It's C, after all.
3. Portable.
4. can be as abstract as necessary.

So basically, a lot of people look at what they want to write, decide that it need to be lean and mean, and so dismiss things like python, vb, c#, whatever, and then choose C by default.

Why not C++? Sure, it's fast ("only pay for what you use"). It's only somewhat less portable. But the abstraction and clean parts get messed up.

Huh? abstraction in an OOP languages being worse than a non-OOP language?

Yeah. OOP is sometimes a square peg for a round hole. Sure, C++ lets you solve those problems by using a different style, but suddenly you loose all that syntax sugar C++ has for OOP and you're left with horribly ugly code. Just look at some of the template functional programming garbage. Horrendously complex.

And it's not like you can't write OO code in C. and when you do, its style is more consistent with other programming styles.
a lot of the OOP in C++ is done during pre-processing. Classes end up getting converted to regular C functions and structures during compile time. It's not like C++ is going to be faster. The real difference is that C++ may to some people feel more user friendly and they may like using it. C++ simply adds a *this pointer parameter to functions of classes and passes *this pointer for you ... This can be achieved in C just as well but will not look or act as pretty.

picture this:

c
rotate(theobject,x,y,z)

c++
theobject.rotate(x,y,z)
or
theobject->rotate(x,y,z)

Really their is no difference at the end of the day. If you are looking for a language that masks the underlying code from you to help you program better, then you should look into Java or .Net languages, because in general thats all they do.
-------------Become part of developing the specifications of a new language. Visit CodeBASIC.org
As it happens, I remember I've always liked using C libraries better than the C++ ones (OpenGL vs. DirectX, SDL vs. CDX, and others). The very same goes for my own modules.

Portability (between platforms and compilers) and compiling speed are some other advantages.

The biggest reward for not going C++ has been that it is vastly easier to connect a C program to other languages than it is for a C++ one. I try to move away from C as well, but C++ is not where I want to end up. I need a dynamically typed language, like Lua or Lisp. (Lua by the way is coded as a vanilla C library.)

This topic is closed to new replies.

Advertisement