Sign in to follow this  
Serapth

C First?

Recommended Posts

Serapth    6671
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. ;) )

Share this post


Link to post
Share on other sites
Serapth    6671
My personal thoughts on the subject.

Learning C first is bad, very bad. At this stage in the game, C and C++ are completely different languages and should be treated as such. I can personally see very little to no real advantage of learning C first, except perhaps as a erudite pursuit. That there are C underpinnings to C++ that are there for legacy reasons only, not learning C first removes the user from exposure to this "cruft". I don't really think that knowing 100% of a language, especially deprecated aspects, makes you a better C++ programmer.


I would consider myself a pretty piss poor C++ programmer, but I do have 15+ years exposure to the language, while only 2 of those in professional use.

Share this post


Link to post
Share on other sites
Antheus    2409
[quote]Do you recommend a new developer learn C before C++?[/quote]
Depends.

[quote]What skill level would you consider yourself in C++ today?[/quote]
Yes.

[quote]Why?[/quote]
Yes.

Share this post


Link to post
Share on other sites
kunos    2254
i think for a complete noob.. C can offer an easier way in, it's a smaller simpler language. At the very beginning of programming I think the guy is already confused by the very idea of variable, control flow and function calling.. no need to get more confused with OOP stuff. For the very first steps a language such as standard basic or pascal migh also do.
Having said that, the danger is to fall into the trap of things like "ah ok, I get C++ now, you use cout instead of printf and class instead of struct".. which is exactly what I did when I was trying to transition to C++ with a background in old basic and C. It's funny that I really understood C++ when I started to study Java.. there you are forced to go OOP or die.

I don't have an answer.. programming is hard and to get good at it you need to WANT IT .. languages perhaps don't really matter.. commitment does. any serious programmer should and will end up knowing at least 3-4 languages from average to good.

Share this post


Link to post
Share on other sites
Washu    7829
[quote name='ApochPiQ' timestamp='1328646483' post='4910624']
One should learn the language most suited to the task they wish to accomplish.

95% of the time, that means neither C nor C++.
[/quote]
Indeed. 95% of the time you should learn...
HASKELL

On a more serious note:
C and C++ share some history. That's about it right now. There has been some standing movement in the C and C++ world to bring the two languages closer together, however that's all it really is...

From a learning perspective starting out with C vs C++ does not give you any particular advantage. Both languages have the same pitfalls in the same areas, although C++ also has other areas with other pitfalls that you must avoid. The thing is, from a learning perspective you're not likely to hit those "more advanced" pitfalls until you actually GET to those C++ features.

If you're hellbent on learning C++, learn C++. Don't learn C. [url="http://www.youtube.com/watch?v=VUslGSoEH8I"]Someone else actually put that better..[/url]

Share this post


Link to post
Share on other sites
Serapth    6671
[quote name='Antheus' timestamp='1328645082' post='4910613']
[quote]Do you recommend a new developer learn C before C++?[/quote]
Depends.

[quote]What skill level would you consider yourself in C++ today?[/quote]
Yes.

[quote]Why?[/quote]
Yes.
[/quote]

Very informative, but I have to disagree with you on that last part there.

Share this post


Link to post
Share on other sites
mhagain    13430
There's really no advantage to learning C first. If you don't want to go head-first into OOP, a much better option is to restrict yourself to the C-like subset of C++. You'll get a much nicer language to use with more modern thought behind it and you'll also have all the C++ extras to play with for times when they may come in useful.

Share this post


Link to post
Share on other sites
[quote name='Serapth' timestamp='1328643554' post='4910607']
Do you recommend a new developer learn C before C++?[/quote]
Definitely not. It'd hamper your ability to understand C++, not enhance it.

[quote]What skill level would you consider yourself in C++ today?[/quote]
Decent. Not an expert, but not a novice either.

[quote]Why don't you recommend C++ first?[/quote]
Because C++ is not C. It is a different language that is backward compatible with C. That was 15 years ago.
Now it's even more different. Still backwards compatible, but very different.
The fundamental difference is not new features, or different keywords, but different ways to think. If you start with C, you'll learn to think in a different way from that which C++ is trying to teach you.

But you're in luck! C++ just changed again. The new C++11 standard version of the language makes (or is in the process of making) C++ more modern, cleaner, faster, and easier to learn then ever. In may be difficult, since C++ is in transition from the "old" C++ to the "new" C++, and there's a lack of resources, but soon good tutorials and books will be coming out that teach the refined and enhanced C++ for beginners.

That said, it may be better to start with a language like [url="http://python.org/"]Python[/url]. But if your choice is between C and C++, it's not even a choice that needs to be seriously considered... Go C++.

My suggestion would be: Learn Python and stick with it for several years, and after that learn C++. Learning Python _will_ help you learn C++, while also giving you skills in Python that are valuable in themselves. Learning C will help some, and hinder some, and the skills wont really be valuable in their own right, unless you are working in some very specific circumstances.
What I mean is, if you know C++ and Python, you'll find circumstances to use both even when you know both. If you know C++ and C, you'll only find circumstances to use C++ except in very rare scenarios.

Share this post


Link to post
Share on other sites
Hiwas    5807
[quote name='Serapth' timestamp='1328643554' post='4910607']
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. ;) )
[/quote]

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.

Share this post


Link to post
Share on other sites
Tachikoma    575
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.

Share this post


Link to post
Share on other sites
Cornstalks    7030
[quote name='AllEightUp' timestamp='1328669158' post='4910744']
First off, learn "C" in the context of "C++".
[/quote]
But... [i]why???[/i]

[quote name='AllEightUp' timestamp='1328669158' post='4910744']
The second reason I suggest the above is the primary item I have to explain to new programmers multiple times.
[/quote]
Yeah, because you can't use pointers in C++... or maybe it's because pointers are different in C++...

[quote name='AllEightUp' timestamp='1328669158' post='4910744']
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.
[/quote]
But... [i]why???[/i]

[quote name='Tachikoma' timestamp='1328669881' post='4910746']
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.
[/quote]
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).

[quote name='Tachikoma' timestamp='1328669881' post='4910746']
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.
[/quote]
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.

Share this post


Link to post
Share on other sites
daviangel    604
[quote name='Tachikoma' timestamp='1328669881' post='4910746']
Objective-C is one such example.
[/quote]
Yeah the hell with it let's just have everyone just start out with Objective-C [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]
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 [img]http://public.gamedev.net//public/style_emoticons/default/laugh.png[/img]

Share this post


Link to post
Share on other sites
Tachikoma    575
I think threads like these perfectly illustrates how differently people approach languages.

[quote name='Cornstalks' timestamp='1328671639' post='4910754']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.[/quote]
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.

Share this post


Link to post
Share on other sites
Hiwas    5807
[quote name='Cornstalks' timestamp='1328671639' post='4910754']
[quote name='AllEightUp' timestamp='1328669158' post='4910744']
First off, learn "C" in the context of "C++".
[/quote]
But... [i]why???[/i]
[/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.

Share this post


Link to post
Share on other sites
cignox1    735
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...

Share this post


Link to post
Share on other sites
Serapth    6671
[quote name='AllEightUp' timestamp='1328706617' post='4910880']
[quote name='Cornstalks' timestamp='1328671639' post='4910754']
[quote name='AllEightUp' timestamp='1328669158' post='4910744']
First off, learn "C" in the context of "C++".
[/quote]
But... [i]why???[/i]
[/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.

Share this post


Link to post
Share on other sites
japro    887
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++).

Share this post


Link to post
Share on other sites
CadetUmfer    234
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++.

Share this post


Link to post
Share on other sites
Cornstalks    7030
[quote name='Tachikoma' timestamp='1328678773' post='4910785']
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.
[/quote]
And yet, you didn't have to learn [url="http://en.wikipedia.org/wiki/B_(programming_language)"]B[/url] in order to learn C. But yes, syntactically understanding one language will usually help in parsing and reading another language, and I have no doubt that your knowledge of C helped you when learning C++.

[quote name='AllEightUp' timestamp='1328706617' post='4910880']
[quote name='Cornstalks' timestamp='1328671639' post='4910754']
[quote name='AllEightUp' timestamp='1328669158' post='4910744']
First off, learn "C" in the context of "C++".
[/quote]
But... [i]why???[/i]
[/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".
[/quote]
I know what the question is, but I don't get what you mean by "learn the core language." What "core language?" C++ [b][i]is[/i][/b] the core language of C++. Not C.

[quote name='AllEightUp' timestamp='1328706617' post='4910880']
[u]Do so in the context of C++ so you are not learning the wrong things since[/u], as you say, the languages *are* different to a certain degree.
[/quote]
(emphasis mine) No, no, no. Learning C in the context of C++ would be learning all sorts of the wrong things. Nothing (well, okay, there are some things) drives me crazier than seeing someone pretend like C++ is C. Idiomatic C and idiomatic C++ are so massively different it's hard to even say where to start. It's harder to break a bad habit than it is to just make sure you start with the right habit.

[quote name='AllEightUp' timestamp='1328706617' post='4910880']
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]
Certainly, and it should be learned, but it can be learned in C++ just as easily as in C, since it's exactly the same in the two languages.

[quote name='Serapth' timestamp='1328710412' post='4910896']
[quote name='AllEightUp' timestamp='1328706617' post='4910880']
[quote name='Cornstalks' timestamp='1328671639' post='4910754']
[quote name='AllEightUp' timestamp='1328669158' post='4910744']
First off, learn "C" in the context of "C++".
[/quote]
But... [i]why???[/i]
[/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.
[/quote]
Pretty much, though I think a better example might be suggesting learning Latin before learning French (seeing as Latin influenced French, kinda like C influenced C++). But they're completely different languages, and if your goal is to learn French, you're better off just learning French. Whether or not you want to learn Latin someday is entirely up to you, but being fluent in French does not require one to start with Latin first.

[quote name='typedef struct' timestamp='1328715058' post='4910921']
C++ is not the best language for learning pointers and fiddling with bits - C is better for that.
[/quote]
I'm sorry, but I fail to see why C is better than C++ in this case. I see them as exactly the same, seeing as there is no difference between pointers or bits in C and C++.

[quote name='typedef struct' timestamp='1328715058' post='4910921']
C++ is not the best language for learning object-oriented programming- C#/Java is better for that.
[/quote]
I'll agree with that.

[quote name='typedef struct' timestamp='1328715058' post='4910921']
C++ is the best language for learning C++.
[/quote]
This is most true.

Share this post


Link to post
Share on other sites
Slavik81    360
[quote name='Cornstalks' timestamp='1328716395' post='4910928']
[quote name='AllEightUp' timestamp='1328706617' post='4910880']
[quote name='Cornstalks' timestamp='1328671639' post='4910754']
[quote name='AllEightUp' timestamp='1328669158' post='4910744']
First off, learn "C" in the context of "C++".
[/quote]
But... [i]why???[/i]
[/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".
[/quote]
I know what the question is, but I don't get what you mean by "learn the core language." What "core language?" C++ [b][i]is[/i][/b] the core language of C++. Not C.
[/quote]
Learn
[code]int arr[] = { 1, 2, 3 };
int product = 1;
for(int i=0; i<3; i++)
{
product = product * arr[i];
}
std::cout << product;[/code]

Before:
[code]std::vector<int> vec;
vec.push_back(1);
vec.push_back(2);
vec.push_back(3);
int product = 1;
for(std::vector<int>::iterator it = vec.begin(); it != vec.end(); ++it)
{
product = product * (*it);
}
std::cout << sum;[/code]

The C-style syntax is easier to pick up than STL C++ with its templates, namespaces and iterators. I'd make an exception for iostreams, since they're much simpler than format specifiers.

There's no reason to immediately push them into using <algorithms> or anything like that, even if it is more 'idiomatic' C++. They're better off ignoring most of the STL until they have a grasp of the basic concepts of the language. Take things one step at a time.

Share this post


Link to post
Share on other sites
Serapth    6671
[quote name='Slavik81' timestamp='1328728951' post='4911002']
The C-style syntax is easier to pick up than STL C++ with its templates, namespaces and iterators. I'd make an exception for iostreams, since they're much simpler than format specifiers.
[/quote]


Funny, I would exactly reverse what you said ( in my humble opinion ). I find the C++/STL way much more clear than the "C" version, while I find C style IO ( as in printf/scanf ) much more intuitive than streams. Then again, I think operator overloading is the work of the devil, so I never really took to streams.


EDIT: I just want to make it clear, I am not endorsing the use of printf/scanf, both are horrifically fragile and dangerous methods and being sent to the dustbin of history is a good thing. I am simply stating they are a hell of a lot easier to grok than streams.

Share this post


Link to post
Share on other sites
alvaro    21246
Of course a true C++ programmer would do it like this:
[code]#include <iostream>
#include <vector>
#include <boost/iterator/counting_iterator.hpp>
#include <algorithm>
#include <numeric>

int main() {
std::vector<int> vec(boost::make_counting_iterator(1), boost::make_counting_iterator(4));
int product = std::accumulate(vec.begin(), vec.end(), 1, std::multiplies<int>());
std::cout << product << '\n';
}
[/code]

</facetious>

I also recommend learning either C first, or the "C++ core language", if that's what you want to call it. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]

EDIT: Oh, and the code above should give you an idea of my level of C++: I've used the language for 10 years now, but there are some areas that I don't [and don't want to] really know, like how to implement boost::counting_iterator from scratch.

Share this post


Link to post
Share on other sites
Washu    7829
[quote name='alvaro' timestamp='1328730311' post='4911014']
Of course a true C++ programmer would do it like this:
[code]#include <iostream>
#include <vector>
#include <boost/iterator/counting_iterator.hpp>
#include <algorithm>
#include <numeric>

int main() {
std::vector<int> vec(boost::make_counting_iterator(1), boost::make_counting_iterator(4));
int product = std::accumulate(vec.begin(), vec.end(), 1, std::multiplies<int>());
std::cout << product << '\n';
}
[/code]

</facetious>

I also recommend learning either C first, or the "C++ core language", if that's what you want to call it. [img]http://public.gamedev.net//public/style_emoticons/default/smile.png[/img]
[/quote]

[CODE]
#include <iostream>
#include <vector>
#include <algorithm>
int main() {
std::vector<int> vec = {1, 2, 3};
int product = 1;
std::for_each(vec.begin(), vec.end(), [&product](int val) { product *= val; });
std::cout<<product<<std::endl;
}
[/CODE]

Edit: Removed numeric include since it's not needed.

Share this post


Link to post
Share on other sites
Guest
This topic is now closed to further replies.
Sign in to follow this