LinuxQuestions.org
Visit Jeremy's Blog.
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 02-27-2004, 05:03 PM   #1
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Rep: Reputation: 31
Discussion: Why use C/C++?


You know, I continually see more and more people ask about how to develop using C/C++ and I rarely what exactly they are using it for. To me, C and C++ are very rarely the best choice of language for a given project, but I see them everywhere. So, my question is directed to those of you developing things in C or C++, or possibly if you are just learning C or C++ for future use. And that question is: why C/C++? Bonus question: What other languages have you considered?
 
Old 02-27-2004, 05:35 PM   #2
cjcuk
Member
 
Registered: Dec 2003
Distribution: Openwall, ~LFS
Posts: 128

Rep: Reputation: 15
I use C, primarily, because a lot of my coding is related to kernel work and security tools ( especially binary analysis ). I also use it because it is one of the better implemented languages on pretty much every platform I have worked with. You can pretty much guarantee you will find a decent C compiler before you get anything else ( possibly, because the others cannot exist first ). I also enjoy the extra power ( though it is a danger for the inexperienced ) that C/C++ offer me in my relation to the machine.

As a less important note, I use C because I like it. It is fast and reliable -- I know what my code is going to do. People using an interpreted language can rarely claim either of those things. This category is really where your statement falls, as you have said they are rarely the best choice _to you_.

As for other languages, I will program in anything that fits the task. C just very often best fits my needs. However, I have been known to use Perl, Scheme, Shell scripting, Ada, and even Java where I am forced to do so by requirement of the project ( I kind of dislike Java =), but lets not get into knocking languages ).

My question to you in return, is what is a valid reason to _not_ use C or C++?. I would not consider memory handling issues ( that is a bad programmer, not a bad language -- do you know the overhead of a GC? ) or issues relating to highly abstracted data objects ( have you ever run one of those programs through cache analysis and watch them smash to pieces any chance of good performance? ) -- though you can if you wish.
 
Old 02-27-2004, 06:14 PM   #3
krajzega
Member
 
Registered: Jan 2004
Location: Poland
Distribution: FreeBSD 5.1
Posts: 92

Rep: Reputation: 15
1. 95 precent of UNIX is written in C/C++
2. Most *NIX apps are written in C/C++
3. C and C++ can learn you many aspects of programming but also lots of computer issues, for example alocating memory, working on streams, tcp/ip ..and it can make you understand it not only in programming case (for example: I couldn't have understand tcp/ip without programming sockets..it was too difficult).
4. Its the best language
5. However it can be right question on windows or dos programming forums, here is just stupid
 
Old 02-27-2004, 06:31 PM   #4
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Original Poster
Rep: Reputation: 31
Quote:
Originally posted by krajzega
1. 95 precent of UNIX is written in C/C++
And?
Quote:

2. Most *NIX apps are written in C/C++
And most of those shouldn't be.

Quote:

3. C and C++ can learn you many aspects of programming but also lots of computer issues, for example alocating memory, working on streams, tcp/ip ..and it can make you understand it not only in programming case (for example: I couldn't have understand tcp/ip without programming sockets..it was too difficult).
Many other languages can do the same and aren't as dangerous nor as hard to write programs in.

Quote:
4. Its the best language
For what?
Quote:

5. However it can be right question on windows or dos programming forums, here is just stupid
Oh please, at least try and pretend to be civil.
 
Old 02-27-2004, 06:37 PM   #5
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Original Poster
Rep: Reputation: 31
Quote:
Originally posted by cjcuk
As a less important note, I use C because I like it. It is fast and reliable -- I know what my code is going to do. People using an interpreted language can rarely claim either of those things. This category is really where your statement falls, as you have said they are rarely the best choice _to you_.
Okay, then let's go ahead and assume I didn't say "To me," in that sentence.

Quote:
My question to you in return, is what is a valid reason to _not_ use C or C++?. I would not consider memory handling issues ( that is a bad programmer, not a bad language -- do you know the overhead of a GC? ) or issues relating to highly abstracted data objects ( have you ever run one of those programs through cache analysis and watch them smash to pieces any chance of good performance? ) -- though you can if you wish.
I would consider memory handling issues VERY important. I don't care if good programmers rarely make such mistakes, programming in languages where you don't have to worry about it means you will NEVER make mistakes about it. Yes I am aware of the overhead of a garbage collector, but for user-end apps such a performance hit is negligible. I'm not asking about things where performance is a top priority, I'm asking about the majority of desktop apps, where a 100ms overhead isn't going to be noticed or even cared about.

Another issue? The fact that it takes lines upon lines of code to do in C/C++ what it takes a handful of lines to do in higher-level languages. This makes more places to make mistakes (like costly memory ones), and means more development time.

Another issue? Learning to be a good C/C++ programmer takes more time than it does to become, say, a good Python programmer. So what you end up with is a lot of mediocre C/C++ programmers who never bother to learn enough to make themselves good programmers, simply because they can get their tasks done... only they don't get them done in the best way.

Last edited by Strike; 02-27-2004 at 06:39 PM.
 
Old 02-27-2004, 06:41 PM   #6
LauroMoura
Member
 
Registered: Feb 2004
Location: Carpina, PE, Brazil
Distribution: Ubuntu 5.10
Posts: 44

Rep: Reputation: 15
Quote:
Originally posted by krajzega

4. Its the best language
I would say its the best language for MOST cases, not ALL cases....


C/C++ are great languages. They give you good control of the machine without being hard to read as Assembly.

For most cases, as running a program in a local machine, that will use the same system EVERYTIME, it's perfect. But for running a program (multiples copies) over multiple systems, a language like Java is better.
 
Old 02-27-2004, 06:47 PM   #7
infamous41md
Member
 
Registered: Mar 2003
Posts: 804

Rep: Reputation: 30
i like, no LOVE, C b/c i can write a program, compile it, and then explain to you what every single byte in the executable and memory image will do and why it does that. and that is a beautiful thing.
 
Old 02-27-2004, 07:11 PM   #8
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
Performance is the only reason i would resort to C or C++ if i had a choice. I love these languages, but more on an 'interest' level. They are powerfull and i wish i had more time to explore them.

Right now i'm doing MFC (which is C++) and it's just a pain in the ass. Not because of the language, but because of it's design. So during those times i long for Java (or VB Forms) simply because you could get your work done much much faster with less hassle. It's takes much less time to get 'good' in higher languages than in C or C++. I've struggled (but still loved) C++ for more than a year, and yet after only 3 months of Java i felt like i was actually able to do something with it.

One of the main advantages of knowing C or C++ is of course that when you move to something higher up you can actually deduce wtf is going on in those encapsulated methods and functions (big bonus in my opinion and i'm glad i went through the C route before doing more Java).

Anyway, i've also found from experience (looking at my friends, etc) that many people prefer C or C++ because they tend to have difficulty with OO design. It really takes some time to get used to how to properly design and work with OO. Some people find it easier to stick to more straighforward procedural structures. Just a general observation here so don't kill me. Personally i can't do anything without thinking of objects these days. After a year since i started OO, i'm finally able to use it 'correctly', and now i can't go back

BTW, in the past i've explored: Perl, Lisp, Python, VB.NET, C#, Java and PHP. My favorite overall so far is Java. C# will probably become my Windows programming language (its very similar to Java). Python or Ruby will most likely become my future love.

Quote:
I would say its the best language for MOST cases, not ALL cases....
I wish more people would have more experience to pick the right language for the right occasion.

Quote:
Another issue? The fact that it takes lines upon lines of code to do in C/C++ what it takes a handful of lines to do in higher-level languages. This makes more places to make mistakes (like costly memory ones), and means more development time.
Not if they realize they can encapsulate the behaviour and just use that. But yeah, i know what you mean here. Even on a higher level, i've seen people repeat a lot of lines over and over without just putting it in a function or something like that. Even people that were all about encapsulation and moving to higher languages.

Last edited by coolman0stress; 02-27-2004 at 07:14 PM.
 
Old 02-27-2004, 07:13 PM   #9
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Original Poster
Rep: Reputation: 31
Quote:
Originally posted by LauroMoura
I would say its the best language for MOST cases, not ALL cases....
Except for the issues mentioned above, I guess ...

Quote:
C/C++ are great languages. They give you good control of the machine without being hard to read as Assembly.
And higher-level languages provide you nearly the same amount of control while being VASTLY easier to read and use than C or C++.


People seem to be avoiding the bonus question, but it's just as pertinent as the main question. It also helps qualify your opinion as informed or not...
 
Old 02-27-2004, 07:15 PM   #10
dakensta
Member
 
Registered: Jun 2003
Location: SEUK
Distribution: Debian & OS X
Posts: 194

Rep: Reputation: 35
1) It's what I know best - to get to a vaguely comparable level in another language would take time and effort I don't really have to spare ... something to do in the future maybe?

2) LOADS of relevant (to me) libraries are written in c/c++ which, especially on *nix, are trivial to install and use and are readily available. Sooo many people use c/c++.

3) I know that, even if I don't spend a lot of time on design, I will get more than adequate performance and if need be, I have a good idea where and how to optimise.

4) templates, especially, make it very easy to change algorithms and functionality making for rapid development (not to say other methodologies don't, but see 1.) Generic design and implementation is pretty easy with out long drawn out object hierarchies (which of course have their place in larger projects).

Why did I start in c/c++?
I had only the briefest of formal computing education from somewhat uninterested teachers - c++ was easily accessible and the information about the internal mechanisms readily available, or pointed to, in the books I was using. VB and Java, other languages I was using at the time, didn't offer (me) the same level of detail. And so I stuck with it and I still learn new things every day. Well, nearly

Would I use other languages?
Yes, of course, but they have to balance point 1) with the others but it mostly depends on what is being written and who I am working with and even what I am told to use!
 
Old 02-27-2004, 07:19 PM   #11
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Original Poster
Rep: Reputation: 31
Quote:
Originally posted by coolman0stress
Performance is the only reason i would resort to C or C++ if i had a choice. I love these languages, but more on an 'interest' level. They are powerfull and i wish i had more time to explore them.

First. thanks for the well-thought-out, informed post Performance is pretty much the only reason to resort to one of those languages in almost all cases.

Quote:
One of the main advantages of knowing C or C++ is of course that when you move to something higher up you can actually deduce wtf is going on in those encapsulated methods and functions (big bonus in my opinion and i'm glad i went through the C route before doing more Java).
Agreed, it's never a bad thing to know C/C++ as they can help elucidate some of what is going on in higher-level languages. I also learned C/C++ as one of my first languages (if you don't count a few dialects of BASIC before my teens ).

Quote:
Anyway, i've also found from experience (looking at my friends, etc) that many people prefer C or C++ because they tend to have difficulty with OO design. It really takes some time to get used to how to properly design and work with OO. Some people find it easier to stick to more straighforward procedural structures. Just a general observation here so don't kill me. Personally i can't do anything without thinking of objects these days. After a year since i started OO, i'm finally able to use it 'correctly', and now i can't go back
OO is indeed nice and very powerful once you know how to use it, and it can be hard to grasp. But a lot of higher-level languages can be used in a procedural way and it would still be easier to do in that language than it would be in C or C++.

Quote:
Python or Ruby will most likely become my future love.
*cough*Python*cough* (really though, Ruby offers nothing over Python, more on that in another future thread if you want me to elaborate )

Quote:
I wish more people would have more experience to pick the right language for the right occasion.
That's kind of what this thread is about.
 
Old 02-27-2004, 07:21 PM   #12
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
I think dakensta brings up a good point:

There is a HUGE code base in C/C++.

I asked this question at my college: Why do you still teach Cobol? The answer is simple: a lot of places still have legacy code, and as long as it works, there is no need to 'update' it a new language. Cobol is at such a stage that if you get a job, you'll do more maintenance than actual coding of new applications...

Not a lot of people are interested in spending time converting their C/C++ libraries to something new....
 
Old 02-27-2004, 07:22 PM   #13
cjcuk
Member
 
Registered: Dec 2003
Distribution: Openwall, ~LFS
Posts: 128

Rep: Reputation: 15
Quote:
Originally posted by Strike
I would consider memory handling issues VERY important. I don't care if good programmers rarely make such mistakes, programming in languages where you don't have to worry about it means you will NEVER make mistakes about it. Yes I am aware of the overhead of a garbage collector, but for user-end apps such a performance hit is negligible. I'm not asking about things where performance is a top priority, I'm asking about the majority of desktop apps, where a 100ms overhead isn't going to be noticed or even cared about.
That is a fair enough comment. I am not saying that the memory handling issues ( the fact the programmer has to allocate and deallocate memory manually -- by default, you can always look at things like Boehm ) are not completely insignificant, I just think it is an issue with the programmer not the language. I would disagree that the performance hit is negligible, try running a shell server where everything uses interpreted, GC languages. I think that 100ms in 250ms being spent on language overhead ( estimated C vs Java ).

Quote:
Originally posted by Strike
Another issue? The fact that it takes lines upon lines of code to do in C/C++ what it takes a handful of lines to do in higher-level languages. This makes more places to make mistakes (like costly memory ones), and means more development time.
This really depends what you are doing. For example, simple file access in Java ( a supposedly improved language regarding this ) is a damn mess, and nobody can deny it. If you consider the amount of `base' classes or modules or whatever other languages have then I think it is only fair to consider C with commonly available third-party libraries ( ie, beyond libc ). At that point, the claim of lines of code can be challenged even better.

Quote:
Originally posted by Strike
Another issue? Learning to be a good C/C++ programmer takes more time than it does to become, say, a good Python programmer. So what you end up with is a lot of mediocre C/C++ programmers who never bother to learn enough to make themselves good programmers, simply because they can get their tasks done... only they don't get them done in the best way.
This is, again, a fair comment. I do agree, a lot of people never bother to push themselves. As a side note, I have no problem with other languages -- I just feel the need to defend C, as it is nowhere near as bad as people make it out to be. In general you should be looking at the language for the task -- for example, PERL for file manipulation, C/C++ for dealing with large amounts of data ( the memory overhead is significant ).

I would also like to note that I disagree with the Java comment made. I think many languages -- including C ( though, not compiled obviously ), think POSIX -- are more portable than Java. In my general experience with Java: it behaves differently on different platforms; it only works on platforms that have a JVM; programmers still make far too many platform-specific mistakes that Java cannot correct; ... ad infinitum ad nauseum.

One thing I will say though, is that C is probably not your best starter language. In many ways it can be, in that it gives you better insight into how systems work and it allows you to really get into the software that you run every day, but it is not. I truly think that a language such a Python ( a good example, Strike ) are brilliant first time languages. I would never put anybody through the pain of Java deliberately -- it is actually one of the worst learner languages I have seen ( implicit pointers, implicit threading, implicit ... -- it all just seems so underhanded ).
 
Old 02-27-2004, 07:27 PM   #14
Strike
Member
 
Registered: Jun 2001
Location: Houston, TX, USA
Distribution: Debian
Posts: 569

Original Poster
Rep: Reputation: 31
Quote:
Originally posted by dakensta
1) It's what I know best - to get to a vaguely comparable level in another language would take time and effort I don't really have to spare ... something to do in the future maybe?
Can't argue with this at all. This is one of the very few reasons I find acceptable for using it But really though, you should look at higher-level languages if you aren't doing very low-level stuff ... the development time you save will more than make up for the time it takes you to learn that language. Python is my favorite (if that's not obvious yet).

Quote:
2) LOADS of relevant (to me) libraries are written in c/c++ which, especially on *nix, are trivial to install and use and are readily available. Sooo many people use c/c++.
Again, hard to argue with, especially when that library isn't available in many/any other languages. But you have to consider the fact that writing libs for some of the higher level languages really isn't that hard Also, many of the more popular higher-level languages have numerous great ones already. But when you get into obscure/specific libraries, you may find yourself in a pickle fast.

Quote:
3) I know that, even if I don't spend a lot of time on design, I will get more than adequate performance and if need be, I have a good idea where and how to optimise.
I'm not so sure about this. It's hard to provide numbers on this, though you do make an interesting point. I have a feeling that this depends largely (no pun intended) on the size of the project. A larger project has more places where bad design in a lower-level language can nip it. Of course, we all profile and optimize and then profile and optimize ... etc., right?

Quote:
4) templates, especially, make it very easy to change algorithms and functionality making for rapid development (not to say other methodologies don't, but see 1.) Generic design and implementation is pretty easy with out long drawn out object hierarchies (which of course have their place in larger projects).
Ah, templates. If you like templates, I bet you'd positively love polymorphic types, especially in a language with type inference (if it is strongly-typed). Weakly-typed languages don't really need things like templates, because the implementation of a container datatype can (and often should) be agnostic of what it is containing.

Quote:

Would I use other languages?
Yes, of course, but they have to balance point 1) with the others but it mostly depends on what is being written and who I am working with and even what I am told to use!
Yeah, of course the big trump card is: "The specs of the program require it" So there aren't any ways around that, but I was kind of aiming this question at the hobby projects of coders here.
 
Old 02-27-2004, 07:30 PM   #15
coolman0stress
Member
 
Registered: Jun 2003
Location: Toronto, Ontario, Canada
Posts: 288

Rep: Reputation: 30
Quote:
But a lot of higher-level languages can be used in a procedural way and it would still be easier to do in that language than it would be in C or C++.
Yes, i wish more people realized that. But as programmers we are all very busy and it's sometimes hard to learn something new. You get stuck into one mind set and it takes a lot of power at times to change.

Mysel i've tried to explore as many languages as possible, but sometimes you just don't have a lot of time... So you have to pick something to specialize in. I'm just glad i have a week of now so i can play around. Even then i have a shit load of retarded assignments to do

Quote:
*cough*Python*cough* (really though, Ruby offers nothing over Python, more on that in another future thread if you want me to elaborate )
Yeah, i assumed that that would be your answer :P. Do elaborate of course.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
DISCUSSION: How To Do Eveything With DD AwesomeMachine LinuxAnswers Discussion 23 03-09-2017 06:50 AM
Discussion LinuxRam General 5 08-24-2004 06:58 AM
A Discussion On Certification LinuxRam Linux - Certification 2 07-31-2004 11:49 PM
webmail discussion illtbagu Linux - Software 2 11-11-2003 11:03 PM
Serious Discussion nbjayme Linux - Newbie 2 09-24-2003 10:49 AM

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

All times are GMT -5. The time now is 12:57 AM.

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