HACKING 4.07 KB
Newer Older
1 2 3 4 5 6
Since 1999, people have been hacking on Krita. Everyone brought their
own coding style, their own code conventions, their own likes and
dislikes. Me, (Boudewijn that is), I like indents of four spaces, and
no scope prefixes for variables. However, in the interests of
consistency, these are the rules new code should adhere to:

7 8
See also http://techbase.kde.org/Policies/Kdelibs_Coding_Style -- that document
is leading.
9

10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29
Qt vs STD vs Boost:

    In general, use the Qt classes wherever possible, even if someone tells you
    that the STD class is better or whatever. We're dealing with a big project
    with lots of developers here and we should keep the code as consistent and
    easy to grasp as possible. Since people need to know Qt in the first place,
    keep to Qt. Discuss deviations on #krita

C++11 and C++14

    Yes, but. Avoid lambdas. Avoid the new sig/slot connection syntax _unless_
    you are porting all of Krita to the new syntax. Sure, it has some advantages,
    but having two different ways of doing the same thing is begging for trouble
    and comprehension problems. For now, keep using foreach, we're using it all
    over the place. auto is fine, when using in for loops. Don't go overboard
    using it in other places. 

    Before using other new features, discuss on #krita so we can expand this list.


30 31
Indentation

32 33
	With four spaces. Use the default kdelibs indentation 
    (http://techbase.kde.org/Policies/Kdelibs_Coding_Style)
34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58

Includes

	Avoid as much as possible #includes in header files; use forward declarations
	of classes.

Initializers

	Avoid as much as possible initializers in the body of the constructor. Use
	initializer lists instead.

Scope prefixes

	Use only m_ for class-level variables. No other scope prefixes; no g_, l_,
	no 'p' for pointer variables.

Shared pointers

	Use shared pointers wherever possible.

Getter/setter

	Krita doesn't use Qt's properties -- yet. If you want to introduce use of
	properties, convert any and all classes in Krita before committing.

59
	Getter/setters are named 'x() for getters and setX(int x) for setters. If you
60 61 62 63 64
	come across violations of this rule, change the code.	

Class naming

	If you use a well-known design pattern, name the class according to the design
65 66
	pattern. All files should start with 'kis_', all classes with the 'Kis' prefix.
	In filenames, separate words with an underscore; in classnames use capital letters. 
Boudewijn Rempt's avatar
Boudewijn Rempt committed
67
    New implementation files end in .cpp, not in .cc anymore.
68
	Example: kis_new_class.h/KisNewClass.
69

70 71 72 73 74 75 76 77
Function naming

	Functions should be named in camelBackedFashion, to conform to Qt's standards.
	If you encounter functions in c_style_like_this, feel free to rename. Also:
	verbNoun -- i.e., rotateLayer, not layer_rotate. The latter is a true c-ism,
	introduced by a language that needs to prefix the 'class' name to every function
	in order to have something that not quite OO.

78 79 80 81 82
Variable/Parameter names

	Variable/parameter names start with an undercast letter. A name composed of different
	words is done in camelBackedStyle.

83 84
Designer

85 86 87
	Krita has started to use designer. All dialogs and all widgets that have a layout
	manager must be done in designer. We don't add code nor add signal/slot connections
	in designer
88 89 90 91 92 93 94

Enums

	All enums should be prefixed with 'enum'.

Namespaces

Boudewijn Rempt's avatar
Boudewijn Rempt committed
95
	Currently, we only use anonymous namespaces for things like undo
96 97
	commands. For the rest, some classes have a 'Kis' prefix, others don't. This should
	be made consistent, and we might want to use namespaces to keep all of Krita
Patrick Julien's avatar
Patrick Julien committed
98 99
	inside.

100 101 102 103 104
Files and classes

	It's preferred (and strongly preferred) to have only one class per .h/.cpp file.
	(Which is logical, because otherwise you won't be able to keep to the naming scheme.)

105 106
Spaces

Boudewijn Rempt's avatar
Boudewijn Rempt committed
107 108
	Keep the source airy and open. In particular, there should be empty lines between function
    declarations and definitions.
109 110 111

Slots and signals

112
	Prefix slots with slot and signals with sig: slotUpdateSelection, sigSelectionUpdated.
113

Boudewijn Rempt's avatar
Boudewijn Rempt committed
114 115 116 117 118 119 120
Boolean operators

    Use the standard !, !=, ==, && etc style, not the "not", "and" etc. style. Keep krita code
    using one, easily recognizable, C++ style.


Boudewijn Rempt