LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-03-2004, 06:50 PM   #1
tumana
Member
 
Registered: Mar 2004
Posts: 102

Rep: Reputation: 15
Should we move away from C?


I would like to ask people's opinions of why we are still using mostly C for Linux development. I know C is not the only programming language for Linux developers. Many other languages are available, such as C++, Java, Pascal, Perl, Smalltalk, ... but most Linux programming is done in C.

I don't mean to cut down on C. It is a very powerful language, but I wish more was done with C++, especially source code available for download off the internet. Although C++ is a progeny of C89, and I'm trying my hardest to not sound biased, but it seems to far surpass what C can do.

Can someone tell me in a professional and non-religious manner why we still use C?

Thanks,
ian
 
Old 12-03-2004, 07:16 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
There isn't anything in C++ that you can't do in C. Personally, I don't like C++ one bit. It's much easier to tell what your program is doing in C. For instance, if you declare a class instance, there might be a constructor you forgot about doing stuff, there might be a forgotten deconstructor when you delete a class instance. You can follow code easily and from beginning to end with C. Debugging is much simpler. C++ is good for people that want to install a library that has a well-documented interface and use it. That's not the kind of person I am. I like to know how and why my program is doing what it's doing. Too much is obfuscated. An operator might do one thing with one type of object but do something completely different with a different type of object. Too much "what the hell is going on in my program?" is more likely to occur.

I'm not saying everything I've just mentioned is pure fact and I know I'm stereotyping way too much, but it's my general viewpoint on it.

EDIT: What I mean by my first sentence is the main goal of the program; not that you can do operator overloading, polymorphing, etc. in C.

Last edited by itsme86; 12-03-2004 at 07:50 PM.
 
Old 12-03-2004, 07:44 PM   #3
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
C is a smaller, and arguably more elegant language than C++. C++ is very large and complex. That means it's very powerful, but also very easy to go wrong with it (of course, it's easy to go wrong in C, too). In general, I try to use Java for what little application programming I do, as I find it a better, if slightly less functional, OO implementation than C++. But C is still tops for system programming because it's not as bloated as C++ (an STL implementation would be royal bloat in things like the kernel) and just as powerful. You can write OO code in C -- I've done it. It's harder than doing OO in C++ or Java, bt it can be done.
 
Old 12-03-2004, 10:09 PM   #4
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
Simply put:

You can write C programs in C++. Therefore there is no such thing as moving away from C. Note that as long as you're using C++, you're using C in some form.

Mark the difference: Are you talking about the *compiler* C or the *language* C? A C++ compiler will be able to compile almost every C program out there. There are a few incompatibilities between C and C++ and those aspects may not work with a C++ compiler.

Writing a C++ program is very similar to writing a C program.
 
Old 12-03-2004, 11:59 PM   #5
tumana
Member
 
Registered: Mar 2004
Posts: 102

Original Poster
Rep: Reputation: 15
Very good replies. I'm surprised there wasn't someone who posted a "Because C rules!!" comment.

I see btmiller's point of keeping the language implementation smaller for kernel development reasons, but would having libraries such as the STL built into the kernel be so bad?
Quote:
A C++ compiler will be able to compile almost every C program out there. There are a few incompatibilities between C and C++ and those aspects may not work with a C++ compiler.
You are very correct. I think you are referring to how not every C++ compiler recognizes all C99 extensions, but GCC uses C89 which should be compliant with MOST C++ compilers... but you know how that works. I've learned C++ fairly well for Java programmer (I know it takes years to know the language well, but anyways...) and I've always had interest in contributing to the Linux kernel or open source dev in general, but my C++ knowledge is not 100% helping me. You just can't write code in C because you know C++.

The bottom line is I'm going to learn C regardless, but I wanted to see if anyone else had concrete reasons why we are still using C. Just a personal curiosity.

ian
 
Old 12-04-2004, 12:08 AM   #6
dmigh
LQ Newbie
 
Registered: Oct 2004
Posts: 29

Rep: Reputation: 15
1. i heard somewhere someone said ,

"i hope c with STL but hope not any other things from c++".

though, not exactly i remember, i agreed.

2. to say my opinion, i want alias in c. just like this.

#include <stdio.h> //note that this should be "iostream"

void func(int &a)
{
a=10;
}

int main()
{
int b=1;
func(b);
printf("%d\n",b); //note that this should be "cout << b;"
}

3. use classpath and gcj and free vm.
http://www.classpath.org
 
Old 12-04-2004, 01:46 AM   #7
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
I'm surprised that anyone who *knows* C++ will have to learn C.

Remember:
  1. You might need to learn the libraries in C, which is not the same as the language.
  2. C and C++ share the same syntax in most cases. A few keywords are different and a few others have different meanings in C and C++.
  3. You can write non-OOP program in C++. Technically it will remain a C++ program (because it may use some IO libraries which are specific to C++ like iostream and fstream) but for all practical purposes it can be considered as a C program.
  4. The other difference is the structure of the program:
    • A C++ program may use class while a C program uses struct.
    • You may encapsulate many functions in classes in C++ which might be global in C.
    • Concepts like event-driven programming are more suited in C++ than C because of having classes which can encapsulate events.
From the above points, I understand that if you are going in for GUI event driven programming in an environment like KDE or Gnome, use C++, because it is more convenient to handle events, windows, dialogs etc. in C++.

If you want to program text-based programs or programs without a GUI, you can use either C or C++ because after all, as I mentioned before, C++ can be used to write pure C programs also.
 
Old 12-04-2004, 06:27 AM   #8
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Quote:
From the above points, I understand that if you are going in for GUI event driven programming in an environment like KDE or Gnome, use C++, because it is more convenient to handle events, windows, dialogs etc. in C++.
That's not entirely true. The gnome and gtk API's (gnome is built on top of gtk) are in C, not C++, while they are object oriented and event driven. Though there are C++ API's for gnome/gtk available, these are interfaces on top of the native C API.
 
Old 12-04-2004, 06:52 AM   #9
vharishankar
Senior Member
 
Registered: Dec 2003
Distribution: Debian
Posts: 3,178
Blog Entries: 4

Rep: Reputation: 138Reputation: 138
I said C++ is more *suitable* for GUI programming. I never suggested that C cannot be used for GUI programming. Using C++ is much easier and cleaner...
 
Old 12-04-2004, 01:42 PM   #10
btmiller
Senior Member
 
Registered: May 2004
Location: In the DC 'burbs
Distribution: Arch, Scientific Linux, Debian, Ubuntu
Posts: 4,290

Rep: Reputation: 378Reputation: 378Reputation: 378Reputation: 378
Also it's possible to associate functions with structures using function pointers. With this, it's possible to do polymorphism of a sort in C (have a dispatch table of function pointers in the struct, and just have a function the calls the appropriate one). It's a bit ugly-looking, but not all that difficult to do if you know how.

Asd for having the C++ STL in the kernel, it would make the kernel a lot bigger, I would think. That may not matter much on a desktop machine, but imagine what it might do to an embedded system.

Last edited by btmiller; 12-04-2004 at 01:43 PM.
 
Old 12-04-2004, 03:46 PM   #11
tumana
Member
 
Registered: Mar 2004
Posts: 102

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by Harishankar
I'm surprised that anyone who *knows* C++ will have to learn C.
For the record... I didn't say I knew C++. I said "I've learned C++ fairly well for [a] Java programmer". In fact, I also admitted to the irony of that comment by mentioning how it takes years to become a veteran C++ programmer.

Anyways...

ian
 
Old 12-05-2004, 11:52 AM   #12
deiussum
Member
 
Registered: Aug 2003
Location: Santa Clara, CA
Distribution: Slackware
Posts: 895

Rep: Reputation: 32
Knowing C++ doesn't necesarily mean you know C. There are additional difference in C that must be taken into consideration such as having to have all variables declared at the start of a block... If you are used to C++ and you tend to declare your variables at the point they are first used, you might be confused by the errors that a C compiler gives you if you were to do the same thing in C.
 
Old 12-05-2004, 01:11 PM   #13
jtshaw
Senior Member
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 67
These arguments of what language to use for everything and what not are always pretty silly.

Linus picked C for the linux kernel for a few different reasons. One, the compiler was a lot better for C at the time. Two, C is aimed at mid-level tasks. It doesn't necessarily make sense to abstract things out in kernel code. Kernel code should be very straight forward and very easy to understand. It is quite remarkable how easy it is for a person with a decent grasp of C (and maybe a little system's knowledge) to pull up kernel code and easily understand how everything is working. The third reason, of course, is Linus believes the C++ ABI is totally broken. He has some good points, but that is an argument for another day.

What people learning how to program should be doing is not emphasizing on a particular language. A good programmer can pick up a language in a few weeks, because syntax is the easy part. Fundamental knowledge of different programming techniques and data structures is the hard part.
 
Old 12-05-2004, 08:21 PM   #14
tumana
Member
 
Registered: Mar 2004
Posts: 102

Original Poster
Rep: Reputation: 15
Quote:
Originally posted by jtshaw
The third reason, of course, is Linus believes the C++ ABI is totally broken. He has some good points, but that is an argument for another day.
I've read a bit about the problems with the C++ ABI and it makes pretty good sense. I can see the hassle avoided by using C for major distributed projects such as Linux.

ian
 
Old 12-06-2004, 01:04 AM   #15
shy
Member
 
Registered: Dec 2002
Location: Russia
Distribution: ASP linux
Posts: 94

Rep: Reputation: 15
Take a look at The linux-kernel mailing list FAQ, section "Why don't we rewrite the Linux kernel in C++?". It has a good explanation of C++ drawbacks, at least for the kernel.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
cannot using FTP move command to move files adrianmak Linux - Networking 4 04-21-2009 12:01 PM
Mandrake Move 2.0 ronan180989 Mandriva 1 02-15-2005 06:20 AM
mandrake move ADCOOL Linux - Wireless Networking 1 12-07-2004 02:22 AM
Should I Really Move?? operator87 Linux - Software 5 09-13-2004 01:27 PM
Should I move on?? New2Lindows Linux - Distributions 14 08-15-2003 01:58 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 04:13 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration