~ubuntu-branches/ubuntu/maverick/yokadi/maverick

« back to all changes in this revision

Viewing changes to doc/hacking.markdown

  • Committer: Bazaar Package Importer
  • Author(s): Harald Sitter
  • Date: 2009-07-19 13:01:35 UTC
  • Revision ID: james.westby@ubuntu.com-20090719130135-eonczddb1s21ux1v
Tags: upstream-0.10.0
ImportĀ upstreamĀ versionĀ 0.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Coding style
 
2
 
 
3
## Naming
 
4
 
 
5
Classes use CamelCase. Functions use mixedCase. Here is an example:
 
6
 
 
7
    class MyClass(object):
 
8
        def myMethod(self, arg1, arg2):
 
9
            pass
 
10
 
 
11
 
 
12
        def anotherMethod(self, arg1, *args, **kwargs):
 
13
            pass
 
14
 
 
15
(Why? Because `someLongAndPowerfulMethod` takes less horizontal space than
 
16
`some_long_and_powerful_method`.)
 
17
 
 
18
Exception: Classes which implement command methods should use underscores,
 
19
since the name of the method is used to create the name of the command:
 
20
 
 
21
    class MyCmd(object):
 
22
        def do_t_cmd1(self, line):
 
23
            pass
 
24
 
 
25
 
 
26
        def parser_t_cmd1(self):
 
27
            return SomeParser
 
28
 
 
29
 
 
30
        def someMethod(self):
 
31
            pass
 
32
 
 
33
Filenames are lowercase. If they contain a class they should match the name of
 
34
the class they contain.
 
35
 
 
36
Internal functions and methods should be prefixed with `_`.
 
37
 
 
38
## Spacing
 
39
 
 
40
Indentation is 4 spaces.
 
41
 
 
42
Try to keep two blank lines between functions.
 
43
 
 
44
One space before and after operators, except in optional arguments.
 
45
 
 
46
    a = 12
 
47
    if a > 14 or a == 15:
 
48
        print a
 
49
 
 
50
    myFunction(a, verbose=True)
 
51
 
 
52
## Import
 
53
 
 
54
Use one import per line:
 
55
 
 
56
    import os
 
57
    import sys
 
58
 
 
59
Avoid polluting the local namespace with `from module import function`.
 
60
 
 
61
Good:
 
62
 
 
63
    import os
 
64
    os.listdir(x)
 
65
 
 
66
Bad:
 
67
 
 
68
    from os import listdir
 
69
    listdir(x)
 
70
 
 
71
You should however import classes like this:
 
72
 
 
73
    from module import SomeClass
 
74
 
 
75
Keep import in blocks, in this order:
 
76
 
 
77
1. Standard Python modules
 
78
2. Third-party modules
 
79
3. Yokadi modules
 
80
 
 
81
Keep import blocks sorted. It makes it easier to check if an import line is
 
82
already there.
 
83
 
 
84
# Command docstrings
 
85
 
 
86
All commands are documented either through their parser or using the command
 
87
docstring. To ensure consistency all usage string should follow the same
 
88
guidelines.
 
89
 
 
90
For example assuming your command is named `t_my_command`, which accepts a few
 
91
options, two mandatory arguments (a task id and a search text) and an optional
 
92
filename argument. The usage string should look like this:
 
93
 
 
94
    t_my_command [options] <id> <search_text> [<filename>]
 
95
 
 
96
No need to detail the options in the usage string, they will be listed by the
 
97
parser below the usage string.
 
98
 
 
99
# Database schema changes
 
100
 
 
101
If you want to modify the database schema (adding, removing, changing tables or
 
102
fields). You should:
 
103
 
 
104
- Present the changes on the mailing-list
 
105
 
 
106
- Implement your changes in db.py
 
107
 
 
108
- Increase the database version number
 
109
 
 
110
- Write an update script in update/
 
111
 
 
112
- Assuming the current version is x and your new version is x+1, you should tag
 
113
  the last commit *before* your changes as "db-vx".
 
114
  This way one can checkout the latest version of Yokadi before your changes,
 
115
  create a database version x and test your update script.
 
116
  The correct way to create the tag is:
 
117
 
 
118
        # Note the -a!
 
119
        git tag -a db-vx
 
120
        git push --tags
 
121
 
 
122
<!-- vim: set ts=4 sw=4 et: -->