-
Notifications
You must be signed in to change notification settings - Fork 0
Cplusplus [the next step]
###1. C++ C++ is the main language used in Pandora. Good knowledge of the language's mechanics and syntax is a must. Developing in C++ and knowing how to write a program in C++ are two different skills, as C++ introduces objects as a code tool for state and flow organizing (http://en.wikipedia.org/wiki/Object-oriented_programming). As a result, object oriented programming skills are needed apart from structured programming skills (http://en.wikipedia.org/wiki/Structured_programming). It also includes generics (http://en.wikipedia.org/wiki/Generic_programming). A program takes full advantage of these features when it correctly uses coding techniques that replace structured programming paradigms with object oriented ones. These techniques are called software patterns (http://en.wikipedia.org/wiki/Software_design_pattern) and their usage helps the developer as it equally serves the program. Advantages and some techniques will be discussed in section 2.
To be able to use these techniques correctly and adopt an object oriented programming style, one must know the virtues and vices of C++ very well. A good tutorial to start studying is on this site: http://www.learncpp.com/ The writer analyzes some tricky issues of C++ in whole paragraphs so it is a good start. Taking care of these issues is important in order to write quality code. Some are being presented below:
-
Encapsulation: organization of data and program states into objects means that we hate global variables and there is a good reason for it.
- block statements and local variables
- global variables
- file scope and static things
- public and private things
- encapsulation
- stating friends (friend statement is a bad thing in general)
-
Const correctness: giving classes, objects or functions the correct permissions on data that they use according to what they are intended [by the programmer-writer or the programmer-user (if is to be used as an API)] to do with them (read-only or read-and-write ??). To understand this, is necessary to think what means for a function to have as an argument or return object a value, a pointer or a reference.
-
Type Casting: Safe type casting is a very powerful tool and can unlock some of the greatest tricks in C++, whereas unsafe type casting can unlock the greatest bugs.
- conversion and casting
- static cast !!
- dynamic cast !!
- const cast usually a bad thing
- reinterpret cast does whatever you like without warnings and with little constraints, useful when one wants to write low level code, but a curse for high level developing
Closing this chapter about C++, the reader must be accustomed with all attributes that consist C++. They must know its basics as well as all concepts about inheritance and templates. Finally they should check libraries that are offered to C++ developers in order to make their lives easier. The most basic are:
- STL which contains the most common data structures (vectors, lists, tuples, pairs, maps etc) in generic form and utilities upon them.
- Boost which is the bread and butter and headache for a modern C++ developer. It is the bread and butter because it delivers the most common things that a programmer needs in a generic way that C++ does not already have it by default (C++11 and on - among other things - are efforts to make canonical into the language most utilities offered by Boost). It is also the headache because of its bad documentation and not always so clear usage of its thingies. Among all Boost's goods you should take some time and read what function binding is (basically means objectifying functions!) and smart pointers. Smart pointers are pointers whose content is deleted when all users/keepers of the same pointer expire (meaning that there are no more active copies of the smart pointer object) or when you decide to do so. Thus, smart pointer objects provide C++ with a Java notion of a reference-object but without the complexes of the garbage collector system that sometimes arise. You are going to see both function-objects and pointer-objects very often so get used to them.