Principles of Qt code design.

Six Characteristics of Good APIs



An API is to the programmer what a GUI is to the end-user. The 'P' in API stands for "Programmer", not "Program", to highlight the fact that APIs are used by programmers, who are humans.

We believe APIs should be minimal and complete, have clear and simple semantics, be intuitive, be easy to memorize, and lead to readable code.

* Be minimal: A minimal API is one that has as few public members per class and as few classes as possible. This makes it easier to understand, remember, debug, and change the API.

Be complete: A complete API means the expected functionality should be there. This can conflict with keeping it minimal. Also, if a member function is in the wrong class, many potential users of the function won't find it.

* Have clear and simple semantics: As with other design work, you should apply the principle of least surprise. Make common tasks easy. Rare tasks should be possible but not the focus. Solve the specific problem; don't make the solution overly general when this is not needed. (For example, QMimeSourceFactory in Qt 3 could have been called QImageLoader and have a different API.)

* Be intuitive: As with anything else on a computer, an API should be intuitive. Different experience and background leads to different perceptions on what is intuitive and what isn't. An API is intuitive if a semi-experienced user gets away without reading the documentation, and if a programmer who doesn't know the API can understand code written using it.

* Be easy to memorize: To make the API easy to remember, choose a consistent and precise naming convention. Use recognizable patterns and concepts, and avoid abbreviations.

* Lead to readable code: Code is written once, but read (and debugged and changed) many times. Readable code may sometimes take longer to write, but saves time throughout the product's life cycle.



General Naming Rules

1.Class names begin with a capital letter: class Programmer.

2.Function names begin with a lowercase letter. char* getProgrammerDetails().

3.Constants and macros are capitalized, and also enum values in a class scope.

4.Boolean member functions: getters- isChecked() or isValid().

5.member functions: setter- setFont(const Font& newFont)





Indentation
 4 spaces are used for indentation.

Use QtCreator as your project IDE, QtCreator offers Auto Indentation (Ctrl+I) by selecting the total text.
The auto-indent format can be modified according to the need and convenience.

Launch QtCreator  Goto Tools->options->TextEditor->Behaviour

Namespaced Code

All forward declarations of types, functions and objects must be namespaced and must be "namespace qualified", i.e. written like below

QT_BEGIN_NAMESPACE

class QCheckBox;

class QComboBox;

QT_END_NAMESPACE

QT Do's And Dont's



Don’t use exceptions.
Don’t use rtti (Run-Time Type Information; i.e the typeinfo struct, the dynamic_cast or the typeid operators,)
Use static_cast, const_cast or reinterpret_cast.
Use templates with caution.
Do not inherit from template/tool classes.
The destructors are not virtual, leading to potential memory leaks.