Main  /  Edit version 1  /  Edit version 2  /   /  Users Area

Difference "CppCMS Coding Standard" ver. 1 versus ver. 2

Content:

## Coding Style
- **Indentation:** --- K&R only.
- **Naming:** use small\_letters\_and\_underscore. Such names are much more
readable. Same namging convention for class names, variables and functions.
NeverUseUglyAndUnreadableCamelCasedCode. _Rationale_ -- readability.
Prefer to use STL conventions. For example, for cleanup operations use `clear()`, for finding something "find()" and
so on.
- **Polish/Hungarian notations** are not in CppCMS. No prefixes or suffixes like `iNumber` or `m_some_class_member`, no boost style underscore suffixes for member variables like this\_is\_my\_cool\_member\_with\_underscore\_ should be used.
- **Variable Names:** --- variables like `i`, `j`, `tmp` are perfrectly well to use inside functions, in loops.
It is ok to use `def`, `tmp` perfixes and suffixes for member variables when they meaning something.
_Rationale:_ Linux Kernel Coding Style.
- **Tab Stops** --- Tab is 8, not 4, not 2 and defenatly not 5! Tab width=8 is like Pi=3.1415926535. Do not use something
- **Tab Stops** --- Tab is 8, not 4, not 2 and defiantly not 5! Tab width=8 is like Pi=3.1415926535. Do not use something
else. This is most compatible over different editors, it is standard, it should be used anywhere. It makes code more
readable at 1:00am.
Do not replace tabs with spaces, all indentation should be done with tabs.
_Rationale:_ Linux Kernel Coding Style
- **Preprocessor Macros** --- should be CAPITAL\_CASED\_WITH\_UNDERSCORES. Always add `CPPCMS_` prefix to them.
## General Coding Notes
### Exceptions
All code you write should be exception safe. Only functions that you may assume they never thow exceptions are POSIX API or 3rd party C libraries like libgcrypy or sqlite3. Even STL may throw exception. Assume that std::bad\_alloc may be thrown and handle it correctly.
All code you write should be exception safe. Only functions that you may assume they never throw exceptions are POSIX API or 3rd party C libraries like libgcrypy or sqlite3. Even STL may throw exception. Assume that std::bad\_alloc may be thrown and handle it correctly.
Thus:
- Always use std::auto\_ptr or boost::shared\_ptr when shared semtantics is needed. Always prefer auto\_ptr over shared\_ptr because:
- Always use std::auto\_ptr or boost::shared\_ptr when shared semantics is needed. Always prefer auto\_ptr over shared\_ptr because:
1. It is faster and does not include refcounting overheads
1. It is faster and does not include ref-counting overheads
2. shared\_ptr can be always created from auto\_ptr but not in other direction.
3. It has move semantics that covers our requirements in most of cases:
For example
- When using C API that does not supports destructors, put your code inside try-catch block and cleanup everything.
auto_ptr<my_class> my_func()
{
auto_ptr<my_class> instance(new my_class);
instance->do_something();
return instance;
}
- When using C API, that does not have destructors, put your code inside try-catch block and cleanup everything.
- If you use C API in more then one place consider wrapping it with simple class or at least provide scoped destructor. See as an example posix\_mutex.h or fcntl\_mutex.h

About

CppCMS is a web development framework for performance demanding applications.

Support This Project

SourceForge.net Logo

Поддержать проект

CppCMS needs You


Navigation

Main Page


Valid CSS | Valid XHTML 1.0