It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
I know the basic OOP-related topics, RTTI, Templates. Reverting back from Java' Collection Framework, I tried to find such collections in C++ and found STL, and am trying to use it in my projects (although I don't know them in and out). I searched and found recommendations for books like Accelerated C++, Effective and More Effective C++.
But I am not sure what should be my progression path. I am looking for something like this -- Python-Progression Path:
def apprentice():
read(diveintopython)
experiment(interpreter)
read(python_tutorial)
experiment(interpreter, modules/files)
watch(pycon)
def master():
refer(python-essential-reference)
refer(PEPs/language reference)
experiment()
read(good_python_code) # Eg. twisted, other libraries
write(basic_library) # reinvent wheel and compare to existing wheels
if have_interesting_ideas:
give_talk(pycon)
def guru():
pass # Not qualified to comment. Fix the GIL perhaps?
Discover list comprehensions
Discover generators
Incorporate map, reduce, filter, iter, range, xrange often into your code
Discover Decorators
Write recursive functions, a lot
Discover itertools and functools
Read Real World Haskell
Rewrite all your old Python code with tons of higher order functions, recursion, and whatnot.
Annoy your cubicle mates every time they present you with a Python class. Claim it could be "better" implemented as a dictionary
plus some functions. Embrace functional programming.
Rediscover the Strategy pattern and then all those things from imperative code you tried so hard to forget after
Haskell.
Find a balance.
It's a tough question, because what you really need is becoming good at what you do, and thus no authoritative list exists.
That being said...
Read Effective C++ by Meyers and C++ Coding Standards by Sutter, you're not likely to understand everything if you're a beginner, so re-read them from time to time (it's also a good vaccine)
Time to introduce the STL (it's an amazing little pearl), learn to use its algorithms instead of hand-crafting everything, if possible jump straight to the C++0x version
Incorporate Boost into the mix, softly at first: boost::optional, boost::variant, boost::lexical_cast, boost::numeric_cast make your code safer and more idiomatic. Also poke the Boost String Algorithms library.
Template Meta Programming and Boost.MPL are next: C++ Template Meta Programming by Abrahams Gurtovoy will help there. You might have to leverage Boost.Preprocessor for some template stuff.
Learn more Boost Libraries, it's a gigormous repository and it's amazing all the libraries there are.
I am still at that last part myself, so cannot comment on going further :)
At each step, you should write a lot of code, reading isn't sufficient, you need to experiment. Programming is not just technic, the architectural part of the program is extremely important in the field.
Oh and try and join (if only to read) an open-source project, nothing beats writing code and it's better when someone else reviews it :)
First get really good with C. I recommend "Deep C Secrets" by Peter van der Linden.
Get a copy of "Effective C++" by Scott Meyers, and commit it's advice to memory ("More Effective C++" is also pretty good).
Read "Advanced C++" by Coplien.
Read the The C++ FAQ.
Read "The C++ Programming Language" by Stroustrup at this point.
Related
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 11 years ago.
I am new to Stack Overflow, and new to programming.
I am learning how to program in C++.
My question is not related to specific code, but is about research and learning the language.
What I have learned so far relates to narrow examples of syntax and simple programs which use variables, functions, arrays, etc.
I am wondering if people have or can link to example programs so I can study them.
I'm looking for console programs which:
use variables (int, double, string, etc)
use functions
use arrays use classes with
attributes and methods use objects of that class
reads and writes to a file
validates user inputs, displaying appropriate error messages
and is basically a useful program.
Through Google, I have mostly only been able to find C++ tutorial pages (cplusplus, cprogramming, etc) which deal with each of the above separately, usually in a bare-bones way to show the syntax. I'm looking for something more complex (but not overly so) so I can learn how to combine these things in a meaningful way with the intent of eventually writing programs of my own at the same level.
I've already coded a calculator (though not one that has all of these features; namely it was missing file i/o and I was able to make a basic one which didn't need objects), so I'm looking for something different. I understand console programs are text based and lend themselves well to these kind of programs, so it can be a calculator of another type, as long as it isn't a basic arithmetic one.
People here won't teach you C++. In fact, even a book or Google by themselves won't exactly teach you any language, they are just tools to make your life easier and the studying curve smoother.
My suggestion is to use Google or a good C++ book and write code.. especially write code, otherwise you won't learn anything, you must get your hands dirty in order to learn C++.
cplusplus.com has a few examples.
As #GMan said, you'd be better off reading a book.
Possibly Effective C++ by Scott Meyers, or maybe one in the Beginner\Introductory section.
The best way to improve is to give yourself a task and code it. Use different techniques/paradigms (OOP, modular, etc). Instead of studying programs, try to create them yourself - you'll learn a lot better this way.
The book can guide you, but you must make the journey.
Here are some exercises. You can try solving puzzles, too. CodeGolf.SE is good if you want to have some fun.
I hope you've got an excellent book. :)
That said, I understand the desire to find source code you can read that's larger than toys, but not giant cathedrals of code; perhaps the AppArmor policy parser can be of service to you. It's a little bit involved, because it's a small-language compiler that builds a DFA of a security policy for 'execution' in the kernel when confined programs perform file operations.
You can clone it with bzr: http://bazaar.launchpad.net/~apparmor-dev/apparmor/master/ or you can browse the source code: http://bazaar.launchpad.net/~apparmor-dev/apparmor/master/files/head:/parser/libapparmor_re/
Supplementing the other posts directing you to various reading, if you are new to programming, I highly recommend starting your venture into programming with Python.
Python is an easy-to-learn programming language that has a LOT built-in and will allow you to start making useful "programs" very quickly.
For example, you can read the entire contents of a text file with a single line of code:
file_contents = open('example.txt','r').read()
I feel it keeps people more encouraged when they can see significant results as they learn. If you are interested, Dive Into Python is a very popular tutorial.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
I'm starting C++ programming in my first job. I'm a CS student and I have learn programming in Java. What advice would you tell me to watch out so I don't cause trouble in my new job?
Would you have any advice or references would be appreciated.
(example: I know C++ is more likely to have memory problem than Java)
Thank you very much!
Maybe you already know this, but one common mistake for folks used to Java and learning C++:
Don't use new unless you have to (and you probably don't really have to). In most cases where you want to create an object, you should just create it "on the stack", like ClassType obj;.
Two things:
Get yourself a copy of Effective C++ by Scott Meyers.
Lint your code. This will not only catch potential bugs early in the development process, but also teach you good coding habits (e.g. declaring a method's input arguments as const references). I use PC-Lint for this.
For me, the biggest difference between Java and C++ is pointers, so I would try to get pointers down. Just my opinion.
No two ways about it. You're going to be a menace until you've been bit enough by C++ gotchas to hate the language. I'd recommend trying to write functions and not classes. A lot of people think OOP is great, but really most users want your code to "do" something, not "be" something. Anyways, good luck. :-)
Definitely what Chance said. Memory management is explicit in C++. I had an excellent textbook in college called Deitel C++. It's a C++ Bible.
I would also learn up on the Standard Template Library and Boost.
This might give you some ideas.
Some important excerpts :
Researchers (Bloom (1985), Bryan & Harter (1899), Hayes (1989), Simmon & Chase (1973)) have shown it takes about ten years to develop expertise in any of a wide variety of areas, including chess playing, music composition, telegraph operation, painting, piano playing, swimming, tennis, and research in neuropsychology and topology. The key is deliberative practice: not just doing it again and again, but challenging yourself with a task that is just beyond your current ability, trying it, analyzing your performance while and after doing it, and correcting any mistakes. Then repeat. And repeat again.
And here is how to do :
Get interested in programming, and do some because it is fun. Make
sure that it keeps being enough fun so that you will be willing to
put in your ten years/10,000 hours.
Program. The best kind of learning is learning by doing. To put it
more technically, "the maximal level of performance for individuals
in a given domain is not attained automatically as a function of
extended experience, but the level of performance can be increased
even by highly experienced individuals as a result of deliberate
efforts to improve." (p. 366) and "the most effective learning
requires a well-defined task with an appropriate difficulty level for
the particular individual, informative feedback, and opportunities
for repetition and corrections of errors." (p. 20-21) The book
Cognition in Practice: Mind, Mathematics, and Culture in Everyday
Life is an interesting reference for this viewpoint.
Talk with other programmers; read other programs. This is more
important than any book or training course.
If you want, put in four years at a college (or more at a graduate
school). This will give you access to some jobs that require
credentials, and it will give you a deeper understanding of the
field, but if you don't enjoy school, you can (with some dedication)
get similar experience on your own or on the job. In any case, book
learning alone won't be enough. "Computer science education cannot
make anybody an expert programmer any more than studying brushes and
pigment can make somebody an expert painter" says Eric Raymond,
author of The New Hacker's Dictionary. One of the best programmers I
ever hired had only a High School degree; he's produced a lot of
great software, has his own news group, and made enough in stock
options to buy his own nightclub.
Work on projects with other programmers. Be the best programmer on
some projects; be the worst on some others. When you're the best, you
get to test your abilities to lead a project, and to inspire others
with your vision. When you're the worst, you learn what the masters
do, and you learn what they don't like to do (because they make you
do it for them).
Work on projects after other programmers. Understand a program
written by someone else. See what it takes to understand and fix it
when the original programmers are not around. Think about how to
design your programs to make it easier for those who will maintain
them after you.
Learn at least a half dozen programming languages. Include one
language that supports class abstractions (like Java or C++), one
that supports functional abstraction (like Lisp or ML), one that
supports syntactic abstraction (like Lisp), one that supports
declarative specifications (like Prolog or C++ templates), one that
supports coroutines (like Icon or Scheme), and one that supports
parallelism (like Sisal).
Remember that there is a "computer" in "computer science". Know how
long it takes your computer to execute an instruction, fetch a word
from memory (with and without a cache miss), read consecutive words
from disk, and seek to a new location on disk. (Answers here.)
Get involved in a language standardization effort. It could be the
ANSI C++ committee, or it could be deciding if your local coding
style will have 2 or 4 space indentation levels. Either way, you
learn about what other people like in a language, how deeply they
feel so, and perhaps even a little about why they feel so.
Have the good sense to get off the language standardization effort as
quickly as possible.
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 12 years ago.
I've barely/rarely used C++ in the past decade, and now it looks like I'll be doing something in it again. I'm looking forward to it, but have to wonder how it's changed since I last used it.
Are there any good / brief web pages, blog posts, or even books on how C++ has changed in the past decade?
Please note this question is regarding the language as well as tools or any additional information about working in C++. Specifically I'm working in Windows, using VC++2008.
While the official standard hasn't changed much over the past decade or so, there are several things of importance that have happened:
while it's not an official standard yet, an upcoming new standard (commonly called C++0x) is 'around the corner'. GCC and MSVC 2010 have incorporated significant parts of that new standard, but I'm not sure how much is in common use.
the Boost library has become a major player in providing additional support for the language - to the point that it was a significant influence on the new standard
'template-based' programming techniques have become much more prevalent, probably overtaking the older 'inheritence-based' techniques of code reuse (this might have been well underway when you last looked at C++ depending on the practives your shop may have been using at the time).
compilers (and in particular Microsoft's) have come a long way in standards compliance
The biggest change is that C++ standard actually works in all major compilers now. Things like member templates used to be iffy.
The language itself has not changed much. However, the best practices and idioms did a lot.
I suggest you take a look at the book "C++ Coding Standards: 101 Rules, Guidelines, and Best Practices" by Herb Sutter and Andrei Alexandrescu to see how modern C++ looks like today.
I think one of the biggest changes is one of mindset: many people have (finally!) realised that templates are incredibly powerful and don't need to be slow, and use of the STL and boost is much more widespread than 10 years ago.
VS2008 comes with TR1, a large addition to std that contains things like static arrays, reference counting pointers, and suchlike. Apart from that, the biggest change is just that the compiler compiles how the Standard defines.
An interesting question as I'm coming up to my 10th anniversary of programming C++ for coins.
My personal view is that I'd be somewhat wary -- but only somewhat -- since I haven't seen it all (though I think I can guess what it's like) -- of paying strong attention to the internet echo chamber. It's true, some people have gone full bore for the modern style of C++, with everything fully template'd up and using modern techniques to get the compiler doing its Prolog thing to best effect. However this is certainly not universally true, and, in the main, the C++ code I see today is very similar in most ways to the C++ code I saw ten years ago.
It would be a good idea to brush up on modern fashions, because some stuff that was somewhat rare ten years ago (smart pointers, regular use of RAII, standard library containers and stuff) is now more common. But unless you are sure that the code you will be working with is festooned with templates and boost and so on, you stand a good chance of working with something that's at heart very much like what you used to work with.
It may be unfashionable to say it, but that doesn't make it any less true: regardless of skill level, lots of people don't care for modern C++. Some, because they don't understand it. Some, because they do understand it. And for some, perhaps "care" isn't even the right word -- they don't even know it exists. And as you might expect these people all code accordingly.
Perhaps I move in the wrong circles, but my experience has been people who don't or can't or won't code in the modern style outnumber those that might do by some vast margin. And those who might do, generally don't, because they're outnumbered. Their code gets rewritten, or ignored, until they start writing stuff that other people can understand. So maybe this is good, or maybe this is bad -- it's hardly relevant, in my view, because the outcome is the same: that if your experience turns out to be anything like mine, you have a good chance of encountering today code that's remarkably similar to what you would have seen in 1999.
P.S. Nicolai Josuttis has written a couple of books that my last employer's resident template expert seemed to like. Also try Modern C++ Design (Alexandrescu) -- probably a bit dated now, but it explains many of the principles. Herb Sutter's Exceptional C++ gives, as I recall from a skim of a work copy, a good overview of some modern techniques without going too nuts on the template front. And of course boost demonstrates all this sort of thing (and much, much more -- then some bonus material) put into practice over a range of compilers.
(Hopefully the above list is not too dated; as my answer might suggest, I have found much less of a need to keep up to date with the latest trends in C++ than I would ever have expected.)
It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center.
Closed 10 years ago.
C++ has too many features, and I can't see how any programmer is able to remember all these features while programming. (We can see how this affected the design of newer languages, such as Java)
So, what I need is a list of features that are enough to know, disregarding all the others, to create c++ programs, perhaps created by someone who thought the same way as I did.
Hope I was clear enough.
Learn Resource Acquisition Is Initialization.
The technique was invented by Bjarne Stroustrup, to deal with resource deallocation in C++.
[...]
RAII is vital in writing exception-safe C++ code: to release resources before permitting exceptions to propagate (in order to avoid resource leaks) one can write appropriate destructors once rather than dispersing and duplicating cleanup logic between exception handling blocks that may or may not be executed.
C++ is an object-oriented language with features like inheritance, encapsulation and polymorphism that is also found in popular languages like Java, C# etc. C++ also features generics via templates. However, in C++ you have to explicitely handle memory deallocation (ie. no garbage collection). This makes it very important to be able to release resources and deallocate memory in a controlled manner, and that is why I believe RAII is a very fundamental concept in C++. You will have a hard time understanding a "smart pointer" unless you understand RAII.
This is really an impossible to create list. Every place I work has a different acceptable subset of C++. So its going to be different depending on what you're developing on. I've seen C++ that truly is just C with occasional use of the "class keyword" to very run-time polymorphism oriented code to template meta-programming heavy code. Then the practices are going to change based on what frameworks/libraries/platforms you are targeting.
The best I could suggest is reading various coding standards and seeing the how they suggest you ought to write code using C++.
Google's Coding Standard
Sutter's Coding Standard Book
You learn and remember them by having a need for them. I'm not sure what sort of "features" you're looking for. "virtual functions" are definitely something you want to learn, but I don't really know your background. Should I be suggesting polymorphism/class inheritance too? Template classes/functions?
I think templates are such a feature...
Do you have a tool box containing too many tools? Then don't use them all? Use the ones you need.
Read a good book with C++ best practices and design patterns.
Don't be in too much of a rush to master a language. Peter Norvig (of Google) argues that it takes about 10 years to gain a mastery at anything.
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.