When learning new languages related readings, Distractions or Aids? - c++

When learning new languages such as C++ from PHP, does reading other language snippets help you understand better by giving one a different prospective, or does doing so confuse a noob like me? Also, any advice on learning C++ would be great.

I find that reading short snippets helps a lot. A good book is really handy too. Once you understand most of the language itself, reading large, full-size programs helps a lot with learning how common problems are solved in that language. Most languages don't have a term for this, but it is like the "Pythonic" way in Python.
As for learning C++, first get a good understanding of C. C is quite simple, so it shouldn't take that long. Once you know C, start learning about the C++ specific features one at a time. This way, you can still write useful programs (C is mostly a subset of C++), before you learn the real "C++ic" way.

I find it helps to
Get a good grasp of the syntax and semantics of the language, by looking at SIMPLE examples and relating it to something you already know
Look at what libraries and design patterns are common. Find out why they are common. Was the language designed to encourage them? Is it convention? Efficient?
have an idea that you want to implement in the language. It will give you a goal, and some perspective.
Look at other's code, once you are comfortable picking apart and reading it, and comfortable with source-layout, conventions, common-naming and so on
I find it best to dive-in heads first. Get feedback from people if possible. Most importantly:
don't be afraid of making mistakes they are a big part of the learning process. And try and relate things to concepts you are already comfortable with.

If you are sufficiently inexperienced to ask this question, I recommend that you read short snippets, but not in another language. A better mental exercise is to say given a short snippet in the new language (C++), how would it compare with what you would write in the old language you already know (PHP)? Similarly, if you read about a new C++ thing, ask what PHP snippets you could express in the new C++ish way.
Regarding C++ itself, there are plenty of other SO questions to trawl. I think it bears repeating that the Design Patterns book with four authors is very helpful to learn the vocabulary and mindset of many longtime C++ programmers.

Related

C++ - Need to learn some basics in a short while

For reasons I will spare you, I have two weeks to learn some C++.
I can learn alone just fine, but I need a good source. I don't think I have time to go through an entire book, and so I need some cliff notes, or possibly specific chapters/specialized resources I need to look up.
I know my Asm/C/C# well, and so anything inherited from C, or any OOP is not needed.
What I do need is some sources on the following subjects(I have a page that specifies what is needed, this is basically it, but I trimmed what I know):
new/delete in C++ (as opposed to C#).
Overloading cin/cout.
Constructor, Destructor and MIL.
Embedded Objects.
References.
Templates.
If you feel some basic C++ concept that is not shared with C/C# is not included on this list, feel free to enter those as well. But the above subjects are the ones I'm supposed to roughly know in two week's time.
Any help would be appreciated, thanks.
Edit: I want to clarify - I don't expect to study for two weeks and then go and write Quake.
I need to get to a level where given some code and a while to think about it, I can understand it. nuances like ++X vs X++ don't matter as much as knowing what the main keywords are, etc.
This site is your best bet. Although its a great reference anyway, the way the questions are phrased and organised you'll be able to get up to speed quicker:
http://www.parashift.com/c++-faq-lite/
I will be honest with you. In 2 weeks, you won't be able to learn the whole C++.
Let me rephrase that, because no one will ever know everything about C++ (it is very huge and yet it's still growing), you won't be able to learn everything you need to become an expert C++ programmer.
However, if you do have some good programming background, many concepts in C++ will sound familiar to you. This will help you learn complex concepts quicker than novice programmers.
I would suggest you to go to C++ FAQ Lite
because it is the site that lists all the main concepts of C++.
Don't expect to program something enterprisy after going through the site, because that ability comes after you have coded some extensive systems in C++. However, the site will definitely help you to understand what C++ looks like and other people deal with in C++.
GOOD LUCK :)
Thinking in C++, Volume II. Free, well written and available online.
http://www.mindview.net/Books/TICPP/ThinkingInCPP2e.html
I know you said you didn't want to read a book but "Accelerated C++" is probably what you want. It was actually was used in like a 2 week crash course at Stanford from what I remember to get people up to speed on C++.
If you do not have time to go through an entire book, you may try an online tutorial such as the one at http://www.cplusplus.com/doc/tutorial/.
However, it will be useful to go into more depth about common pitfalls and good practice in C++. A good online resource for this is the C++ FAQ lite, at http://www.parashift.com/c++-faq-lite/ .
If you decide to buy or borrow a book, "Effective C++" by Scott Meyers would be a good choice. You do not need to read it front to back, as each chapter is dedicated to a specific problem you are likely to encounter when writing C++ code, and can be read separately.
If you need quick explanations of specific sections of the language, http://www.learncpp.com/ is also a good resource. The caveat is that their webserver is dog slow most of the time (which is unfortunate, because they have some really good explanations).

Learning C++ as a Perl programmer [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
I'm a Perl5 programmer for 7 years and I'm trying to learn C++ now.
Some of the C++ syntax is hard for me to understand and to think in C++ way.
For example:
In Perl, you can mix the data in the arrays
#array = (1,"string",5.355);
You can assign any value to a scalar variable:
$var = 1;
$var = "string";
$var = \$reference_to_scalar;
There are many examples.
A friend of mine recommend me the book "Thinking of C++" by Bruce Eckel, but I haven't any C background and it's hard for me to understand some things.
So my question is - could you recommend me a book for this situation. I don't want to learn C. I understand OOP (I'm getting more familiar with C++ oop aswell), I understand the point of the pointers (and some arithmetic) and references (widely used in Perl).
I don't need manuals for dummies (what is int, bool, double, if, while), I just need a direction how to learn C++ from the perspective of a Perl programmer, because I'm sure that there are many like me.
Thank you in advance.
EDIT: Thank you for all the recommended books and the answers, I will try with "Accelerated C++". I will start from the beginning and try to change my mindflow to C++. I have added the "beginner" tag.
"C++ For Perl Programmers" is a pretty specific request. Given that Perl abstracts away more of the machine than C++ does, I think that a good way to start would be to forget what you know about Perl and get a regular C++ book.
For example, it seems reasonable to you that you should be allowed to have multiple data types in an array, because a Perl array is a higher-level construct than just a series of contiguous words in memory. If I were going to go from an array in C++ to one in Perl, I would say that a Perl array is like a C++ array that holds pointers to data instead of data (if that is even true - I am not a Perl programmer so it may not be. Maybe a Perl array is more like a linked list data structure. In any case, you get the idea.) Going backwards, IMO, is not quite the same.
As far as the book I'd recommend - there are a lot of good ones, so it depends on the style and depth you're looking for. I think Accelerated C++ is great for ramping up - its thorough and covers a lot of ground without inundating you with the tedious details.
Don't bother with learning C unless you want to know C. Programming in C++ is nothing at all like programming in C. I realize most books and teachers claim otherwise, but they're wrong. You should be looking for the exceptions, such as the previously mentioned, "Accelerated C++."
You won't find any books that will help you write code like the code you've just shown. Perl is a very weakly typed language and C++ is exactly the opposite: a strongly typed language. There are, however, ways to get kind of what you're showing in your post in various boost constructs such as variant and tuple.
I would suggest though learning C++ as a totally independent language before stepping into that kind of thing. Don't learn C++ as a Perl Programmer, learn it as a complete newb. You may be bored with the first few chapters but in the end you'll have a better grasp of the style and powers unique to C++ vs. those unique to Perl. I haven't seen any "Xlanguage for Ylanguage" book that will get you there.
I've gone through the opposite process. One of the first things I learned was that while you can write Perl code that looks like C or C++, you shouldn't. The same goes for you. You can probably find a way to write Perl-ish C++ code, but don't bother. The languages are too different. You need to learn how to write C++ code as a C++ programmer. Several goods books have already been suggested. I think you should augment that by finding a mentor. You'll get immediate feedback if you're doing things the right or wrong way. You can also check out the C++ FAQ Lite, especially chapters 28 and 29 on issues for new C++ programmers.
The biggest difference is that C++ is strongly typed. Every variable has a type, and it doesn't change. Your example Perl code is technically possible in C++, but it requires an extra library that I'm not sure you're ready for yet. Instead, the C++ way is to think about a collection of mixed but related items as their own new type - a struct or class.
Another great option is to post specific C++ questions here on SO. We encourage beginner-level questions as long as they're clearly worded and show some prior effort.
I tried to learn C++ from the "Thinking in C++" book. I found it very, very hard to learn from.
A much better book for someone starting in C++ is "Accelerated C++: Practical Programming by Example" by Andrew Koenig and Barbara E. Moo
I second Thinking In C++. I read it after knowing perl, and I found it very good. The second edition doesn't assume C knowledge; here's what it says under Prerequisites in the Preface:
In the first edition of this book, I
decided to assume that someone else
had taught you C and that you have at
least a reading level of comfort with
it. My primary focus was on
simplifying what I found difficult:
the C++ language. In this edition I
have added a chapter that is a rapid
introduction to C, along with the
Thinking in C seminar-on-CD, but I am
still assuming that you already have
some kind of programming experience.
In addition, just as you learn many
new words intuitively by seeing them
in context in a novel, it’s possible
to learn a great deal about C from the
context in which it is used in the
rest of the book.
As danben said, you pretty much just need to "forget what you know about perl". It's useful to know perl just because it's another programming language (C-like, even), but it's nowhere near similar enough to just "learn the differences".
Also: Thinking In C++ is free for the electronic version.
I work with Perl exclusively for my day job and program C++ for fun on nights and weekends. They require totally different mind sets. You're better off approaching C++ as a noob programmer and learn it from 'Hello World' on up. Sure you can fast track over general concepts such data types, but still pay enough attention to know your short from your long and your reference from your pointer.
I would avoid learning C first unless you really need to know C. Character handling in C is a pain and not suited for what I suspect you want to do. The String class in C++ is your friend: learn it, live it love it!
Actually, since you already know an imperative language, learning C won't take you much time at all. The basics are all the same -- if statements, while loops, for loops etc. Even the way the namespaces are organized are similar (although the guts of course are different.) You might want to gloss over some of the pointer handling, as C++ does references a little differently, but you would not be doing yourself any harm by picking up and reading through a copy of K&R (the official C reference) at least once. (Every decent programmer should have a copy on his bookshelf as a reference, anyway.)
After that, pick up a recent edition of Stroustrup and have at it, ensuring that you work through the exercises. Some of the concepts may be a little foreign to a Perl-oriented mind, but it won't be too strange. If you encounter a particular concept you find tricky, post again on SO and there will be lots of people happy to go through it with you!
(source: wikimedia.org)
(source: att.com)
My university recommended us this book : http://www.lrde.epita.fr/~akim/ccmp/assignments.html#C_002b_002b-Primer
Anyway, Thinking in C++ is available on the web for free. You could find the link on the previous link I gave you.
Good luck :)
Here you can find a vast variety of free downloadable/online books.
The Stroustrup book is a little hard when learning the language, its better to try another book and use the Stroustrup book as a reference.

C++ for Ruby scripters

I am a fairly capable Ruby scripter/programmer, but have been feeling pressure to branch out into C++. I haven't been able to find any sites along the lines of "C++ for Ruby Programmers". This site exists for Python (which is quite similar, I know). Does anyone know of a guide that can help me translate my Ruby 'thoughts' into C++?
I don't think that language introductions written specifically for migrants from a certain language have considerable advantage over traditional "independent" introductory books. Reading as a cognitive process has a great feature: reading speed varies greatly. That means that you should take any good C++ book (I'm sure you'll find excellent recommendations here on SO) and your reading speed will be greatly affected by your previous programming knowledge - reading about things you already know will become almost skimming-fast, others will take some time. In the end, you will spend practically the same amount of time as you would if you read a specific migrant course, with the difference of having read a book that you will be able to use as a language reference at any given time in the future, unlike the "transitional guide", which is always kind of "one-time read".
On the other hand, from a perspective of a writer, it's pretty ungrateful to assume (and rely on) such thing as reader's knowledge on a topic. When one says he knows Ruby is it really a guarantee that he knows OOP thoroughly, for example? Or just have been using it not understanding the internals (which is really easy for a Rails programmer, for example).
So a general book is a safe bet both for a writer and a reader. :)
I agree with others. Your skills in Ruby will certainly help you to learn C++ in a way, but they are quite different. A great online book to learn C++ : Thinking in c++
Bruce Eckel's books are a really good start with an adapted learning curve. Simple to begin but going quite deep into the language. Recommended.
my2c
If you want to learn C++, start here.
Once you have learned the fundamentals, you should also look into these:
Effective C++,
More Effective C++,
Effective STL, and
Exceptional C++

Resources to learn C++ itself, not the basics of programming? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I'm something of a new, reluctant convert to C++ from a Pascal, Ruby, and PHP background. I haven't worked with Pascal since a few months of torture with "Delphi Turbo;" since then I've practically been eating and sleeping Ruby and PHP. I'm already well acquainted with object oriented programming and many various subjects.
My main trouble is that I already know the rudiments of C/C++ programming, less the actual experience of working with C++. I worked with C for long enough to realize that even without macros, etc, I didn't want to work with it. (Some of the disgust was from maintaining a CGI application in C, when accustomed to Pascal's automatic string management.) I know just enough C++ to be dangerous to myself and anyone else unwitting enough to use my "code."
I'd really like to work up to a good enough understanding of C++ to use libraries like Crypto++ and Boost without major problems or in-depth knowledge of the language's intricacies. I just need to figure out how to work with C++ without killing myself (either with C++, or with the long-standing dislike that I'm already battling).
What are effective resources that will teach me C++ without assuming that I must be retaught all basic programming? I'd rather not relearn concepts that I already know, unless the paradigm in C++ is significantly different. I'm also learning on my own time, so don't recommend me a book complex enough to need a guru to explain to me, please! And I have an effective budget of $0 for learning C++, so please keep suggestions to quality online resources or books common enough that I could likely find them at the library.
Read Effective C++ by Scott Meyers - it's a good guide for getting past the basics of C++ and showing how to write and use "correct" C++ code
The C++ FAQ Lite is a great resource.
I highly recommend Stroustrup: The C++ Programming Language (Third Edition). As the author of C++ he is the authority on the language, and the book is useful as a reference as much as it is for learning the language. It's common enough that most good general purpose libraries will have a copy. He goes into quite some depth on all the features of C++, including explanations of why certain design decisions were made in the language. Personally, I think this is the best book around for programmers to learn C++.
Once you have a good grip on core C++, David Abrahams and Aleksey Gurtovoy's book, C++ Template Metaprogramming, goes into further depth and provides many examples of how C++'s template system allows you to perform complex compile-time programming, a highly valuable skill these days. This one is a little less common but you can probably find it at a university library.
I can give you a couple of keywords you might want to research in more detail:
RAII (Is pretty much the technique that ensures you don't have to worry about memory leaks. Very convenient)
Generic Programming (The STL in particular. Experiment with iterators and the standard library algorithms, and see just how powerful these abstractions are. They're a key part of what I like about C++)
Functors (Perhaps too simple on their own, but the way they can be used instead of function pointers with the algorithms mentioned above is interesting)
And just get familiar with templates, and "mild" forms of template metaprogramming. (Traits classes, for example, and (partial) specializations.
And just keep an eye on the C++ questions here on SO. A lot of interesting topics are regularly brought up.
But the best advice is probably to keep it completely separate from C. Forget everything you learned about how to use C. It either doesn't apply in C++, or leads to inferior code that is harder to read and maintain.
It's an interesting language in its own right, and has a number of unique features. Leverage those, and it can actually be fun to work with C++. Treat it as an overengineered Java, PHP or C, and it'll just make you want to throw up.
You need to write code. A lot of code in C++. There is no substitute. You also need to read good code.
I agree with the suggestion for Scott Meyers' books though. Those are pretty good.
Part of your learning will be the leap from procedural programming to OO.
I would highly recommend the book "C++ Common Knowledge" by Stephen C. Dewhurst. Don't know if it's common enough to be found at the library (it's not at mine, but my library sucks for computer books that aren't 5-10 years out of date), but it does an excellent job of taking the complex aspects of C++ and making them easy to understand, without dumbing anything down for beginners. Definitely worth the investment.
To quote from the back of the book:
This book is for you if
You're no "dummy," and you need to get quickly up to speed in intermediate to advanced C++
You've had some experience in C++ programming, but reading intermediate and advanced C++ books is slow-going
You've had an introductory C++ course, but you've found that you still can't follow your colleagues when they're describing their C++ designs and code
You're an experienced C or Java programmer, but you don't yet have the experience to develop nuanced C++ code and designs
You're a C++ expert, and you're looking for an alternative to answering the same questions from your less-experienced colleagues over and over again
C++ Common Knowledge covers essential
but commonly misunderstood topics in
C++ programming and design while
filtering out needless complexity in
the discussion of each topic. What
remains is a clear distillation of the
essentials required for production C++
programming, presented in the author's
trademark incisive, engaging style.
Here is a link to a question with answers that should help you.
https://stackoverflow.com/questions/1227764/i-need-to-improve-my-c-skills-fast-is-this-realistically-possible/1227805#1227805
For effective stuff you can find online Cplusplus.com has a pretty good reference and information.
If you can find the book "C++ Common Knowledge" (Stephen Dewhurst) at the library or cheaply online, I would add that to the list posted on the StackOverflow link above as well as "The C++ Programming Language" (Stroustrup). Going through the questions under the C++ tag right here on SO should give you some good pointers and code examples to get you on your way.
Here's a list of good C++ books which teach you C++ rather than basics of programming.
Sit down and write some C++ code.

Should I learn C before learning C++? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance.
Closed 10 years ago.
I visited a university CS department open day today and in the labs tour we sat down to play with a couple of final-year projects from undergraduate students. One was particularly good - a sort of FPS asteroids game. I decided to take a peek in the src directory to find it was done in C++ (most of the other projects were Java 3D apps).
I haven't done any C before but I have looked through some C code before. From what I saw in the .cpp code in this game it didn't look very different.
I'm interested in learning either C or C++ but will probably learn the other later on. Is there any advantage to me learning one before the other and if so, which one?
There is no need to learn C before learning C++.
They are different languages. It is a common misconception that C++ is in some way dependent on C and not a fully specified language on its own.
Just because C++ shares a lot of the same syntax and a lot of the same semantics, does not mean you need to learn C first.
If you learn C++ you will eventually learn most of C with some differences between the languages that you will learn over time. In fact its a very hard thing to write proper C++ because intermediate C++ programmers tend to write C/C++.That is true whether or not you started with C or started with C++.
If you know C first, then that is good plus to learning C++. You will start with knowing a chunk of the language. If you do not know C first then there is no point focusing on a different language. There are plenty of good books and tutorials available that start you from knowing nothing and will cover anything you would learn from C which applies to C++ as well.
Please see further reasoning in this answer.
I love this question - it's like asking "what should I learn first, snowboarding or skiing"?
I think it depends if you want to snowboard or to ski. If you want to do both, you have to learn both.
In both sports, you slide down a hill on snow using devices that are sufficiently similar to provoke this question. However, they are also sufficiently different so that learning one does not help you much with the other. Same thing with C and C++. While they appear to be languages sufficiently similar in syntax, the mind set that you need for writing OO code vs procedural code is sufficiently different so that you pretty much have to start from the beginning, whatever language you learn second.
I learned C first, and I took a course in data structures which used C, before I learned C++. This has worked well for me. A data structures course in C gave me a solid understanding of pointers and memory management. It also made obvious the benefits of the object oriented paradigm, once I had learned what it was.
On the flip side, by learning C first, I have developed some habits that initially caused me to write bad C++ code, such as excessive use of pointers (when C++ references would do) and the preprocessor.
C++ is really a very complex language with lots of features. It is not really a superset of C, though. Rather there is a subset of C++ consisting of the basic procedural programming constructs (loops, ifs, and functions), which is very similar to C. In your case, I would start with that, and then work my way up to more advanced concepts like classes and templates.
The most important thing, IMHO, is to be exposed to different programming paradigms, like procedural, object-oriented, functional, and logical, early on, before your brain freezes into one way of looking at the world. Incidentally, I would also strongly recommend that you learn a functional programming language, like Scheme. It would really expand your horizons.
If you decide to learn both (and as other people have mentioned, there's no explicit need to learn both), learn C first. Going from C to C++ feels like a natural progression; going the other way feels like deliberately tying one hand behind your back. :-)
I think you should learn C first, because I learned C first. C gave me a good grasp of the syntax and gotchas with things like pointers, all of which flow into C++.
I think C++ makes it easy to wrap up all those gotchas (need an array that won't overflow when you use the [] operator and a dodgy index? Sure, make an array class that does bounds checking) but you need to know what they are and get bitten by them before you understand why things are done in certain ways.
When all is said and done, the way C++ is usually taught is "C++ is C with objects, here's the C stuff and here's how all this OO stuff works", so you're likely to learn basic C before any real C++ if you follow most texts anyway.
I'm going to disagree with the majority here. I think you should learn C before learning C++. It's definitely not necessary, but I think it makes learning C++ a lot easier. C is at the heart of C++. Anything you learn about C is applicable to C++, but C is a lot smaller and easier to learn.
Pick up K&R and read through that. It is short and will give you a sufficient sense of the language. Once you have the basics of pointers and function calls down, you can move on to C++ a little easier.
In the process of learning C++ you will learn most of C as well. But keep in mind a lot of C++ code is not valid C. C++ was designed to be compatible with C code, so i'd say learn C++ first. Brian wrote a great answer regarding this.
Learning C forces you to think harder about some issues such as explicit and implicit memory management or storage sizes of basic data types at the time you write your code.
Once you have reached a point where you feel comfortable around C's features and misfeatures, you will probably have less trouble learning and writing in C++.
It is entirely possible that the C++ code you have seen did not look much different from standard C, but that may well be because it was not object oriented and did not use exceptions, object-orientation, templates or other advanced features.
Like the answers to many other questions in life, it depends. It depends on what your programming interests and goals are. If you want to program desktop applications, perhaps with a GUI, then C++ (and OOP) is probably a better way to go. If you're interested in hardware programming on something other than an x86 chipset, then C is often a better choice, usually for its speed. If you want to create a new media player or write a business app, I'd choose C++. If you want to do scientific simulations of galaxy collisions or fluid dynamics, behold the power of C.
I think learning C first is a good idea.
There's a reason comp sci courses still use C.
In my opinion its to avoid all the "crowding" of the subject matter the obligation to require OOP carries.
I think that procedural programming is the most natural way to first learn programming. I think that's true because at the end of the day its what you have: lines of code executing one after the other.
Many texts today are pushing an "objects first" approach and start talking about cars and gearshifts before they introduce arrays.
No.
It's generally more useful to learn C++ because it's closer to the most modern OO-based languages, like Eiffel or C#.
If your goal is to learn C++, learn modern, standard C++ in the first place. Leave the mallocs aside.
But Steve Rowe has a point...
Having observed people, who have learned Java first, struggle with the concepts of pointers and memory management in C++, I'd say that learning C first is a good idea, in order to grasp these two concepts, isolated from the complexities of other C++ features.
My two cents:
I suggest to learn C first, because :
it is a fundamental language - a lot of languages descended from C
more platforms supports C compiler than C++,- be it embedded systems, GPU chips, etc.
according to TIOBE index C is still about 2 times more popular than C++.
i think c is a really nice programming language, it's compact and somewhat easy to learn.
but if you only want to learn c++ start with c++. but i suggest you to learn both. and if you want to do that; i think it's better to start with c. as said before: it's small and somewhat easy to learn. might be a nice step-up to a more complex programming language as c++. (since c provides you with some basics)
good luck.