LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 09-22-2010, 09:12 AM   #1
portia
Member
 
Registered: Oct 2009
Distribution: Slackware
Posts: 112

Rep: Reputation: 20
c over c++


I'm relatively young and equally ignorant as to C or C++ (or any other language for that matter). I've started learning C, but come across a view that C is getting old/obsolete, etc. and If someone just starts out they should start with C++.

I know that most of the linux kernel is written in C and so are a lot of linux tools. Are there any other areas where C still prevails?
The reason I'm asking is that I'm now not sure which one to learn. I know that you'll answer: depends what you want to do. The problem is that I don't really know what one can do with C, as opposed to C++.
 
Old 09-22-2010, 09:16 AM   #2
jangovich
LQ Newbie
 
Registered: Sep 2010
Location: Mississauga, Ontario
Distribution: Ubuntu 10.04
Posts: 21

Rep: Reputation: 5
You'll probably end up learning both, including many other languages along the way It's not like you will get defined as a programmer by the language you learn - good programmers program /into/ a language, as opposed to programming /in/ a language, in other words, the limitations of the language itself should in no way constrain your creative thought/imagination.

It does depend on what you want to do - you wouldn't try to hammer a nail with a screwdriver. C is a good (a bit complex in certain areas) to get introduced to programming and it's time well spent.
 
Old 09-22-2010, 09:26 AM   #3
portia
Member
 
Registered: Oct 2009
Distribution: Slackware
Posts: 112

Original Poster
Rep: Reputation: 20
Thanks. I see your point about knowing a few languages.
Quote:
It does depend on what you want to do - you wouldn't try to hammer a nail with a screwdriver. C is a good (a bit complex in certain areas) to get introduced to programming and it's time well spent.
Where is C mainly used and where C++?
 
Old 09-22-2010, 09:36 AM   #4
jangovich
LQ Newbie
 
Registered: Sep 2010
Location: Mississauga, Ontario
Distribution: Ubuntu 10.04
Posts: 21

Rep: Reputation: 5
Quote:
Originally Posted by portia View Post
Thanks. I see your point about knowing a few languages.


Where is C mainly used and where C++?
Kernel development, drivers, embedded systems, low-level hardware interactions. There are many, many discussions on the internet and advocates for both languages exist. However, as I said, there is no reason why you can't learn features of C++ later on.

Also, personally, I find that when learning a first language OOP stuff is not really helping, but adds more complexity when you try to learn basic language features.
 
Old 09-22-2010, 09:40 AM   #5
portia
Member
 
Registered: Oct 2009
Distribution: Slackware
Posts: 112

Original Poster
Rep: Reputation: 20
Thx, you've cleared my doubts. I think I'll continue learning C.
 
Old 09-22-2010, 10:08 AM   #6
JohnGraham
Member
 
Registered: Oct 2009
Posts: 467

Rep: Reputation: 139Reputation: 139
Quote:
Originally Posted by portia View Post
Thx, you've cleared my doubts. I think I'll continue learning C.
A wise decision, if you ask me. C++ is a horrible language for beginners (too big and messy, in my opinion) but if you learn C first you're half-way there if you want to learn it later.
 
Old 09-22-2010, 10:39 AM   #7
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by portia View Post
Thx, you've cleared my doubts. I think I'll continue learning C.
I also suggest to observe once a year the sad day on which it was decided that C++ would no more be a preprocessor for "C".
 
Old 09-22-2010, 01:31 PM   #8
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
This thread sure has gotten the anti C++ opinions.

I don't know how one might get a representative sampling of professional programmers, but I suspect if you could you would find the opposite bias to what is shown earlier in this thread.

C++ is a much better language than C.

The right subset of C++ would be a much better beginner language than C. (Though there is the serious problem that C++ tutorials don't do a good job of selecting the right subset of C++).

Most beginners in C get confused because the simple operations beginners tend to program end up needing a good understanding of pointers in general in order to use char pointers correctly. A good C or C++ programmer must gain a good understanding of pointers. But in C++ you can safely learn that later. You can advance smoothly from not using pointers, through using them in easily understandable situations, up to using them more generally. In C, you must understand char pointers before you are ready to really understand pointers.

Most beginners in C get confused by scanf. Once you are a good C programmer, you will have far less use for scanf. For serious projects, scanf is usually just almost good enough to do its job. Working around scanf to do the job really correctly ends up being harder than doing that whole thing some other way. So the time a C beginner spends learning scanf (unlike learning pointers) is mostly wasted. But as a C beginner, you usually have no alternative to scanf.
 
Old 09-22-2010, 01:40 PM   #9
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by johnsfine View Post
... A good C or C++ programmer must gain a good understanding of pointers. But in C++ you can safely learn that later.
...
I don't think so. I.e. I think that the notion of pointers should be introduced quite early, problems/dangers related to pointers should be explained, and good known methods how to minimize/eliminate the problems/dangers in C++ should be explained.

Pointer are a key element of hierarchical data structure, and serious programming is impossible without them.
 
Old 09-22-2010, 01:49 PM   #10
johnsfine
LQ Guru
 
Registered: Dec 2007
Distribution: Centos
Posts: 5,286

Rep: Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197Reputation: 1197
Quote:
Originally Posted by Sergei Steshenko View Post
I don't think so. I.e. I think that the notion of pointers should be introduced quite early, problems/dangers related to pointers should be explained, and good known methods how to minimize/eliminate the problems/dangers in C++ should be explained.

Pointer are a key element of hierarchical data structure, and serious programming is impossible without them.
Depends on what the meaning of "later" is.

Pointers are a key element of serious programming. Pointers are a big part of the reason C and C++ are better than most programming languages. Pointers should be introduced earlier and should be understood thoroughly.

Despite all that, beginners in C get confused over char pointers because they typically use char pointers before they are ready to understand pointers.

I learned asm before C, so I never experienced any confusion over pointers. I never understood why it should be confusing even for those who didn't learn asm before C. I don't think I would have been confused and I know some beginning C programmers aren't.

But even not understanding why pointers should be confusing, I still have observed that most beginning C programmers are confused by pointers. Getting a little of the basics of C programming behind them before tackling pointers would make it much less confusing. But that means working just with numbers, not text, for the first several projects. That would present other problems for starting to learn C.

In C, the same kind of pointer might point to an item of a specific type of data, or it might point to an array of items of that data type. In a typed languages (as C mostly is) an item and an array of such items are two different types deserving two different pointer types. It would be nice if a beginner first learned and understood pointers that point to an item of a specific type, then learned the additional complication that it might point to an array of items of that type. But the typical beginner use of char pointers jumps into the deep end on that as well as other confusing aspects of pointers. All that must be learned, but better in a more logical sequence.

Last edited by johnsfine; 09-22-2010 at 01:57 PM.
 
Old 09-22-2010, 03:38 PM   #11
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by johnsfine View Post
...
Despite all that, beginners in C get confused over char pointers because they typically use char pointers before they are ready to understand pointers.
...
Pointers can be easily explained using as examples arrays storing indexes to other arrays.
 
Old 09-23-2010, 05:35 AM   #12
portia
Member
 
Registered: Oct 2009
Distribution: Slackware
Posts: 112

Original Poster
Rep: Reputation: 20
Quote:
Originally Posted by Sergei Steshenko View Post
Pointers can be easily explained using as examples arrays storing indexes to other arrays.
Can you elaborate on that or provide a link, please?
 
Old 09-23-2010, 07:53 AM   #13
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723Reputation: 723
I also think C++ is ugly and messy, but sadly there is no alternative.
 
Old 09-23-2010, 10:23 AM   #14
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by portia View Post
Can you elaborate on that or provide a link, please?

????

Code:
unsigned array_of_unsigned_indexes[...];
...
some_type array_to_use_the_indexes_above[...];
...

// indirection, i.e. moral equivalent of using pointers:
some_index = ...;
...
some_type foo = array_to_use_the_indexes_above[array_of_unsigned_indexes[some_index]];

// actually, there are two levels of indirection:
// 1) array_of_unsigned_indexes[some_index];
// 2) array_to_use_the_indexes_above[array_of_unsigned_indexes[some_index]];
Computer RAM is an array of bytes from the point of view of C99, and true pointer is just an index to that array.
 
Old 09-23-2010, 10:27 AM   #15
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Maybe later I'll cook up something related to trees using C99 arrays - am busy at the moment. The point to show some more practical example.
 
  


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



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

All times are GMT -5. The time now is 01: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