I've been reading about C++ and working with classes and pointers, but now I need to know where to go from here (if it's GUI then it's gonna have to be Qt because it seems the best).
Start a personal project that requires the use of all the things that you have learned. You will soon learn where you need to improve.
Find some example code for a bare-bones Hello World application using the UI framework you want to use (QT). Learning how to code in a graphical/windows UI is often as hard as learning the language itself.
Experience.
That's really the best teacher-- until you've experienced a need for a particular aspect of the language, you won't know what it's for.
For instance, templates. I never understood what templates were for, or why I would ever need them, or why someone would bother. To top it off, the visual studio 6 compiler handled templates really badly, so templating seemed like a good way to make life really difficult for myself.
Then I ran into a number of different image types. Grayscale images with 8, 12, 16 bit depths, color images with RGB or HSV encoding, float-based images, etc etc. And I was writing a lot of code to handle each one. Then I realized what templates were for, and my code got a lot cleaner.
There's no real way to predict what you're going to need to be 'better', it's more about solving problems. And you don't know what problems to solve until you try to do them, and realize the skill you need to fix the problem.
Pick a significant open source project which has enough participants that your contributions will get reviewed. It should be one that is internationally recognised, use modern techniques like templates, formal bug tracking and a build system (adding to your education in that area).
Fix bugs. You will learn more about the language by fixing bugs within the context of a large body of work than you will studying in the abstract.
I suggest you strongly consider Boost: There are many ways to become part of the Boost developer community, all starting with getting involved in the development discussion. But if you are looking for an "easy" place to get your feet wet is to voluteer testing resources.
Effective C++, and/or More Effective C++ would make you aware of many pitfalls.
Here's a few generic suggestions:
- Work closely with a more experienced C++ developer.
- Read some of the wacky books about template metaprogramming in C++.
- Write a lot of C++ code, either for work or for fun.
Really though, this is a super-generic question. I have no idea what you want to do with programming in general, but presumably you're learning it for something. Get some sort of hobby project and run with it in C++. Translate an old project into C++. Write your own spam filter. Whatever you do, do something.
Apart from some other good advices, my take on this is, try learning a functional programming such as F# or Haskell, once you have fall in love with one, you will come to be a better C++ programmer. You will start to incorporate some of the styles in C++ (And no, you won't abandon C++). You will start writing C++ codes that can be easily multi-threaded with minimal locking/synchronization, because you will learn to avoid global variables and to write functions that are side-effect free (as much as possible). You will write C++ codes that are less buggy because you will prefer the use of immutable variables.
The more you code the better you will get. Code for fun and for money.
Start solving problems with C++ (or any other language) to learn more about what can be done with the language and what libraries is available to help with the heavy lifting. Solving problems you haven't dealt with before increases your skill. Churning out the same old code everyday will decrease your ability to use a language to its fullest potential.
Something like problems Project Euler or International Olympiad in Informatics (See websites at bottom of page) can help you practice.
Also read some books on design patterns to learn how to recognize and solve common problems that occur regularly in software. Try and find the patterns in your previous solutions to problems when you re encounter a similar problem. A good pattern book is Head First Design Patterns
It really depends on what you want to do. Here are some things that can be learned in any order: writing your own templates, design pattern concepts, exception handling, OpenGL.
Actually it sounds like you need a project to apply some coding to. You can try Open source projects. I don't know if school is a possibility but many computer science courses would involve C++ assignments and group projects. So you can could get programming experience, some computer science concept work and school credit.
If you want to become a better C++ programmer write a lot of contrived examples and learn the limitations of the language, particularly when it comes to multiple and circular inheritance (yes' it's possible to really mess yourself up and the compiler sometimes doesn't even warn you). Example: assume the following code sample is in a .cpp file. Will it a. compile? b. run? Why?
class Foo {
public:
Foo(int i) : m_i(i) {};
private:
static int m_i;
};
int main(int argc, char** argv) {
Foo myFoo(0);
return 0;
}
If you want to learn Qt think of it like a whole other language. The Trolls were goodly enough to abstract and reimplement everything you could possibly think of. They've got strings, data structures, network code, data storage, compression, etc. Everything in Qt is all wrapped tightly in Qt.
Qt is also event driven - so get used to the idea of asynchronous event driven programs. No more busy waits or selects. Ask for data from a network socket and the call returns straight away. You'll can go off and keep crunching and will be alerted when data is available. A lot of the time you'll write an event handler in a derived class but you'll never call it directly - the Trolls were goodly enough to call it for you. If you've come from a GUI background you should be familiar there; most GUI toolkits are event driven even if they use raw callbacks in C. Qt just extends it to everything.
If you want to become gold at C++ programming, get familiar with the STL and Boost. Everything you want to do data structure-wise is in those two. Data storage, reordering, computations, etc are all covered.
If you do aim to do any GUI programming, I suggest gtkmm if you really want a good C++ API. It more depends on what platform you're aiming to develop on: if KDE, you want Qt; if any other GTK WM/DE, gtkmm of course; if Windows, any of the above (I know there's a GTK port, so I assume there's a gtkmm port).
Minimize use of 'set/get' functions. Remember that in C++ (or any other OO language), writing a 'set/get' function for a member variable is an indirect violation of 'encapsulation'.
In my experience, my coding and design imporved when I started to question the need of set/get functions in classes. Obviously you cannot eliminate all set/get functions. But questioning the need of a particular set/get, exposed lot of unneccessary code and improved the encapsulation and eliminating such set/gets resulted in flexible code.
Learn much, much practice, know more than one language.
Remember, you learn a language in 24 hours, but learn how to program, it takes time.
Read this also:
Teach Yourself Programming in Ten Years
- Read "The C++ Programming Language" by Bjarne Stroustrup.
- Look at Boost Libraries.
- Start with small projects using Boost libraries.
Write a lot of code. As much as you can, and branch out into different areas. You can find books and tutorials on your own, and those are great, but the real world experiences are the ones that stick with you the longest.
Have you read Meyer's two books, Effective C++ and More Effective C++? After 7 or 8 years you may know a lot of their content already, but they're a useful list of about 85 mistakes to avoid using C++.
Also, have you read Stroustrup's C++ Programming Language? I found it good to read after Meyer's books: it's big so it fills in little details that you won't have read previously, and, gives you ideas of how he imagined people would want to be using C++, and why therefore C++ is designed as it is.
Regarding rules to follow - check the Google C++ style guide. I think it's a reasonable set of rules that reduce complexity of C++ without reducing too much of its power. It proved to be working well for a large group of very good programmers.
I always find it helpful to actually read a lot of code that gurus that you mentioned write, pick up their 'tricks' and then use them as much as possible. Reviewing open source code is also quite helpful, especially if you have a open source project that partially(or fully) address similar problems that you have to deal with.
All answers thus far are great examples of ways to get started. I would add that looking through some open source programs to see how other experienced programmers are implementing projects with C++ would be worth your while.
Join and/or start your own open source project which uses C++. Your co-developers and users in your project will challenge you to become a better programmer.
Learn a different language.
Only after I learned about lambdas in python did I become interested in the ideas of method pointers, boost::lambda and the upcoming c++0x lambdas.
A fresh and different perspective can make you think about how to do things differently within the languages you already think you know.
I'd offer you advice on thinking positive and not listening to what other people say, but I dont think this is the answer you'r looking for so I'm telling you:
- Forget everything that you think may lead you into a pitfall.
- Review lots of code written by clever people and try to fully understand and embrace it.
- Do a lot of exercises by writing "hard" code (code you previously thought was hard and puzzled) found in books and such.
- while(true) { Read, read, read; Write, write, write; Understand, understand, understand; }
I would agree with everyone else read, read, and read some more. Oh yeah, and write lots of code. I often feel left out because I haven't embraced template programming to the level that Alexandrescu and the others have. I just assume that I haven't found a need for that level of complexity though.
As for the STL, there are two must read references: the original SGI STL documents and The C++ Standard Library: A Tutorial and Reference. Read the tutorial and refer to the SGI documents regularly. They will enhance your understanding of the C++ Standard Library dramatically.
I'm surprised that Herb Sutter's Exceptional C++ series hasn't made the list thus far. These two books did more for my understanding of exception handling issues more than anything else. They are also excellent at explaining a number of the dusty corners of the language. If you haven't read through the Guru of the Week archive, then I recommend that you visit it for a good sample of the sort of detail that Mr. Sutter delves into.
The last thing to glance at in your spare time is Marshall Cline's C++ FAQ Lite. This is a fun thing to read over during lunch or when you are waiting for something to build. By the time that you manage to make it through this list, you should feel quite comfortable with RAII, exception handling, and the STL at the very least.
OK, men, you need to read a lot of book and code. of course, you need write more.
In my exp(although I only have 3 year exp), language is not important(at last not that important), the key point is, whether or not you are familiar with the OS,CPU,Software Engineering,language philosophy,the detail of implement.
So I suggetst you to read this books(if you not have them done):
I suggest you read the code from sourceforge.net , there are lots of good code there.
15 year exp... We all have a long road to walk..
ps: the suggestion others post are more objective, take them.
Reading books and writing code are of course two excellent ways of learning the trade. Reading code and writing books are two more things :) It doesn't have to be anything big, it could be a simple blog about your findings.
There's always someone else that can benefit from it. Teaching someone is a very nice tool to advance your own thoughts and ideas.
Cheers !
Other than learning a new language as suggested in another answer, I'd read some of the classics. I haven't yet (just bought my first one: Pragmatic Programmer), but I made a list based off this SO thread:
What is the single most influential book every programmer should read?
I made a list in pretty much the same order as by upvotes on that thread, except I started with Pragmatic Programmer since it is shorter.
EDIT: This probably does not make you a better C++ per se, but definitely a better programmer in general, which will translate to your C++ code.
I've found that there are few substitutes for the draft standard. It's not very interesting for idle reading, but C++ is a large and complex language. When you've got a specific problem, and you're stuck trying to figure out why the compiler is doing something or other, it can be of great benefit to actually look up the details of how it's supposed to work. It's hard to get that from other resources.
Read a lot of code. From what I understand, you already have written lots of code so what you need is learn how other people think in C++. Read code that was written by really smart people that solves some real-world problem (like open-source projects).
Think about, if you're writer, do you need to read? Stephen King, in "On Writing" says that a good writer absolutely must read a lot. Programming isn't all that different.
Read James Coplien: Advanced C++.
If you haven't been exposed to other language styles then it'll teach you to mimic the styles of other languages in C++.
It may get you thinking differently
Coming from a C background myself, I have two advices for you:
I think you should look into how object oriented programming is done in ANSI C. That's right. It is possible to do it. These are actually the roots of C++. Check out OOC, which as an awk program written by Axel T. Schreiner. It is incredibly well documented and the documentation will give you an insight into how you can use object oriented concepts in plain ANSI C. After reading the documentation, I think you will gain a better appreciation for how things are actually working under the hood.
The advice above won't help you with templates and other more sophisticated aspects of the language. For that, I think your best choice is to learn from the Gurus. Using the Boost libraries is already a good start as it will give you an insight on how its developers have solved certain problems. Better yet, the Boost libraries are open source. So you can peep into the code and learn from it.
Cheers
A lot of good books have been mentioned, but what also helped me a lot was to read the questions on comp.lang.c++.moderated, see if I could answer them, and then read the answers (usually from experts in the field) and see how close I came. When I could answer correctly, I knew I was getting better.
Of course, nowadays, you'd read SO. :)
Reading professional blogs helped me to learn some new techniques. I've been programming for money for about 10 years. And I've read almost all C++ related books. Every day's a school day still.
C++ has the added bonus that it allows you to program in any style you choose. As a result it is usually possible to solve problems in 3, 4 or 100 different ways.
My recommendation therefore is, when you are confronted with a problem that you believe you have a solution for, then stop and try to think how it might be solved using a different style.
For example if polymorphism will solve your problem, then why not try to use templates to come up with a solution that uses "compile time polymorphism".
Books and coding styles are invaluable, but I find it's easier to really comprehend their meaning when I'm applying what they teach in real code.
Finally, don't be shy of using 3rd party libraries. IMHO, boost and QT provide the missing pieces that C++ lacked (in comparison to say Java) as well as removing a lot of the low level pain such as memory management etc.
Don't just learn another language, learn about what makes those other languages special. I hate to use the term paradigm, but that's exactly what you need: a shift in paradigm. Learn about functional programming in scheme or haskell or ML. Learn about 'logic' programming via prolog. Learn about building massively scalable apps in erlang. Learn about clojures and lambdas and actors and type systems. And then take those ideas and see how they apply back to your work in C++ and C# by revisiting old code (like code you wrote 7 or 8 years ago). What would you do different, and more importantly WHY? Then try to imagine how you would re-write that code in another ten years, and why.
Here is how: Look to the master, Follow the master, Walk with the master, See through the master, Become the master.