Sign in to follow this  

C++ As First Language

This topic is 2009 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Ok guys i have been hearing a lot about how bad C++ is as a first language. Well before i had read this topic here:[url="http://www.gamefromscratch.com/post/2011/08/04/I-want-to-be-a-game-developer.aspx"]http://www.gamefromscratch.com/post/2011/08/04/I-want-to-be-a-game-developer.aspx[/url]

I had already started learning C++ with this book C++ Primer Plus and went ahead till the second chapter with no real problems. The book has learned me so far how to creat functions, some statements and explained about the prepocessor directives,directives and very little about classes and objects. Well i had no prior experience from any other programming language but still i think i got how things work till now.

So my final question is.. Is really C++ that hard for a begginer? is it impossible to learn C++ as first language? or it just requires some more dedication than other languages? or maybe i just havent got to the difficult things yet....


PS. After i read that article that i mentioned before i started learning C# but it really didint got my attention so much and also the books where not traditional like those of C++ which first learn you how to write "hello world" , variables ect... Most of C# books empasize fist on Visual Studio and dont get you to the basics of the language first. I would like to work on a book that first learns me how to write and then introduce me to Visual Studio.

Sorry for my English.

Share this post


Link to post
Share on other sites
Hi ShadowStep.

[quote name='SimonForsman' timestamp='1342003322' post='4957973']Many of the worst issues will be avoided if you write modern proper C++ rather than the bastardized mix between C and C++ that some online tutorials teach[/quote]
A big +1 on that one Simon. Besides C is a lot better for understanding basic language syntax (functions, conditional instructions, loop instructions, basic code layout, etc.). C++ adds a lot more to that. Edited by MoroS84

Share this post


Link to post
Share on other sites
Yes C++ as a first language usually isn't that great of an idea. There are some things in C++ that are just best learned through another language. I learned Python first and I don't regret it. C++ is still my favorite but only after I had a good hold on the other language. (Python, .net, Java)

Share this post


Link to post
Share on other sites
[quote name='shadowstep00' timestamp='1342002724' post='4957970']
Is really C++ that hard for a begginer?
[/quote]

'hard' isn't really the proper description. It's not hard to learn so much as it's hard to learn right. There's a lot of little gotchas that aren't obvious, and things that are correct yet less optimal than other things.

Worse yet, C++ requires a lot of overhead to make sure you're doing things right. That overhead would be better spent on learning to program. Since learning to program can be done with any language really, it's better for you to work with one that requires less overhead and has less gotchas.

[quote name='shadowstep00' timestamp='1342002724' post='4957970']
I would like to work on a book that first learns me how to write and then introduce me to Visual Studio.
[/quote]

This is (arguably) unwise. Visual Studio is what you see first, and it's important to make sure that you can compile and run your code before giving you too much code to write (since you should be writing code as you work through the book).

Share this post


Link to post
Share on other sites
If you are enjoying it, and not feeling disuaded or overwhelemed, then go for it. Programming is not an easy discipline no matter the language (for most people, anyway), even failures and false starts can be a learning experience - the only real danger is becomming discouraged and quitting. With C++, there is probably a higher "drop-out rate" due to added complexity and annoyances specific to that language.

Heck, I consider myself somewhat experienced, and these days I only use C++ when I have to (mostly this coincides with someone is paying me to) - it's not a particular easy and smooth experience for anybody, compared to many other languages (note that for many people, easy =/= enjoyable, however).

Share this post


Link to post
Share on other sites
First of all, I thank you for all your answers they really help me out.

I wanna tell you that this book that I am reading C++ Primer Plus [url="http://www.amazon.com/gp/product/0321776402/ref=s9_simh_gw_p14_d1_g14_i2?pf_rd_m=ATVPDKIKX0DER&pf_rd_s=center-2&pf_rd_r=173AYHY02ZQMBXKEGAX4&pf_rd_t=101&pf_rd_p=470938631&pf_rd_i=507846"]http://www.amazon.co...&pf_rd_i=507846[/url]
is updated to the[size=4] [color=#000000][font=verdana, arial, helvetica, sans-serif]C++11 standard[/font][/color] [/size]cause it was realeased 2011 and in the description says that includes [color=#000000][font=verdana, arial, helvetica, sans-serif][size=1][size=4]C++11 standard.[/size]

[size=4]Apart from that it also does not mix the C language with C++ but it does[/size][/size][/font][/color][left][background=rgb(250, 251, 252)] [/background][/left]mentions some things that you can skip(i skip them) for those who have come from C to make it easier for them.In addition i think that if i get each chapter right and do all the exercises correctly( and some similar more of my own) i should be on the right way.

I think from what you have mentioned here is that the most difficult thing about C++ is the freedom that it gives you in terms of how you can write a program in too many different ways.

Other than that what should i watch out? Where i might be tricked? So to be Extra alarmed in that chase.... Edited by shadowstep00

Share this post


Link to post
Share on other sites
A good indicator of a bad way to teach C++ could be if you stumble across pure pointers or the keyword "new" in code example quite early (like earlier than halfway into the book). This *could* mean the book might still use some old fashioned (and thus error-prone and dangerous) ways to achieve certain things.
Even pure arrays might be an indicator of such a problem.

I don't know this book, but I don't think a C++ book can easily be adopted to cover C++11, because a lot of the basic workings of the language have been improved substantially, thus rendering section relying on the older standard obsolete.

Maybe somebody knows this book and can give a more facts based assessment of it.

Share this post


Link to post
Share on other sites
[quote name='shadowstep00' timestamp='1342010495' post='4958002']
Other than that what should i watch out? Where i might be tricked?
[/quote]

Scott Meyer's collection of C++ books are a good collection of these. Unfortunately, they only cover a fraction of all the things you might run into and won't help for the things you can't avoid.

[url="http://www.amazon.com/Scott-Meyers/e/B004BBEYYW"]http://www.amazon.com/Scott-Meyers/e/B004BBEYYW[/url]

Share this post


Link to post
Share on other sites
[quote name='rnlf' timestamp='1342011983' post='4958008']
I think, Effective C++ & Co. are more useful to people who already know C++. Otherwise you will have no clue what he's talking about.
[/quote]

That's true.

Share this post


Link to post
Share on other sites
[quote name='kunos' timestamp='1342004691' post='4957984']
To recap, I'd suggest you to take a step back, and consider C# and especially Go as your introduction to programming.
[/quote]
Wait, what?
You recommend he doesn't start with C++, but C# is OK? I'd NEVER recommend C# to anyone, unless they want to do what's best for Microsoft, and not for themselves.

Share this post


Link to post
Share on other sites
[quote name='boblehest' timestamp='1342016487' post='4958033']
[quote name='kunos' timestamp='1342004691' post='4957984']
To recap, I'd suggest you to take a step back, and consider C# and especially Go as your introduction to programming.
[/quote]
Wait, what?
You recommend he doesn't start with C++, but C# is OK? I'd NEVER recommend C# to anyone, unless they want to do what's best for Microsoft, and not for themselves.
[/quote]

If this was 2006, I *might* ( probably still wouldn't ) give this argument an ounce of credence.


The existance ( and success ) of Mono, as well as the fact C# is an ECMA standard pretty much render your argument moot.

Now you could make that claim in regards to certain .NET libraries like WinForms and WPF which aren't part of the standard, but again, this is pretty silly. It would be like shunning Qt because it is controlled by a single entity.

Share this post


Link to post
Share on other sites
also it's fun to notice that the whole Mono / Xamarin group seem to be way more interested in promoting C# than MS itself is at this stage.

Share this post


Link to post
Share on other sites
[quote name='kunos' timestamp='1342018050' post='4958042']
also it's fun to notice that the whole Mono / Xamarin group seem to be way more interested in promoting C# than MS itself is at this stage.
[/quote]


Yeah, this is certainly true. I have noticed a definite shift at Microsoft since Steven Sinofsky took control. Silverlight is dead, XNA is dead, DirectX is "just another library", .NET has been defocused and WinForms end of lifed ( although the writing was on this wall for a long time ), while WinRT has received focus. C# seems to be getting less emphasis, while JavaScript and C++ are getting much more, especially in Metro. They even tried to axe the Express line ( except for targeting Metro ), until there was a community backlash.

Can't say as I particularly like the change of direction, but thats just me.

Fortunately C# is mature and feature complete enough Mono can take it and champion the cause. Unlike C++ and to a lesser degree Java, there arent as many things that need fixing in C#. In some ways the current additions ( like dynamic ) feel unfocused and inappropriate, so leaving the langauge alone might not be a bad thing.

Share this post


Link to post
Share on other sites
I find it interesting how people seem to overstate how difficult it is to learn programming from C++. I teach high school students programming using Stroustrup's [url="http://www.stroustrup.com/Programming/"]Programming: Principles and Practice Using C++[/url]. This is a text book for an introductory course on computer programming.

The students have found the book to be readable, engaging, and useful. There are practical exercise in learning to solve real problems in programming. The language choice is naturally C++.

I find C++ to be fine as an introductory programming language.

Share this post


Link to post
Share on other sites
[quote name='rnlf' timestamp='1342011123' post='4958004']
A good indicator of a bad way to teach C++ could be if you stumble across pure pointers or the keyword "new" in code example quite early (like earlier than halfway into the book). This *could* mean the book might still use some old fashioned (and thus error-prone and dangerous) ways to achieve certain things.
Even pure arrays might be an indicator of such a problem.

I don't know this book, but I don't think a C++ book can easily be adopted to cover C++11, because a lot of the basic workings of the language have been improved substantially, thus rendering section relying on the older standard obsolete.

Maybe somebody knows this book and can give a more facts based assessment of it.
[/quote]

I just quickly skimmed through C++ Primer Plus 6th edition ( love my Safari membership ), I have to say your guess is exactly right.

DO NOT use this book to learn modern C++. At all, period.

First off, it starts off by saying:
[i]C++ Primer Plus[url=""][/url] approaches C++ by teaching both its C basis and its new components, so it assumes that you have no prior knowledge of C. You’ll start by learning the features C++ shares with C. Even if you know C, you may find this part of the book a good review. Also it points out concepts that will become important later, and it indicates where C++ differs from C.[/i]

This is troubling, and arguably the wrong way to teach C++, especially in the C++11 world. If you come from a C background, sure, but teaching a user an obsolete language construct is worrying.

Even worse, guess when the first mention of smart pointers is... Chapter 12. How many chapters in this book? 12.

Basically they've bolted on the C++ 11 features as an additional chapter, instead of making them intrinsic to the book.

It's not a horrible book, but certainly not an ideal one.

Share this post


Link to post
Share on other sites
Bill Door: I guess, if a beginner has an experienced instructor, she may well start with C++. But most people start learning programming on their own. If they have to do homework on which the instructor comments, even better. The instructor may guide them in the right direction. But people learning on their own get little to no feedback. This way, the jump on the first train that *seems* to work but nobody shows them the problems that may arise. Years later their programming technique stabs their backs. Edited by rnlf

Share this post


Link to post
Share on other sites
[quote name='Bill Door' timestamp='1342022311' post='4958077']
I find it interesting how people seem to overstate how difficult it is to learn programming from C++. I teach high school students programming using Stroustrup's [url="http://www.stroustrup.com/Programming/"]Programming: Principles and Practice Using C++[/url]. This is a text book for an introductory course on computer programming.

The students have found the book to be readable, engaging, and useful. There are practical exercise in learning to solve real problems in programming. The language choice is naturally C++.

I find C++ to be fine as an introductory programming language.
[/quote]

This goes completely contrary to my University experience. This was about the point the drop out rate went through the roof.

Granted, my prof may have sucked and it was 95, so the langauge has certainly changed since. I went into the course with a decade of programming experience, so i was not typical. But the students new to programming certainly struggled. Also, we moved beyond non-trivial examples, which is the point that C++ clubs you over the head with a mallet. Edited by Serapth

Share this post


Link to post
Share on other sites
I figure it must be quite hard to show people how the overall structure of C++ is a mess when discussing programming concepts instead of the language itself.

Perhaps it would be ok if I share an example which I stumbled upon just a few minutes ago. If I was programming in Java, my code would compile on the first try without an error or would at least have a very high chance of doing so. In C++, apparently I forgot a "couple" of things.

For one thing, we have the whole inclusion garbage. I was creating a Vector class and a Matrix class in order to do some rotations, but I didn't feel like making separate functions to facilitate multiplication between a vector and a matrix, so instead I added functions into the Vector and Matrix class that would turn them into a Matrix or a Vector respectively. This of course requires me to #include "Matrix.h" in Vector.h and #include "Vector.h" in Matrix.h so that I may work with those objects. Anyone who has experience with this already knows what horrendous things are going to start to happen. If we compile Matrix.h first, it's going to execute the #include statement, and try to compile Vector.h, but before that finishes, it encounters #include "Matrix.h" which goes back to Matrix.h. Now, the inclusion guards do their job, so the preprocessor skips over the contents and class Matrix is not declared for class Vector, so when Vector encounters Matrix types, it's going to complain they weren't defined, and class Vector is not going to get defined, and when we finally return to Matrix.h, class Vector has not been defined so Matrix can't use it, and alas, nothing gets defined properly and the code doesn't compile.

Unfortunately I can't use pointers (well I could but the resulting code would be horrendous), because that would suggest I'd have to allocate memory inside the function and remember to deallocate it later outside. I can't use references because the local variables will go out of scope and I don't want to modify the object I'm converting. I have no choice then, I have to move the functions in a utility header and define them there so I can use both Matrix.h and Vector.h without complications.

Of course I could put it into a constructor where the class itself will take care of the memory, but that will only work for turning a vector into a matrix. I still have to hack about to get a single row or column of a matrix into a vector.

So there is your simple C++ deal. In Java, you write import Matrix; and import Vector; in their respective files, and magic happens [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img] No need to "set your code up right."

If you've got a whole lot of experience dealing with this kind of stuff or you're really good at solving cryptic problems, you'll know where to progress. If you're a beginner and you get your shirt caught here, goodbye! And preprocessor troubles aren't the only "gotcha's" there are :D Oh man, there are so many fun problems to solve dealing with invalid memory ^.^ ! Edited by boogyman19946

Share this post


Link to post
Share on other sites
Thank you Serapth and rnlf for taking tha time to answer to my thead. Serapth with all that you said above it seems that C++ is not a very smart choice for begginer language.

I will have to choose between Java and C#. Maybe I should give C# one more chance [img]http://public.gamedev.net//public/style_emoticons/default/biggrin.png[/img]! I dont think that Head First C#, is my type of book got any others to recommend me? something more "traditional"

Boogyman even though I am a begginer I think I got your point there [img]http://public.gamedev.net//public/style_emoticons/default/laugh.png[/img]

Again thank you all for you answers!

PS. The thing that I liked about C++ Primer Plus was that it just explained everything and it was very analytical, where you had no questions to make why is this thing like this or like that. Edited by shadowstep00

Share this post


Link to post
Share on other sites
Sign in to follow this