1While the spotify-qt code style is mostly inconsistent, it tries to follow
2the style of Qt. spotify-qt-lib however, is trying to have a code style more
3similar to the standard C++ library. It's mostly based of
4[povilasb/style-guides](https://github.com/povilasb/style-guides/blob/master/cpp.rst).
5
6### Formatting
7* 80 character lines.
8* Indent with tabs, 4 space width.
9* Unix LF line endings (\n).
10* Brackets are always on a new line.
11
12### Namespaces
13Namespaces are in all lower-case with underscore separators. Usually very short.
14```c++
15namespace lib
16{
17	// spt instead of spotify
18	namespace spt
19	{
20			// ...
21	}
22}
23```
24
25### Classes
26```c++
27class album_track: public track
28{
29public:
30	// explicit for constructors with a single argument
31	explicit album_track(const std::string &id);
32
33protected:
34	// ...
35
36private:
37	// ...
38};
39```
40
41### Enums
42Same style for both `enum` and `enum class`. The last line ends with a comma.
43```c++
44enum class log_type
45{
46	// enum classes don't use any prefix
47	information,
48	warning,
49	error,
50};
51
52enum log_type
53{
54	// enums use a simplified version of the name of the enum
55	log_information,
56	log_warning,
57	log_error,
58};
59```
60
61### If/else
62Brackets are always used, and is always on a new line.
63```c++
64if (true)
65{
66	do_something();
67}
68
69if (true)
70{
71	something_with_a_long_name()
72		.do_something_with_it();
73}
74```
75
76### Other stuff
77```c++
78try
79{
80	// ...
81}
82catch (const std::exception &e)
83{
84	// ...
85}
86
87switch (0)
88{
89	case 0:
90		break;
91
92	case 1:
93		break;
94
95	default:
96		return;
97}
98```
99
100## Naming
101
102### Files
103Header files use .hpp extension and source files use .cpp extension. Files
104are named after the class, enum, etc. containing it without any spaces.
105
106`artisttrack.hpp`:
107```c++
108class artist_track
109{
110	// ...
111};
112```
113
114### Fields
115Fields are lower-case with underscores. Getters and/or setters are prefixed
116using `get_` or `set_`. Avoid setters having the same parameter name as the
117property itself, as that will create a naming conflict.
118```c++
119class track
120{
121public:
122	void load_something();
123
124	void set_id(const std::string &value)
125	{
126		// Usually defined in source file
127		id = value;
128	}
129
130	std::string get_id()
131	{
132		return id;
133	}
134
135private:
136	std::string id;
137};
138```
139