C++ Coding Techniques and Principles
Contents |
← Back to MySQL University main page
[edit] C++ Coding Techniques and Principles
- Date (MySQL internal): 2007-08-30
- Date (at the Heidelberg Developers Meeting): 2007-09-21
- Date (public online presentation): 2008-02-07
- Presenter: Mats Kindahl and Jim Starkey
- Scribe (at the Heidelberg Developers Meeting): Peter Lavin
- Scribe (public presentation): Jon Stephens
- Attendees (please register by filling in your name below, and read the Instructions for Attendees):
- Alexander Nozdrin
- Hakan Kuecuekyilmaz
- Jay Pipes
- ...
[edit] Presentation
[edit] Recommended reading
- Listmania list "C++ Programming Essentials" on Amazon
[edit] Questions at Web Presentation
[edit] Questions asked before the session
- None yet
[edit] Questions asked during the session
- None yet
[edit] Questions at Heidelberg
[edit] Questions asked before the session
- None
[edit] Questions asked during the session
Question:What are circular includes?
- An include file that includes a file already included. One header should never include another header -- except in exceptional circumstances. Include the header file in the source file. Use forward declarations instead of includes.
Question: Why include your own header files first?
- If you do not do this the code may break -- don't force dependencies on other users. The header file should be self-sufficient in the sense that it should not have dependencies forced on any file using it. If a source file containing just an include statement compiles cleanly (i.e., the source file containing just
#include "my_header.h"), you are not forcing any dependencies on any user of the header file.
Question: How can you have inheritance if virtual functions are private?
- It is a common misconception that in order to be able to override a virtual function, it has to be accessible, i.e., non-private. However, there is nothing preventing a subclass to override private virtual function.
Question: Doesn't this break your definition of a interface?
- Basically no. Much discussion -- see the video. The critical point is being able to change your code. [Sergei]In the code we changed public virtual functions to private virtual functions.
[edit] Remarks
- Jim, Mats: Learn to think in objects.
- Jim: C++ is a very bad language. Do not use all the features of C++, for what you should use look at Java and note what was left out.
- Mats: Define your own constructor, copy constructor, assignment operator, destructor because otherwise you'll get one for free and it won't work. If you don't want the class to be copyable or assignable, declare the corresponding functions as private in the class.
- Mats: Compilers ignore the inline keyword since they are usually better at deciding when a function should be inlined.
[edit] Voice recording and other links
- [Voice Recording] (.ogg file, ~7MB)
- [IRC log] (text file, ~4KB)
- Other resources: See last page of presentation
