PDA

View Full Version : Is learning C/C++ worth it?



C/C++ Learner
11-03-2008, 01:47 PM
Hey everyone, I've always wanted to start learning C++ and I love programming.

A few weeks ago I downloaded some tutorials and in a few hours I could write some nice basic programs with loops etc.
I'm planning on reading some C++ books this vacation and learning C++ from the ground up. I've got previous experience with programming in form of Java.

So, I was wondering is there any drawback to learning C++ and not knowing C?
I know C++ is the superset of C but still, why would I learn C when I could learn C++?

Akkernight
11-03-2008, 01:56 PM
No need learning C first ;) Or so a tutorial told me...

Daved
11-03-2008, 02:00 PM
C and C++ are different languages with different approaches, different uses, and different tools.

If you want to learn C++ well, you'll be learning a lot of things that you wouldn't do or would do differently in C. So learning C is a completely separate task from learning C++.

It is beneficial to learn many different languages, but I wouldn't necessarily suggest doing several at a time. There's not really any good reason why you should learn C with or before C++, and some people would even say that learning C first is a detriment because it teaches you habits that you would want to avoid in C++. So I'd say stick with C++ now by itself. In the future, you can broaden and deepen your understanding by learning C, assembly and lower level languages as well as other high level languages.

If you do want to learn modern C++, I'd be careful about which book(s) you use. Most books still teach C-style C++, so to get the most out of learning the language you'd probably want to go with those that teach the more modern style.

sean
11-03-2008, 02:57 PM
I know C++ is the superset of C

It's being picky, but basically the answers above are correction your error in this statement.

C++, as the name suggests, was developed as an incremental change to C - but they really have become 2 separate language, even if they are very similar, and even if for the most part, this statement is pretty much true)


Most books still teach C-style C++

True. My first book taught C++ in 2 parts. The first one was called "The Basics" or something similar and the second was called, "Object Oriented Programming in C++". Looking back now - Part 1 was pure C. Part 2 was just C with classes (incidentally - the original name of C++).

C_ntua
11-03-2008, 03:36 PM
Depends on what you need the language for.
Java is closer to C++ than to C. So, you would broaden more, in a way, your knowledge if you learned C.
If you know Java and learn C you can easily learn C++ to add more on your knowing languages.

Dae
11-03-2008, 04:01 PM
It's definitely worth learning both.

I know others disagree, but I now recommend C over C++. Yes, there are drawbacks, which Daved mentioned. I feel like if you have a good head on your shoulders and actually enjoy programming, then you can be self-aware of those problems and avoid those habits. If you're somebody who is learning for work, or money, and doesn't care, then it's different.

The reasons are as follows:

1) As a beginner you are going to be prone to procedural programming. It's the way a beginners brain is wired. Even if you start out in C++ or Java, you will still treat code the way you would without OOP, but instead wrapped inside members and methods ("bad OOP"). Look at any beginner who starts their own game in C or C++. It's always extremely bad.

2) Most of the libraries you will use in C++ are written in C (for compatibility mostly), and you will have abstracted low level procedural non-OOP code no matter what. Choosing C++ over C isn't going to save you from this.

3) C is a lot easier than C++. They are both easy to learn, and hard to master, but C++ is a level or two higher. I'm not talking about classes, not even multiple inheritance, but you're immediately into operator overloading, generics (templates), scopes, static classes, patterns (singleton, observer, etc.), macro templates, polymorphism, STL data structures (without knowing how they work behind the scenes), and those are the basic topics.

4) There's obviously less keywords, features, and learning required in C. C is mostly about the libraries. You can learn C and basic libraries considerably quickly in comparison to C++.

5) In a way, C makes you think more about what how the underlying system works. You don't just add something without knowing how it works. I'm mostly referring to strings, memory, io, classes, etc. Each of those have pre-requisites you learn in C.

abachler
11-03-2008, 05:15 PM
There is nothign 'beginner' about procedural programming. While it does tend to be easier to grasp for beginners, it also provides the best performance if done correctly. I've been programming for nearly 30 years, and still mostly code using procedural style. Obviously there are times when its not appropriate, such as writing tools and libraries, but just because a hammer can't do the job of a screw driver, doesnt mean a hammer is a beginners tool, because a screw driver cant do a hammers job either. Each programmign style has its own strengths and limitations. A good programmer uses them all when they are most appropriate and doesnt get into the rut of using one style preferentially.

Daved
11-03-2008, 05:23 PM
Referring to something as a beginner's tool does not imply that it cannot also be a tool for advanced users.

@nthony
11-03-2008, 06:53 PM
As noted, C++ is C, so good knowledge of C++ entails knowledge of C.

It also depends on your long-term goals and interests. If you're more focused on design principles (i.e. Soft-Eng) and are content to leave the hardware as abstracted, then C++ is the way to go. If you'd like an in-depth understanding of computation from architecture to design then starting with C would be preferential.

My personal recommendation would be C->C++->Java/C#. Why? Because you need a solid foundation in order to really grasp what's going on behind the scenes in any super-high-level language (as in Java/C#). Priority one is memory management: the kind that you just won't get from using new/delete or automatic allocation; you've got to sweat it out with malloc to fully appreciate what's going on.

A bit of a warning though: compared to the hand-holding of Java, C (or even C++) is going to get a bit hairy some times. In a nutshell, C is about not shooting yourself in the foot while holding a greased-up .22 caliber magnum.

master5001
11-03-2008, 07:08 PM
Nope

How do you like them apples?

BobMcGee123
11-03-2008, 07:17 PM
Programming is way too hard.

abachler
11-03-2008, 07:41 PM
I dont think that Java>C# is necessarily a logical progression from C>C++. If Java and C# are what you will end up using, there is really little if any need to learn C or C++ for THAT purpose, although they will certainly give you more perspective on OOP in general, its not a bare necessity.

master5001
11-03-2008, 07:48 PM
C# is more like the Java transitioning into $.

zacs7
11-03-2008, 07:48 PM
> My personal recommendation would be C->C++->Java/C#.
My recommendation is similar, C -> Java -> C++ :)

A lot of the concepts in Java are the same in C++, but far easier in Java and thus you'll be able to apply/expand on that when you learn C++.

My theory of course, so feel free NOT to bash me ;)

master5001
11-03-2008, 07:58 PM
>> My theory of course, so feel free NOT to bash it

But... but... I want to throw in pedantic arguments. You did already thwart my efforts by being polite, however.

zacs7
11-03-2008, 08:02 PM
I want to hear them :). You can bash my theory, just not me *cough* Elysia :p

whiteflags
11-03-2008, 09:16 PM
My theory is that C++ is worth it to learn it because I am studying it right now. Anything I study is important. :D

abachler
11-04-2008, 02:22 AM
Just try the following if you want to know how necessary C++ is

Write a hardware driver in JAVA
Write an OS in C#

zacs7
11-04-2008, 04:46 AM
> Write a hardware driver in JAVA
I'd do that in C, C++ is not necessary ;). You could also write the driver in C/Java via the JNI (ugly, and really... who would?).

> Write an OS in C#
I'd also do that in C :)

I fail to see how your example show the necessity for C++ specifically. It should be noted that Java does not need to run on a VM. So point 1 is highly possible, and point 2 is possible in non-standard obscure Java. Check out GCJ http://gcc.gnu.org/java/

C/C++ Learner
11-04-2008, 06:56 AM
Thanks everyone for your comments! It is deeply appreciated.
I have decided to learn C++ first as soon as the vacation hits, which was my original plan, but I'm hoping that it will make me at least 60% comfortable with the C syntax/way of programming, if I decide to learn C after C++.

What is your opinion of the above?

Again, thanks everyone for the comments, so far.

Elysia
11-04-2008, 07:39 AM
C++ and C syntax is very similar. You are probably just going to struggle with the typical lack of tools that everyone in C++ takes for granted (std::vector, for example), that does not exist in the C standard library (that is not to say, though, that there are not any implementations out there).

Anyway, good luck.

C/C++ Learner
11-04-2008, 09:24 AM
You mean #include <vector>?
What is C used for primarily these days? Surely not everyday desktop applications?
Is it only used for drivers and/or operating systems?

I'm just guessing since it's a mid-level or lower level language.

Thanks for the good luck, anyway can't wait for the exams to finish.
My first book I'm going to read is "C++ How to Program" by Deitel and Deitel,
next I'll read some e-books?

Any books I should look out for?

sean
11-04-2008, 09:26 AM
Write an OS in C#

Singularity?

I'm actually really curious to learn more about that - I'm sure there must be plenty of cheating involved. At the very least using a different compiler.

sean
11-04-2008, 09:30 AM
You are probably just going to struggle with the typical lack of tools that everyone in C++ takes for granted (std::vector, for example), that does not exist in the C standard library (that is not to say, though, that there are not any implementations out there).

I had gotten so used to the C-way of doing things, that when I started working in a high-level language it actually caused me problems. I would find something that needed implementing, implement it the way my brain automatically thought was best, and then when I was almost done, I found there was some high-level data-structure I had almost never heard of that did exactly what was needed. So had I known the high-level one, I would've been faster, but now it actually slows me down to go and learn the high-level way.

On the reverse side of that - our project is starting to get unnecesarily slow, so perhaps some of my techniques would've been the better option.

Dae
11-04-2008, 10:33 AM
You mean #include <vector>?
What is C used for primarily these days? Surely not everyday desktop applications?
Is it only used for drivers and/or operating systems?

I'm just guessing since it's a mid-level or lower level language.

Thanks for the good luck, anyway can't wait for the exams to finish.
My first book I'm going to read is "C++ How to Program" by Deitel and Deitel,
next I'll read some e-books?

Any books I should look out for?

C is used for operating systems, drivers, DLLs, hardware, robots, stuff like that almost exclusively (engineering). As mentioned, C is still used for many libraries and programming languages (opengl, mysql, curl, perl, php). This includes Python, which is gaining popularity. I believe you can only use C for Python modules, not C++. It's used a lot in game hacking (with ASM), although usually wrapped in C++ classes to make it fancy. There's not a lot of cases where it'd be advantageous to use C over C++, but there's cases where your C++ is mostly just C. Games used to use C but started transitioning to C++ nearly 10 years ago (takes time to give up the libraries these companies have). C is still great for small scripts, much like perl. You'll see it used a lot for math computations.

Accelerated C++
C++ Primer

Read the stickies:
http://cboard.cprogramming.com/showthread.php?t=74078

maxorator
11-04-2008, 10:37 AM
Generally the C style means "implement it yourself" and C++ style means "use an external library". :p

It is good to know how to implement things yourself, since anyone seriously into programming will, at some point, need to actually create something. The fact that external libraries have often implemented ways to do what you need doesn't mean you never have to actually do something from scratch.

A C++ programmer who isn't familiar with the C style is clumsy, a c++ programmer who isn't familiar with the C++ style is impractical.

Daved
11-04-2008, 10:44 AM
>> I have decided to learn C++ first as soon as the vacation hits, which was my original plan, but I'm hoping that it will make me at least 60&#37; comfortable with the C syntax/way of programming, if I decide to learn C after C++. <<

This sounds like a good plan to me. You'll be comfortable with the syntax, but will likely have to learn a different way of programming if/when you switch to C (and that's a good thing).

Is the Deitel and Deitel book you've got the 6th edition? I'd highly recommend getting the latest edition if you can, otherwise you'll likely end up learning the C-style C++ that I recommended against.

C/C++ Learner
11-04-2008, 11:15 AM
Once again thanks everyone.

@Daved

No, my version is the third edition... Is that bad?
I can get the fifth edition, though?

@Dae

Thanks for the book suggestions.
I read somewhere that I should alternatively read The C++ Primer Plus to C++ Primer?

Daved
11-04-2008, 11:23 AM
I'm not familiar with the differences between the editions other than the fact that the 6th edition has added more information about modern C++. I would imagine the 5th edition would be better than the third.

If you can't get the 6th, it sounds like you'll learn C-style C++. I don't recommend it, but you'll be ok. Just understand that a lot of the techniques you learn aren't really recommended any more. You'll still get a sense of the language and improve your general programming skills.

If you can get Accelerated C++, I'd definitely recommend that over an old Deitel and Deitel edition.

Oh, and you should prefer C++ Primer (4th edition) over C++ Primer Plus (again because C++ Primer Plus teaches C-style C++).

Some books that teach C-style C++ are easier to follow and better at teaching, but I'd prefer to use a book that teaches the latest style adequately over one that teaches outdated stuff well.

Elysia
11-04-2008, 12:41 PM
I had gotten so used to the C-way of doing things, that when I started working in a high-level language it actually caused me problems. I would find something that needed implementing, implement it the way my brain automatically thought was best, and then when I was almost done, I found there was some high-level data-structure I had almost never heard of that did exactly what was needed. So had I known the high-level one, I would've been faster, but now it actually slows me down to go and learn the high-level way.

On the reverse side of that - our project is starting to get unnecesarily slow, so perhaps some of my techniques would've been the better option.

That is what I figured. If you are used to C++, you would get frustrated with the lack of tools and libraries.
If you were used to C, you would likely try to implement everything yourself using low-level code.
It takes a while to get used to the change!

maxorator
11-04-2008, 12:51 PM
That is what I figured. If you are used to C++, you would get frustrated with the lack of tools and libraries.
If you were used to C, you would likely try to implement everything yourself using low-level code.
It takes a while to get used to the change!
But the best way is if you're used to both! Then you use a library, if there is some that fits you, otherwise you implement one of your own (instead of getting frustrated). ;)

Elysia
11-04-2008, 12:57 PM
But the best way is if you're used to both! Then you use a library, if there is some that fits you, otherwise you implement one of your own (instead of getting frustrated). ;)
Aye, no arguments there. I am kindof like that myself. Like to implement my own stuff.

C/C++ Learner
11-04-2008, 01:13 PM
Hehe, anyway, I just checked out my copy of C++ How to Program 3rd Edition, the book I'm planning to read first. Anyway, it says that the first 5 chapters are the "C" part of C++, datatypes arrays etc, and at the end of every chapter there's a Talking in OOP part, used to get the reader familiar with OOP concepts.

@Daved
The rest of the chapters are more C++ or oop chapters and as described before, the first 5 chapters are procedural programming. What do you think?

Daved
11-04-2008, 01:35 PM
It's C-style C++. Not worthless, but not ideal. If you want to learn modern C++ you'll have to get another book. If getting another book will be difficult, then this one is fine. Just remember that you'll need to adjust your learning to account for the difference.

For example, if you stick with the 3rd edition then come on to the forum and ask a question about why this isn't working:
char word[] = "hello";
char input[10];
cin >> input;
if (input == word)you'll be told that you can't use == with C style strings and that you should be using C++ strings instead. I don't know if the third edition talks about C++ strings, but if it doesn't you'll have to go look them up outside of your book. The same thing will happen quite a few times. You'll still end up learning, just not quite as smoothly as you could.

Is vector mentioned in the index at all? If not, then you'll be having to do a lot of research outside the book, and you'll probably end up buying a second book anyway.

abachler
11-04-2008, 02:57 PM
I'm not 100% sure, but I dont think vector is actually part of the C++ standard, its part of the STL.

Daved
11-04-2008, 03:02 PM
It's part of the standard.

The STL is an informal name often used to refer to the containers and algorithms in the standard library. The name comes from the actual STL library from SGI (I think) that formed the basis for the completed standard library. However, when people refer to the STL now, they're almost always referring to the stuff inside the C++ standard.

C/C++ Learner
11-04-2008, 10:28 PM
Hmm, haven't seen vectors in my book, that's a negative.
Anyway, by pure chance I downloaded vector tutorials the day I learned basic C++.
I'm going to read the book, and after that I'll read some other books I can get my hands on, hopefully, I can get the C++ Primer,
although I'm having trouble finding Accelerated C++.

What do you think about this:

The C++ Standard Library: A Tutorial and Reference

Dae
11-05-2008, 12:55 AM
Hmm, haven't seen vectors in my book, that's a negative.
Anyway, by pure chance I downloaded vector tutorials the day I learned basic C++.
I'm going to read the book, and after that I'll read some other books I can get my hands on, hopefully, I can get the C++ Primer,
although I'm having trouble finding Accelerated C++.

What do you think about this:

The C++ Standard Library: A Tutorial and Reference

That's more of a reference, or an intermediate tutorial (like someone transitioning). Meaning it assumes you are comfortable with C++ and just teaches you STL. It's not that hard finding e-books (wink ;) wink ;) - buy them if you like them). I really liked Accelerated C++, but I haven't looked into C++ How to Program (latest edition might be better, I don't know).

C/C++ Learner
11-05-2008, 06:42 AM
Still, I'll take the chance and read the third edition thoroughly and then read e-books, I can get a lot of e-books.

abachler
11-05-2008, 11:06 AM
It's part of the standard.

The STL is an informal name often used to refer to the containers and algorithms in the standard library. The name comes from the actual STL library from SGI (I think) that formed the basis for the completed standard library. However, when people refer to the STL now, they're almost always referring to the stuff inside the C++ standard.

Nope, looking at a copy of the proposed standard (yeah im that old) now, vector isnt part of it.

laserlight
11-05-2008, 11:15 AM
Nope, looking at a copy of the proposed standard (yeah im that old) now, vector isnt part of it.
Maybe you're looking at too old a copy of the proposed standard.

Daved
11-05-2008, 11:27 AM
>> Nope, looking at a copy of the proposed standard (yeah im that old) now, vector isnt part of it.

Interesting. I'm looking at the actual standard, and vector is right there.


23.2.4 Class template vector

A vector is a kind of sequence that supports random access iterators. In addition, it supports (amortized)
constant time insert and erase operations at the end; insert and erase in the middle take linear time. Storage
management is handled automatically, though hints can be given to improve efficiency. The elements of a
vector are stored contiguously, meaning that if v is a vector<T, Allocator> where T is some type
other than bool, then it obeys the identity &v[n] == &v[0] + n for all 0 <= n < v.size().

...

CornedBee
11-05-2008, 01:09 PM
vector is in the actual standard, and also in the 1997 final public draft, which is available for free:
http://www.open-std.org/jtc1/sc22/open/n2356/

C/C++ Learner
11-05-2008, 01:50 PM
Hmmm, I'm planning on reading C++ Primer 4th after the book I mentioned.

abachler
11-05-2008, 03:55 PM
ah, the 'new' c++98 standard, my copy is an older version published in 1994.