What comes below is a [slightly modified] note developed by Sebastian Bosma, a DARSim graduate researcher, who managed to teach himself how to program in C++ in a very short period of time. We hope his experiences help all students who want to learn how to program in C++, which is a general-purpose object-oriented compilable programming language. It allows one (1) to run bigger problems in faster times (2) experience all complexities of an algorithm –especially for scalability tests–, and (3) get a feeling of CPU times and how efficient an algorithm can be. These help attract various potential users, especially if the algorithm is meant to solve a practical problem. Remember, one can only be a good programmer by doing it more and more. No amount of driving lessons would make you a good driver, unless you take a car and drive!
A few important notes before moving to Sebastian notes:
Many times students have problems with 'logic of programming' rather than learning how to translate their idea into a program (like C++ or Matlab). Therefore, please make sure you have studied some related topics on programming logic, and know how to break a big project into smaller interconnected tasks, etc.
C++ offers object oriented platform, where modules can be created to do small functionalities. This allows one to create 'class' to assign a specific task or rule with several members and functions in it, in a very abstract way
Sebastian Bosma, 21 February 2016:
For everyone that is planning to use C++ as a part of her/his thesis, here is a quick guide to how I got started. Hope it helps so that you can learn really efficiently. I should add a small note that since you're learning the language alone, it can be quite frustrating at times because progress can feel a bit slow. However this will pass quickly! As for the topics covered in this tutorial, please contact Hadi if you want a specific subject to be addressed.
1. Plan to learn C++
1.a) The new Boston C++ Tutorial : In my view, this is the essential first step. A tutorial consisting of 72 videos covering all the basics. Some things might not be useful to us and some things might seem trivial but I seriously recommend watching everything attentively. There are some subtle differences compared to Matlab which can save you a day or two of debugging. Trust me. Note that you may use different development environments instead of Code::Blocks which is used in Boston C++ videos (e.g., Eclipse, Kdevelop, Microsoft visual studio, ...). I’ve been using Eclipse and am quite pleased with it.
1.b) Just do it! - Write some code : As they say: learn by doing! After and during the tutorial make some of the files shown in the tutorial. This gets you accustomed to debugging and the Eclipse user interface. Start with something very simple, like some of the C++ templates you cover in the tutorial, then add more and more functionality to it.
A good idea is to ask for some code of the team you are working in. For the following reasons: 1) to understand common coding practice within your team. I recommend some focus on the use of classes, their constructors, memory allocation and the use of pointers. Those were most important for me. 2) c++ packages used in the code. There are quite a few add-ons which have pre-programmed functions which could significantly simplify your life. 3) Basic classes tailored to your problem available in the team. E.g. matrices or vectors. Likewise this can save a lot of time.
As a final exam for yourself, tackle a simple problem in your field. In my case this was a 2D pressure solver.
1.c) Meet the debugger: When you are comfortable with the basics ask a more experienced coder to explain the debugging run modes and debug interface of Eclipse. This will help you locate problems in the code more efficiently, especially once the code starts getting relatively large.
- A good code is optimized for scalability and is clean: In C++, due to its object-oriented framework, one breaks a big project into several smaller functions, structures, classes,... Many classes can be re-used for other projects and are therefore not necessarily tailored to a specific problem. Furthermore, one has to always remember that a code will evolve over time, both in terms of complexity of the problem it is aiming to solve (adding more physics or functionality for example) and the existing problem description (data structure, size of the domain, etc.). Thus, a good code is one that allows for extensions easily. At the same time, it is clean with several comprehensive 'comments'! This is crucial when you want to maintain your code for a long time or if several people are working on the same platform. So keep it 'scalable' and 'clean'.
-Google it! Although c++ reference sites are not as good as Matlab unfortunately, they do have examples here and there. Additionally, most questions have been answered on forums quite extensively. Along the way you'll get faster at finding what you need and understanding the explanations.
Good luck! And although it may be frustrating at times, it's very rewarding!