state-of-the-art C++ projects - c++

I like to go through existing software projects as a source of learning and new ideas.
doing so I discover things that I did not think were possible
in your opinion, what is the top state of the art C++ project that you have used/develop/extended? can you state reasons why you consider it state of the art and what you can learn from it.
my latest craze is boost::phoenix, http://www.boost.org/doc/libs/1_43_0/libs/spirit/phoenix/doc/html/index.html, which is very comprehensive functional programming library.
Despite its capabilities it is straightforward and easy to extend. After some tweaking I was able to write multithreaded lambda parallel loops and mathematical domain specific language, probably within 2 weeks.
What is yours? (please do not just say boost, as it is huge collection of project)

Personally, I like to look at code in Qt. I do use it everyday, but it seems like every day I use it, I find something new. In terms of total code, it is probably as big as boost. But it comes with excellent documentation and examples and complete source code and is free for LPGL & GPL versions.
For me, what I liked about Qt was that it's concepts matched the way C# works, so it was a fairly easy transition back into c++ for me. But by looking at their code, it has really given me many ways (although not as many as SO) to understand some of the complexity in C++

From what I've seen, the code-sources that I have learned the most from have been from fairly complex 3rd party software libraries. Havok is an excellent example from which I've not only learned programming practices and solutions, but also quite a few mathematical and philosophical discussions. I've also seen some other code-sources which have not been open sourced from which I've learned how to not solve things.
Game engines for AAA-titles in general tend to involve a lot of complex code that tries to push as much as possible through a piece of hardware. I guess that the recommendation goes for all software that tries to achieve something similar but I've only dived into game engines when it comes to such software. AAA-titled game engines often have good or bad solutions to study and I would generally recommend looking into those. There are some that are open source... I think Source/Valve have released theirs in different stages.

Related

How to learn C++ for the purposes of debugging

Some background: My job involves maintaining a large multi-threaded multi-process C++ / C# application, and so I'm often tasked with understanding access violations, memory leaks, heap curruption issues and the like.
I quite enjoy this, and I've amassed quite a good understanding of various low level concepts, but the trouble is that I don't program in C++, and aside for the purposes of maintenance I don't really intend to.
What I mean by that is that if I ever need to develop something then at the company I work at the best choice is C# (more developers, other apps also in C# means better interops), so its not that I don't program in C++, it's just that whenever I do program in C++ it will be purely for the purpose of learning C++, and so I want to get the most out of it.
My view is that "Teach yourself C++" books and the like aren't very suitable as they focus too much on getting things done - there are usually many ways of doing things and so they tend to pick one method, so when I'm presented with some code that does things a different way I'm stuffed (e.g. a book teaches MFC, I then get presented with some ATL code and the book hasn't even taught me what ATL and MFC are, let alone how to recognise that what I'm looking at is different!)
I'm really looking for teach yourself C++, with the emphasis on understanding other peoples code.
IMHO C++ in particular is a language that you cannot learn by reading a "teach yourself" book, you really need to have several sources and one of these is actually to look at other people's code.
I would recommend reading Effective C++ and More Effective C++ by Scott Meyers to learn some of the pitfalls when programming in C++, it is a good way to learn especially when you are looking at people's code. Another site than can help is gotw as well, some excellent information is there as well.
Since you'll never be creating C++ programs from scratch, I recommend you narrow your vision and just look at the applications you will be supporting, concentrating on the things you do not fully understand and tackling them one-by-one.
I find http://www.parashift.com/c++-faq-lite/ to be a good basic resource for C++. When dealing with specific technologies like MFC or ATL, do some research beforehand on which book(s) will suit you best. My favorite method: a strong coffee, a comfy chair and a pile of candidate books at Barnes & Noble to review. Focused on-line searching will suffice as well.
There are no shortcuts to knowledge and mastery, but by limiting your focus you can save yourself some wasted effort. Generally speaking, the more complex the technology--or the more fundamental the design screw up--the more you need to know to fix it. It's the facts of life!
The C++ FAQ is a great source of information.
Despite others' answers, I don't think your problems will lie mainly with the language. Sure, you can look at the standard or Stroustrup, but these will only teach you language constructs.
Most of what you will have trouble learning, I imagine, will be windows-specific and whateverplatformyouareusing-specific.
Do read stroustrup and other language guides, but be prepared to delve into the docs for the libraries and systems you are using.
It sounds like you really need a copy of the C++ standard. (ISO/IEC 14882 - available in draft form for free online. the final version costs a few bucks)
Of course, Stroustrup's book would be a good choice too. But in general, focus on material that describes the language, rather than, as you say, "how to get things done".
If you're having to maintain C++ code that uses MFC and/or ATL to a large degree then the best way to learn how it works so that you are able to properly maintain the code is to write small applications that use MFC and/or ATL so that you get an understanding of hwta is going on when the code is run. Reading a book by Stroustrup will not help you in any way to understand MFC and/or ATL. The other thing you should probably be focusing on is how COM works since ATL is basically a framework of templates, macros, etc that makes using COM easier.
Hope that helps.

Need sample problems for hands-on

I have been working with C++ for a few years now and have got good theoretical knowledge on the matter (I think).
However I've been missing involvement in good projects, sort of projects that really gets one going on the technologies.
So I intend to work on my own to get some good grip on C++ and related technologies.
'Have started with a sample projects such as designing and coding a telephone directory.
Please suggest similar projects/problems that test knowledge about C++ , all aspects of the language such as using STL containers/algorithms, polymorphism, as well as designing (design patterns).
Check out this link to test you c/c++ skills and really tough stuff.
http://www.tenouk.com/cpluspluscompetitioncontest.html
Book on Data Structures, Algorithms, And Applications In C++ by Sartaj Sahni
has really challenging problems sets and you will enjoy it.
Project Euler is a large collection of mathematical problems, most of which are most effectively solved by writing small programs.
Doing these will not expose you to the whole technological breadth of C++ but could be part of a self-study program around algorithms, performance, logic and of course mathematics.
Code katas!
Modular progressively more difficult sets of questions that allow a gradual introduction into the more esoteric uses of the language. Various sites have their own question sets.
Parashift C++ FAQs are useful, and so is the C++ idioms wiki - they offer a more overall shaping of design - concentrating on efficiency and correctness.

learning c++ from boost library source code

I am very interested in c++ and want to master this language. I have read a lot of books about c++. I want to read some library source code to improve my skill, but when I read the boost library source code, I find it is very difficulty.
Can anyone give me some advice about how to read boost source code and before I can understand it what kind of books about c++ should I read?
If you're starting out in C++, the boost source code is probably not the best place. It's where the wizards hang out and they deal in template magic. I think a better starting point are Scott Myers and Herb Sutters books (in that order).
Some versions of Scott's book can be a bit out dated but they are still strong in the fundamentals. Herb's books are worth reading many many times and are an invaluable tool. Once you've gotten through both of those authors, then would be a good time to tackle the boost source code.
Scott Myers: Effective C++
Scott Myers: Effective STL
Herb Sutter - Really I would go for anything with Effective and C++ in the title from this list.
I can't give advice on how to read boost code, but I can offer some other advice.
Stop reading and start writing :) Reading is valuable, but you won't learn anywhere near as much unless you start writing code yourself. Start with the basics. Read the beginners books and type out the samples (don't copy and paste). You'll learn by having to fix the errors that are the result of you mistyping. Play with some of your own ideas for simple applications and go from there.
Starting off by reading boost source code is a sure fire way of scaring yourself off the language and/or ending up very confused with a lot of questions.
Start small, work your way up.
Since you mention that you want to learn the dark art of meta programming then I would recommend "Modern C++ Design" by Andrei Alexandrescu.
Meta programming is a very complicated area and is not required most of the time. Once you learn about it, it is very easy to think that it can solve all your problems. It becomes your new favourite hammer.
I would also recommend becoming a very proficient user of libraries based on meta programming like boost and loki before you add it to your own code.
Two different programmers used meta programming in parts of the code base I am responsible for. While they were skilled programmers a commercial product should not be treated like a playground. These are probably the worst area's of our code base now, very complicated and very brittle esp when you add support for new compilers. If I was responsible for the code when they were written they would not be here, now they are too expensive to replace.
In short you very rarely need meta programming unless you are a library writer. And you cannot be a library writer without being a very accomplished library user.
I imagine boost uses a lot of advanced c++ features like templating etc. Boost libraries tend to be very complicated as they try to follow strict programming standards and styles for them to be compatible with things like the STL.
Quite simply, if you don't understand it, you are probably in over your head. and if you do understand it, you don't really need to be reading it anyway. Don't jump into the water if you don't know how to swim... You've essentially tried to swim up a waterfall.
Yeah, there is some truly awful stuff in some of the boost libraries. If you want to read some very nice source code, try checking out WebKit or some of the Google open source projects (like Chrome or Protobufs).
Id suggest you start off with something like Lipmann's Premiere(other begginers books of
your liking). Then, when you're comfortable with the code, you can move on to Herb Sutter,
Alexandresku to broaden your horizons, acquire a more complete view on the soft dev. And
MOST IMPORTANTLY - to be able to cede well one has to code A LOT, as it is a skill just as
any other and it takes practice to master.
P.S.> If you're confident you can pick up Stroustrup right from the start along with other
book(s). I don't think that theres another source on C++ just as complete as the authors.
For learning anything, i mean, there's a principle which is very important. To fill the belly we have to learn how to cook, to chase a girl we have to learn how to flirt with, to resist the beast we have to learn how to make fire. So finally we find that we learn and master a thing in the process of solving a specific problem.
In my perspective, it's best to learn and master the c++ language with diving into a specific problem waiting for solving. You analyse it, stick with it, try it, many times, with facing various difficulties, and solve it, finally, and bravo. With the delight of success you will find that the C++ language has been conquered, by you.

learn and practice c++

I'm trying to learn c++ and I really want to do a lot of coding but I'm not sure what I can code.. Tbh, book exercises are not very interesting to me (usually because they're just too short). I like to code OS related stuff like I/O stuff..
I'm thinking of looking at linux and try mimicking some of the tools there.. is that a good idea?
Rewriting tools is a good idea - my C++ professor made us rewrite all the standard library string functions by hand before we were allowed to use them in our homework assignments so that is something that may help you as well. You could also check out Project Euler.
Here's a good task that involves I/O, has interesting algorithm, is not too simple, not too difficult, and can even have practical application:
Write a simple compressor / decompressor.
Simple ideas to start with: LZW, Huffman codes.
I write stuff I'm interested in ... games for example. Poker games or blackjack games. I also take existing libraries and see if I can make better versions of their stuff, like try and make a QuickSort that outperforms the Framework version. Some day I will write a chess game, but that will take some time. :)
Write a language! Make C# compile to Sparc V9 assembly (just kidding.) But seriously, I think, writing a small compiler that produces actual machine code is one of the greatest ways to learn a great deal about software and hardware (and operating systems, and libraries, etc. etc.) and pick up lots of useful skills along the way. Here's the The Dragon to get you started :)
You can try getting involved in some open-source projects if you are wanting to write code. If you find a project that has some use to you personally, it is going to greatly increase your interest levels and decrease the likelihood that you'll get bored with it and move on to something else. Plus you'll be able to get some feedback from other developers on the same project.
Try TopCoder. They're competition applet has hundreds of example programming problems. Some of them are sure to be more interesting than the exercises in the books, and you have the added bonus of seeing how your problem solving abilities measure up to other users.

Practical and advanced C++ usage

I've studied C++ as a college course. And I have been working on it for last three years. So I kinda have a fairly good idea what is it about. But I believe to know a language is quite different from using it to full potential. My current job doesn't allow me to explore much.
I have seen you guys suggest studying a open source project and perhaps contributing to one too. So my question is, can you suggest one(of both?) to start with that is simple and doesn't overwhelm a starter.
I was in the same situation 12 years ago when I got my first programming job out of college. I didn't do any open source but I managed to gain a lot of practical and advanced C++ knowledge by reading books (the dead tree kind).
In particular, there was an excellent series by Scott Meyers which I feel helped the most in turning me from newbie to professional:
Effective C++: 55 Specific Ways to Improve Your Programs and Designs
More Effective C++: 35 New Ways to Improve Your Programs and Designs
Effective STL: 50 Specific Ways to Improve Your Use of the Standard Template Library
The topics in these books range from beginner to advanced. It took me about 2 years working in C++ to understand every chapter in these books, so don't be disheartened if it goes over your head at some point... just try reading it again later :)
If you're willing to climb the very steep learning curve, I would think that you could do worse than studying parts of the boost libraries. I don't think there is another similar body of C++ code out there that is pushing the boundaries of what can be done in C++.
re project selection: you'll want to hack on something that has some relevance to you, otherwise it's just unpaid work. i might suggest eg. Pure, but will you find enough interest?
re advanced code: see Boost
Obviously learning something like this does not happen overnight; You can study existing open-source projects like other posters suggested. However, I have one more suggestion: I suggest joining one of the big IRC c++ channels (for example #c++ on efnet or freenode). Of course most of the questions / discussions going there are basic; however quite often interesting discussions and questions come up. Over the several years I've learned quite a bit just by participating in channel discussions.
My main advice would be that you do not need to stick to C++ to learn technique.. Study Erlang, Lua, and Haskell (lots of others). You will learn so much from these language that you can apply in C++.
Google protocol buffers is a very well written C++ application that sticks to the features of C++ that are proven in the industry -- i.e., they don't go over the top with features that cause headaches for using the code.
In terms of learning to use C++ to its full potential, well the full potential is often hidden. There are very few exceptional C++ programmers, even in the open-source community. So I suggest you read some books. Like the books from Scot Myers and Herb Sutter (all 6 of em).
Boost is an amazing library and has a lot of good code, ranging from simple techniques to very advanced techniques. It definitely touches all of the bleeding edge of C++ idioms. The problem with boost is, it doesn't work well with modern IDE features (code-completion being the main problem), and it has a LOT of symbols :D. It is the place to learn about generic programming and template meta-programming, the former represents the most advanced and immediately-usable idioms, and the latter you can skip for the immediate future.
Apart from the Scott Meyers books DSO has already suggested: Participate on SO and try to answer other people's C++ questions. If you don't know the answer, wait a little until some good answers are posted. You will probably get some idea where the gaps in your knowledge are and you could do some more reading to fill those afterwards.