-
Notifications
You must be signed in to change notification settings - Fork 0
Style Guide
This style guide is currently under development. In time, and with input from Laurent, the goal is for this to become SFML's official style guide which contributors to SFML may use to know what programming style they must adopt in order for their code to be homogenous with SFML's code.
SFML uses CamelCase, where identifiers are formed from combining words, and the individually distinguished by their capitalization.
Capitalize the first letter of the first word, and for every word thereafter, capitalize the first letter of the word also. Example:
class InputStream;
class Event;
struct KeyEvent;
Member functions have the first letter of the first word lower case. This applies to both static and non-static member functions. Example:
Non-member functions follow the same conventions as member functions: the first letter of the first word is lower case. This applies to both publicly accessible non-member functions, as well as functions within an unnamed namespace. Example:
The enumeration type name is capitalized just like struct
s and class
es are. In some cases, the enumeration may be unnamed/anonymous. The values in the enumerator list are also capitalized just like struct
s and class
es.
Example:
enum
{
Count = 8,
ButtonCount = 32,
AxisCount = 8
};
enum Axis
{
X,
Y,
Z,
R,
U,
V,
PovX,
PovY
};
Acronyms and Abbreviations are treated as a single word, and as such all letters are lower case (except the first letter, which may be upper case or lower case depending on the identifier using the acronym or abbreviation). Example:
enum Axis
{
// ... from above
PovX, // Pov, not POV
PovY
};
class TcpSocket; // Tcp, not TCP
class IpAddress; // Ip, not IP
Macros are written ALL_CAPS with words separated by underscores. Example:
#ifndef SFML_CONFIG_HPP
#define SFML_CONFIG_HPP
#define SFML_VERSION_MAJOR 2
#define SFML_VERSION_MINOR 0
#endif
Namespaces are lower case and are as short as possible while still being obvious what they stand for. Example:
namespace sf // Namespace containing all of SFML
{
namespace priv // Namespace containing private implementation functionality for SFML
{
}
}
SFML uses 4 spaces for indentation, no tabs.
Align statements and expressions that form logical groups. Example:
enum
{
Count = 8, // Aligned at =
ButtonCount = 32,
AxisCount = 8
};
Access modifiers (public
, protected
, and private
) are dedented. Note that there is a space between the access modifier and the colon.
Example:
Braces are always on their own line. Example:
Remove trailing whitespace. This includes whitespace appearing on a blank line.
Each part of the public API is prefixed with a macro associating it with its module and properly exporting and importing the API symbols. These macros are: SFML_AUDIO_API
, SFML_GRAPHICS_API
, SFML_NETWORK_API
, SFML_SYSTEM_API
, and SFML_WINDOW_API
.
Example:
// From the Network module
class SFML_NETWORK_API IpAddress
{
}
SFML_NETWORK_API bool operator !=(const IpAddress& left, const IpAddress& right);