C++ As First Language

Started by
71 comments, last by Fredericvo 11 years, 10 months ago

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


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.

http://www.amazon.com/Scott-Meyers/e/B004BBEYYW
Advertisement
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.

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.


That's true.

To recap, I'd suggest you to take a step back, and consider C# and especially Go as your introduction to programming.

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

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

Stefano Casillo
TWITTER: [twitter]KunosStefano[/twitter]
AssettoCorsa - netKar PRO - Kunos Simulazioni

As the author of the article, I suppose I should chime in. First, and some of this might be lost due to language barriers, but a lot of the criticism leveled at C++ in the article is pretty firmly tongue in check. It is certainly hyperbolic. Although with that said, C++ is still a crappy language to start with. I say that with absolutely no caveats. There is not a single metric by which I would call C++ a good beginners language.


So my final question is.. Is really C++ that hard for a begginer?


Hard is a relative expression, and pretty meaningless on it's own. Is C++ harder to learn than almost every other modern programming language? Yes.

is it impossible to learn C++ as first language?
[/quote]
No.

or it just requires some more dedication than other languages? or maybe i just havent got to the difficult things yet....
[/quote]
Dedication is the wrong word. Patience? Yes. A willingness to smash your head against a wall repeatedly, yes. I would imagine you havent gotten to the difficult things yet. They aren't insurmountable, they are just a really inefficient use of your time.


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.
[/quote]

Bad books exist for all languages. I do believe every C# book I recommended in that guide don't even mention Visual Studio.


Now for a bit of justification.

First off, there is this thing that most new developers don't and can't understand, because you learn it from experience.

The first programming language you learn is going to be by an order of magnitude the hardest programming language you learn. This is because in addition to learning the language and it's associated tools, you are also learning to program. Your goal at this stage should be to minimize complexity as much as possible. It's a pretty well established technique in teaching... you don't bombard a student with a thousand topics at once, you streamline as much as possible and learn in a more linear progression. C++ makes this exceedingly difficult, as the number of topics you need to cover in a short span of time is quite a bit larger than most other languages. For the record, this applies to C# and Java too... an absolute beginner is probably best served starting with a language with an even simpler build process.

Second, it's all about the design of C++. C++ has a design ethos of "everything is optional". C++ won't force anything on you, and for a new developer this is a very bad thing. When just starting out, as little choice as possible is actually a good thing.

C++ is 4 languages in one, and 3 of them suck. When you set out to learn C++, you are actually learning a number of languages at once. Basically there is C, C++ of yonder, templates and C++11. Before you argue this point, all 4 of those aspects are actually turing complete, and frankly, the 4 languages don't mesh extremely well. The legacy C core is because in 1983 C was the language of the day. It's inclusion was a big reason why C++ caught on, but as a language of today, its effectively 27 years old, and a kinda crappy one at that, especially in regard to security. As was said earlier, if you pick up a book and it deals with C'isms in the first half, return it. 99.999% of the time, there should be no C in your C++ code.

Now the templating aspect of the language is pure garbage for a beginner. They are difficult, have an unweildy syntax ( compare for each in C++ to , well, any other language as an example ) and even in 2012, the errors they generate are absolute garbage.

As to the two flavors of C++, C++ pre-11 and C++ post 11, well all languages suffer from this to a degree, so this ins't an exclusively C++ related issue. C# suffers it in the form of non templated collections, as well as the lack of features before a certain level ( generics are the biggest though ), while Java suffers from the fact it's initial class libraries are a mess, and the fact it hasn't aged as well as C#. C++ however is the oldest, and thus, most prone to cruft. On the brightside, the C++ mindset of "do it yourself" and "everything is optional" makes the core fo the language quite small, to a degree minimizing the cruft that has developed ( well except the entire C subsystem that is ). As was mentioned earlier though, in modern C++ you shouldn't be using new or naked arrays on a regular basis. Reading 99% of the tutorials on the web though and this sure as hell wouldn't be obvious!

Next up, the standard libraries are pure garbage. Seriously, they are freaking awful. When it comes to certain every day tasks ( data access, gui, xml handling, string manipulation, web access, etc... ) they suck or simply don't exist. This is both a strength and weakness of C++, but from a beginners perspective, it is a weakness, a gigantic one.

Then there is the linker and preprocessor. Modern languages don't really have these anymore, and for good reason. Very early on, new developers have to deal with these baffling concepts and the experience sucks. Figuring out headers and include guards, figuring out how to link your program, static vs dynamic vs static debug, vs dynamic debug linking... this isn't stuff a beginner should have to deal with, but the second they want to do something the minimalistic standard libraries dont support ( such as graphics... ), they need to conquer this mountain as well.

Then of course, there is the language itself. People often cite manual memory management as the biggest hurdle to a new C++ programmer. This is not only untrue, it's actually proof that people are learning from outdated sources! That said, memory management in C++ is a pain in the ass. So are the inheritence rules, especially around multiple inheritence. So are a few thousand other byzantine rules behind it.



Dont get me wrong, C++ has its merits. First off, and this is a big one, it is ubiquitous, which is probably the most important thing. It is used, and it is everywhere. Basically it is the current least common denomintor language on every platform ( except win phone 7 and pre BB10 devices). Next, for an expert, the everything is optional approach is a blessing, especially when you are trying to ring out every bit of performance. It has a good ecosystem, especially when it comes to games, and exceptional tooling support in the form of Visual Studio and to a lesser degree Qt Creator.

However, not a single one of those strengths is a good thing or a positive for a beginner.


Let me reinforce a point that only experience can teach, one last time. Your first language is your hardest to learn. So don't make the task harder on yourself than necisarry. You can always pick up C++ later, and will probably be a hell of a lot more successful when you do! If you do go with C++, learn C++ 11 using modern tools ( this means no DevC++ and no C or direct memory management ). I know people won't listen to me, which is why I created this tutorial. It eases the transition from simple console apps to complete games, and hopefully encourages a modern and clean style. ( By the way, there is naked memory access in the example... part 8 or so. This was always intended to be replaced in an upcoming part... that I havent written yet! ;) ).

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.



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.
There's nothing to add to this. Too bad people won't listen.
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 topic is closed to new replies.

Advertisement