Planning the general structure of a C++ program
I'm very much a newbie at OO C++ programming, and I'm wondering if anyone has links to articles/guides/whatever discussing the initial planning of a C++/OO program, or some first-hand tips on doing so.
At the moment I just tend to dive right in without really thinking about the overall structure (classes, instances, class and header files, how objects exchange data, etc... everything really), and I end up with some fairly mixed results.
Usually I end up restructuring the whole program a few times before I'm happy with it, and I'm not too worried about it at the moment, but I think it would be better to develop some good practices before attempting anything larger.
Maybe it starts with drawing diagrams, or maybe just writing a list of objects... I don't know.
Any recommended reading?
Re: Planning the general structure of a C++ program
Hi, i'm "kind of" in a similar situation, i know C++, i learn Qt but the progress is not as fast as i wanted to be.
From my "experience" (learning experience) it isn't a book to teach you that (you should read many and practice, do exercises...), but i really recommend the C++ programming language written by Bjarne Stroustrup, it contains some chapters about design (i'm not at that chapters yet, so i can't say if i like it or not ;) )
Anyway, my opinion is that you should read many books, work with libraries that are known to be good (like Qt and Boost) and try to get a programming job, you will learn from experienced programmers (read/answer to forums might compensate a little bit, if you are in a similar situation like me :o and can't find a job)
Re: Planning the general structure of a C++ program
I don't think it's possible to write perfect code the first time. Code evolves through versions. Sure, I don't just throw code together and hope it works, but I don't spend 6 months doing diagrams either.
Generally I just sketch the way the app should work and how to code it, then decide which module I'm going to do first. Decide on how I'm going to do that, write it, and then move onto the next. You will usually want additional or modified functionality further down the line in one of your modules, but that's acceptable - you can't think of everything first and lock it in stone.
Unit tests are also good. You should be writing everything in reusable modules, so it shouldn't be difficult to write something simple to ensure those modules still work how you expect them to. It could easily saves hours of time searching for bugs that appeared versions ago and buried their heads and are now only showing up through other modules.
It isn't all about coding either, I think you need to use (and learn well) a decent version control application like Subversion(SVN) or GIT (I prefer the former), even if your the only author. They make life easier and save your bacon. Don't be tempted to just copy the odd version to another directory, or zip up the contents.
Re: Planning the general structure of a C++ program
Some experience I can share when dealing with complex projects (not only coding projects, but in general).
A lot of projects seem easy but are complex in nature. Complex doesn't mean it will be difficult but it needs attention.
I have always learned to study a problem first and think about how to split it up into managable parts.
Don't set your goal on the completion of the whole project. Set your goal on the completion of one milestone. This way you will be interested in the project much longer because you get a lot more rewards when working on it.
Re: Planning the general structure of a C++ program
I have the following books are excellent to learn from C++ How to Program Fourth Ed by Dietal .I did 14 chapters of this book. Another excellent book C++ Primer by Stanley Lippman 4th ed. I have not gone this book yet. It is even better than first book. For data structures get Data Structures Demystified by
James Keogh; Ken Davidson.