Jump to content

  • Log In with Google      Sign In   
  • Create Account


C++ As First Language


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
72 replies to this topic

#21 Serapth   Crossbones+   -  Reputation: 5327

Like
1Likes
Like

Posted 11 July 2012 - 10:03 AM

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.


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:
C++ Primer Plus 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.

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.

Sponsor:

#22 rnlf   Members   -  Reputation: 1117

Like
1Likes
Like

Posted 11 July 2012 - 10:04 AM

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, 11 July 2012 - 10:06 AM.

my blog (German)


#23 Serapth   Crossbones+   -  Reputation: 5327

Like
1Likes
Like

Posted 11 July 2012 - 10:15 AM

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 Programming: Principles and Practice Using C++. 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.


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, 11 July 2012 - 10:33 AM.


#24 boogyman19946   Members   -  Reputation: 1051

Like
0Likes
Like

Posted 11 July 2012 - 10:32 AM

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 Posted Image 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, 11 July 2012 - 10:34 AM.

"If highly skilled generalists are rare, though, then highly skilled innovators are priceless." - ApochPiQ

My personal links :)
- Khan Academy - For all your math needs
- Java API Documentation - For all your Java info needs :D
- C++ Standard Library Reference - For some of your C++ needs ^.^

#25 shadowstep00   Members   -  Reputation: 501

Like
0Likes
Like

Posted 11 July 2012 - 10:42 AM

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 Posted Image! 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 Posted Image

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, 11 July 2012 - 10:48 AM.

Failure is not an option...


#26 Serapth   Crossbones+   -  Reputation: 5327

Like
1Likes
Like

Posted 11 July 2012 - 10:47 AM

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 Posted Image 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 Posted Image Oh man, there are so many fun problems to solve dealing with invalid memory ^.^ !



For the record, what you are looking for is forward declarations.

It doesn't invalidate your example in the least, again the preprocessor is a big part of what sucks about C++ for new developers, I just felt I should give you the proper solution to your problem. :)

#27 Serapth   Crossbones+   -  Reputation: 5327

Like
0Likes
Like

Posted 11 July 2012 - 10:52 AM

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 Posted Image! 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 Posted Image

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 like this or like that.


Anders Hejlsberg's ( the father of C# ) book C# Programming Language is probably as good a place to start as anywhere. If you like analytical, its a good book. Additionally its annotated by other developers with discussions about WHY this was done, or why that was done, and in some cases, the annotations are quite critical. It makes the book a bit less dry.

I can understand not liking the Head First series, that is why I recommended people preview it before purchasing. Personally it's not my bag, but then, I am very technically minded, so I dont really like a lot of anecdotes in my texts. I also find the page layout chaotic and loud.


One last piece of advice, and something new ( and experienced ) developers fall for all the time ( and goes completely contrary to everything I have said in this thread).

Don't let people push you around. If you really want to learn C++, learn C++. If you really want to use SFML instead of SDL, use SFML. Of course, disregarding other peoples opinions and learning experiences is a stupid thing to do, but remember... opinions are like a______s, everybodies got one. At the end of the day, experience is the best teacher, and you can't really make an unfixable mistakes at this point. The most important thing really is to pick something and stick with it. Someone with an opinion contrary to mine will come along and try to sway you to go a different way. Ultimately you will get nowhere if you spend a week learning one language, then switch to a different one, then a different one, then a different one. Learning lots of languages is a good thing of course, just not initially. In the programming world there is always a shiny distraction just over the hill, or a compelling reason to switch technologies... most of the time, it is a bad idea. Most of the time. It is hard, really hard, to keep focused in this profession, but you will have to if you want to get anywhere!

That said, choosing a language other than C++ was a good call. Posted Image

Edited by Serapth, 11 July 2012 - 10:59 AM.


#28 boogyman19946   Members   -  Reputation: 1051

Like
0Likes
Like

Posted 11 July 2012 - 10:54 AM

EDIT3:

Vector Matrix::getRowVector(int row);


Vector Matrix::getColVector(int col);



Matrix Vector::getRowMatrix(); // returns a row vector


Matrix Vector::getColMatrix(); // returns a column vector




Alright, so I've done an actual test to see if those functions above would cause a problem in my classes, and they do not, so then Serapth was, of course, right. I made a mistake thinking the return value had to be a reference or a pointer. But I digress now.

Edited by boogyman19946, 11 July 2012 - 07:52 PM.

"If highly skilled generalists are rare, though, then highly skilled innovators are priceless." - ApochPiQ

My personal links :)
- Khan Academy - For all your math needs
- Java API Documentation - For all your Java info needs :D
- C++ Standard Library Reference - For some of your C++ needs ^.^

#29 rnlf   Members   -  Reputation: 1117

Like
0Likes
Like

Posted 11 July 2012 - 11:01 AM

You're welcome.

I recommend you take a look at Python before settling with C#. It has a very easy syntax, a comparably large standard library and supports lots of different paradigms (you don't need to know what that means right know, but it will allow you to learn different approaches to the whole problem solving part, once you are ready for it). It has the added benefit of being used as an integrated scripting language in some major products, so you get scripting in those for free. Blender is a nice example for this, as it features a full fledged game engine.

It has one feature, which is at the same time a blessing and a curse (depending on whom you ask): It uses dynamic typing. This means, you have an easier time writing down your programs because you don't have to type in the right type for every object, but at the same time, this may lead to confusion in very large programs. And it will require you to learn the idea of static typing once you decide to learn one of the C style languages. But for you first programs, it won't matter that much and later, you will have learned how to deal with it.

I can't actually make a valid statement about which language is easier to learn for a beginner, because I learned both languages after several years of C and C++. But considering the facts that C# felt quite familiar to me as a C++ programmer and I still felt more comfortable with Python after a shorter time, I personally prefer it.

I would strongly discourage you from using Java for mostly the same reasons Serpth points out in the "Java cons" part of his article. Java is really annoying.

my blog (German)


#30 Serapth   Crossbones+   -  Reputation: 5327

Like
0Likes
Like

Posted 11 July 2012 - 11:14 AM

Hi ShadowStep.

C++ isn't so bad as a first language, but I would suggest that you concentrate on pure C first. It's much more simple to learn and understand. It's also a good starting point to learning C++. Think of C++ as an extension to C, that adds object-oriented programming (why do I have a feeling that some people are going to try to stab me with a rusty fork for this sentence? Posted Image ).


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

A big +1 on that one Simon. And the things I wrote above have a bit of a flaw: you're risking in creating those "bestardized" mixes when learining C first and then C++. C is a lot better for understanding basic language syntax (functions, conditional instructions, loop instructions, basic code layout, etc.). C++ adds more to that.

PS. Hello GameDev Community. Posted Image


First off, Hi! Welcome to the gamedev community.

I also wanted to take a moment to explain why ( I think... I didn't personally downvote you ) you are taking a shelacking reputation wise. It isn't an attack on you personally, it's just your advice is outdated, and by modern standards, wrong.

The C subsystems within C++ exist for legacy ( and mostly political ones at that ) reasons alone, and certainly should not be the focus for a beginner. In general, they should be avoided by people starting out with C++ today.

I just wanted to clarify why you were getting downvoted, so you didn't take it personally and get put off by the Gamedev community.

Again welcome, and don't worry, we are a generally agreeable sort in these parts.

#31 shadowstep00   Members   -  Reputation: 501

Like
0Likes
Like

Posted 11 July 2012 - 11:28 AM

Serapth, actually taking a glance at the book

C# Programming Language I think the book is more of a reference than an actual tutorial book for novice begginers like me. Also it does not have any exercices seeing it from the preview contents...

Failure is not an option...


#32 Matt-D   Crossbones+   -  Reputation: 1450

Like
4Likes
Like

Posted 11 July 2012 - 11:38 AM

Other than that what should i watch out? Where i might be tricked?


As for the C++11 style -- read this:
http://herbsutter.co...modern-c-style/ // "Elements of Modern C++ Style" by Herb Sutter
http://msdn.microsof...y/hh279654.aspx // Welcome Back to C++ (Modern C++)

And watch this:
http://channel9.msdn...D2011/TOOL-835T // Writing modern C++ code: how C++ has evolved over the years

Should be good for starters :-)

// If you need more, this is pretty good (but not free $$$): http://www.artima.co..._of_the_new_cpp // Presentation Materials: Overview of the New C++ (C++11) by Scott Meyers

*The* C++11 book I can *strongly* recommend is coming out soon:
http://www.informit....isbn=0321714113 // "C++ Primer, 5th Edition" by Stanley B. Lippman, Josée LaJoie, Barbara E. Moo
Incidentally, Barbara E. Moo happens to be one of the "Accelerated C++" co-authors -- nuff said :-)

// EDIT: Serapth, perhaps you might be interested in taking a look, this one introduces smart pointers immediately, in the very same section it introduces dynamic memory -- as it should be :-)

Edited by Matt-D, 11 July 2012 - 12:17 PM.


#33 DZee   Members   -  Reputation: 194

Like
2Likes
Like

Posted 11 July 2012 - 08:20 PM

I honestly don't think C++ is that hard. It's just very broad and flexible so it's easy to overlook certain features. Or if I rephrase you can do so much with it that it can be a little confusing for someone who's new to understand why the language is so detailed and let's you do certain things until you understand more advanced concepts.

Personally if I had to learn a first language I would choose Java because it's syntax is similar to C++ and it's easier ; pretty much every problem is documented on the web making it easy to move on. It also renders the same results no matter your OS.

Then again, my two friends learned C as their first language and they rock. It's all about how much effort you are willing to put into learning. They are both in electrical engineering though and rather strong in arithmetic's.

Edited by DZee, 11 July 2012 - 08:22 PM.

I "surf" the web, literally.


#34 Acotoz   Members   -  Reputation: 73

Like
-2Likes
Like

Posted 11 July 2012 - 08:26 PM

C++ is the founding father of the world. Learn it.

Good luck

#35 Serapth   Crossbones+   -  Reputation: 5327

Like
0Likes
Like

Posted 11 July 2012 - 09:15 PM

It's all about how much effort you are willing to put into learning.


Only if you are doing it wrong. It *should* be all about minimizing the amount of effort you need to put into it.

#36 Detectiverr   Members   -  Reputation: 112

Like
0Likes
Like

Posted 11 July 2012 - 10:23 PM

It depends. I got no programming experiences but I started out C++ as my first language because I want to program games. :D So far, it took me.....2 or 3 weeks to understand the first chapter. XD LOL

#37 DevLiquidKnight   Members   -  Reputation: 834

Like
0Likes
Like

Posted 11 July 2012 - 11:29 PM

Ok guys i have been hearing a lot about how bad C++ is as a first language

C++ is by no means a bad language to start with, sometimes transitioning from one language to another is harder.

Is really C++ that hard for a begginer?

No, C++ is fairly easy if you take your time to learn it, just like any other language.

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....

It is by no means impossible to learn C++ as your first language, its a great language. It is extremely versatile and quite frankly can do a lot of things most other languages cannot. If you eventually master C++ you will find learning other languages to be significantly easier.

I personally found this book to be pretty good when I checked it over: C++ Without Fear: A Beginner's Guide That Makes You Feel Smart

Edited by DevLiquidKnight, 11 July 2012 - 11:30 PM.


#38 rnlf   Members   -  Reputation: 1117

Like
-1Likes
Like

Posted 12 July 2012 - 12:52 AM

C++ is not easy. You can, however learn it as your first language. But you will most likely pick up some very bad practices along the way.

The book you recommend, DevLiquidKnight, seems to be another example of a bad C++ book. It teaches the wrong topics at the wrong time (considering the table of contents and index), it refuses to teach very important topics in an adequate depth (two pages for smart pointers), heck, it doesn't even mention any STL containers beyond std::list. This seems to be a terrible book. And even this terrible book's title implies that C++ is hard. If you worked through this book and you believe you know C++, you're wrong.

Edited by rnlf, 12 July 2012 - 12:52 AM.

my blog (German)


#39 shadowstep00   Members   -  Reputation: 501

Like
2Likes
Like

Posted 12 July 2012 - 01:39 AM

Thank you for trying to help me Posted Image , but Guys now i start getting a little comfused here, cause many say stick with C++, others start with C# or Java or Python.


From what i see in Amazon, Python has some really well made introductary books like this one http://www.amazon.co...howViewpoints=1 (very positive reviews) and this http://www.amazon.co...howViewpoints=1 (great reviews too)

While in C# i still havent found a good introductory book. (dont like Head First neither C# programming language cause its not really a tutoral than more of a reference)

In C++ I am a little comfused, first because some peoeple say it is not such a bad first language when others disagree (Well we have discussed this theme already and you dont have to start giving arguments why its better or not cause I have already seen the two sides of the opinion)What I would like you to do to help me is to tell me if there is really a good book to start with this language cause all we have mentioned so far are not good (by your opinions neither C++ Primer Plus nor C++ Without Fear).

In Java i found this http://www.amazon.co...9&keywords=java and http://www.amazon.co...8&keywords=java if you have any other good books to recomend me better that these two tell me to check them out.


So what I really want from you is to tell me which language you prefer most and a good introductory book with it. I will check all the books reviews and see what is better for me. Thanks Again!

P.S. I forgot something important.. if i am about to learn a diffrent launguage from C++ I want to learn it and be ready to move on C++, not learn a second launguage again and then go to C++.

Edited by shadowstep00, 12 July 2012 - 02:09 AM.

Failure is not an option...


#40 SimonForsman   Crossbones+   -  Reputation: 6059

Like
1Likes
Like

Posted 12 July 2012 - 02:26 AM

P.S. I forgot something important.. if i am about to learn a diffrent launguage from C++ I want to learn iT and be ready to move on C++ not make another launguage again first and then go to C++.


You probably shouldn't think that way, you will most likely never "move on" to a new language, languages are just tools so rather than moving between languages in some sort of progression from bad but easy to hard but good you just keep adding new languages to your toolbox, almost every language out there is good for something. (And while most programmers have a favorite language a good programmer will choose language based on the task at hand)

For me the languages that i currently(as in, on a near daily basis) have a real use for are: C#, Java, C++, Python, PHP, JavaScript and Lua, Of those PHP and JavaScript are primarily for the Web and Lua primarily as a scripting language (and thus generally not used exclusively on a single project).

Learning C# or Python first is very unlikely to be a waste of time as those are languages that can be used for a very wide variety of things and you are very unlikely to abandon either of them completely even if you become a C++ expert.
I don't suffer from insanity, I'm enjoying every minute of it.
The voices in my head may not be real, but they have some good ideas!




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS