3.1.  Style Guidelines, Naming Conventions

[ fromfile: style.xml id: style ]

C++ is a powerful language that supports many different programming styles. The coding style used in most Qt programs is not "pure" C++. Instead, it is common to see a combination of macros and preprocessor trickery to achieve a higher-level dynamic language that has a lot in common with Java and Python. In fact, to take full advantage of Qt's power and simplicity, we have abandoned the Standard Library entirely.

In any serious collaborative programming project there are likely to be style guidelines to improve the readability, reusability, maintainability, and reliability of the code produced. The semi-official Qt programming style guidelines are described in [qtapistyle] and [kdestyle]. Here is a summary of the style guidelines that we have adopted.

We have adopted a modified Hungarian notation for our data members, in which we use a common prefix so that data members are always clearly visible in the code:

For each attribute, we have naming conventions for their corresponding getters/setters.

A consistent naming convention greatly improves the readability and maintainability of a program.

Other Coding Standards

Following are some other coding standards that have been in widespread use. Keep in mind, the style most relevant to Qt programming is still [qtapistyle].



[35] The latter is Java style, the former is Qt style. Both conventions are widely used. Try to follow one convention consistently in your code. (We are not consistent in this book because we want to expose the reader to different conventions.)