C First?

Started by
48 comments, last by All8Up 12 years, 2 months ago

I have noticed as a rather recurring trend that quite a few people seem to recommend learning C before learning C++.

When I was starting out, the option was basically taken from me ( C++ was fairly new and compilers were scarce ), so I never had to make this decision. I have my own opinion on the subject now, but I don't want to taint the thread with it. So I was hoping to do a quick survey.


Questions:

Do you recommend a new developer learn C before C++?
What skill level would you consider yourself in C++ today?
Why? ( either way EDIT: Why as in do you recommend for/against C++ first, now why do you consider yourself a certain skill level. ;) )


I will go against many folks and say that I agree with learning C first but with a couple differences. First off, learn "C" in the context of "C++". I.e. use cpp/cxx files so the compiler assumes C++ and use the syntactic sugar which C++ allows such as creation of variables as needed instead of all defined at the head of the function. There is no effective difference in the generated code and in this specific example, C++ can actually be more efficient since it won't expand the stack until needed and may keep core variables in cache longer due to the "expand only as used" behavior. (Not all compilers respect this as it can be a detriment, depends on the function and the compiler's belief of which is better. Key item here, trust your compiler until it proves to be wrong....)

The second reason I suggest the above is the primary item I have to explain to new programmers multiple times. "Pointers" and how they work. Pointers are so simple yet the language makes them complicated for various reasons. How can uint8_t* ++ =1, uint16**++=2 etc and how struct/class*++ doesn't match anything you might expect. How can temp[ 80 ] be used the same way as generic pointer math or temp[ 80][ 80] etc. Pointer math is rather arcane and the only thing I really care folks learn before digging into other areas is that they have a VERY solid pointer math understanding as it is critical to a lot of higher level usage of the language.

Finally, solid understanding of the language. I don't think ANYONE should code OO, virtuals, templates, etc until they REALLY understand the general base language of 80ish keywords.

As to the alternative ways to learn programming in general, sure fine whatever. Learn Python, Java, whatever, but to make the jump to C++, is a very large change and as the Spidey paraphrase goes: "With power comes responsibility". It is your responsibility to learn the basics before jumping into the fancy stuff because you can so easily screw things up.
Advertisement
Depends what platform you want to break into.

Personally I say learning C first is very useful. It exposes you to some fundamental programming concepts and gives you an insight how machines work one level up from assembly. Also, many laguages "borrow" the C syntax in various forms, and some laguages is even a superset of the C standard. Objective-C is one such example.
Latest project: Sideways Racing on the iPad

First off, learn "C" in the context of "C++".

But... why???


The second reason I suggest the above is the primary item I have to explain to new programmers multiple times.

Yeah, because you can't use pointers in C++... or maybe it's because pointers are different in C++...


Finally, solid understanding of the language. I don't think ANYONE should code OO, virtuals, templates, etc until they REALLY understand the general base language of 80ish keywords.

But... why???


Personally I say learning C first is very useful. It exposes you to some fundamental programming concepts and gives you an insight how machines work one level up from assembly.

Learning C can be useful, yes, but that doesn't mean it should be learned before C++ (nor does it mean C++ should be learned before C).


Also, many laguages "borrow" the C syntax in various forms, and some laguages is even a superset of the C standard. Objective-C is one such example.

Learning C just for the syntax is unnecessary. The syntax is such a small part of programming.


@OP: If there's a language you want to learn, learn it. C is a totally different language from C++. If you want to learn C++, learn C++. If you want to learn C, learn C. If you want to learn Haskell, learn Haskell. etc.
[size=2][ I was ninja'd 71 times before I stopped counting a long time ago ] [ f.k.a. MikeTacular ] [ My Blog ] [ SWFer: Gaplessly looped MP3s in your Flash games ]

Objective-C is one such example.

Yeah the hell with it let's just have everyone just start out with Objective-C biggrin.png
then they'll have no clue if they are learning C or C++ or some bastard hybrid like most people that start out learning C code continue to write even when they finally switch to C++ since they never really get the C++ thing laugh.png
[size="2"]Don't talk about writing games, don't write design docs, don't spend your time on web boards. Sit in your house write 20 games when you complete them you will either want to do it the rest of your life or not * Andre Lamothe
I think threads like these perfectly illustrates how differently people approach languages.

Learning C can be useful, yes, but that doesn't mean it should be learned before C++ (nor does it mean C++ should be learned before C).

[...]

Learning C just for the syntax is unnecessary. The syntax is such a small part of programming.

In all honestly, I can only speak for myself here. The learning approach I mentioned earlier was very useful, particularly syntax part. When you have never written a line of code before, syntax is everything, and learning it is one of the first fundamental steps for understanding what you are looking at. And when you switch over to some other language with a familiar syntax, learning that will be also a hell of a lot easier. I probably would have struggled with C++ if it weren't for C.
Latest project: Sideways Racing on the iPad

[quote name='AllEightUp' timestamp='1328669158' post='4910744']
First off, learn "C" in the context of "C++".

But... why???
[/quote]
The question is "learn C before C++?", take the baby steps into C++ but learn the core language "FIRST". All the rest of your arguments get the same answer: "because you need to learn the basics first". Do so in the context of C++ so you are not learning the wrong things since, as you say, the languages *are* different to a certain degree. The whole pointer thing was just a very common basic missed knowledge that continually comes up, so I suggest learning that specifically if nothing else.
Learning C before C++ only means that once you move to C++ you need to forget all the things no longer needed. Why should you learn to use c strings when you can start with std::string? Or why should you ignore references? Or to use malloc/free instead than new/delete?

A better option would be to learn 'C++ without classes', but still, a lot of languages (Java and C# to start with) are highly OO so you can as well learn C++ the OO way...

I don't see reason why you would want to learn C if you target C++. And I don't see reason to learn Pascal if you want to program with Delphi, for that matter...

[quote name='Cornstalks' timestamp='1328671639' post='4910754']
[quote name='AllEightUp' timestamp='1328669158' post='4910744']
First off, learn "C" in the context of "C++".

But... why???
[/quote]
The question is "learn C before C++?", take the baby steps into C++ but learn the core language "FIRST". All the rest of your arguments get the same answer: "because you need to learn the basics first". Do so in the context of C++ so you are not learning the wrong things since, as you say, the languages *are* different to a certain degree. The whole pointer thing was just a very common basic missed knowledge that continually comes up, so I suggest learning that specifically if nothing else.
[/quote]


Isn't it kinda like suggesting people learn French before learning English? They share a number of words and use the same alphabet, but are completely different languages. Sure, knowing one will make learning the other a bit easier, but it seems like a downright wasteful use of time.
I absolutely see no benefit in starting with "pure C" over "C++ without the fancy features". For a beginner the big challenge is learning to program, not learning to program in <language>.
To me it seems like you are intentionally wasting your time on learning stuff someone else arbitrarily considers "basics" just so you can throw them out the window later (it's not like you can get around learning what pointers are in C++).
C++ is not the best language for learning pointers and fiddling with bits - C is better for that.
C++ is not the best language for learning object-oriented programming- C#/Java is better for that.
C++ is the best language for learning C++.
Anthony Umfer

This topic is closed to new replies.

Advertisement