Debian Codegraph @

HACKING

raw
1 <braindump>
2
3 Howdy, interested contributor,
4
5 My name's Paul, and I've done some of the work designing and implementing this
6 particular bit of software. Since you're interested in hacking on this code,
7 I'd like to make a few things clear up front, so you don't end up hating me.
8
9 Perhaps you'll still end up hating me, but at least it'll be informed hate.
10
11 How it works
12 ============
13
14 OK, so this code is actually a pretty novel class-based state machine. The code
15 may look to some like it's too spread-out (e.g. using "include magic" to drive
16 the logic), and perhaps that critisism has some merit, but the code's here, and
17 it's very maintainable.
18
19 Why did I rebuild a state machine?
20
21 You know, it's a good question. I'd not mind re-considering this, provided that
22 the new implementation is better.
23
24 I don't see some of the other stuff maintainable or readable, so this was mostly
25 just a rejection of what I found. It's a CS101 topic, so I figured I'd be
26 able to implement something workable that's clean, clear and maintainable
27 without too much issue.
28
29 If you think this is wrong, email me and let me know why. I'm seriously
30 interested.
31
32 Alright, enough. So, how does it work?
33
34 The code processes a stream of bytes, one char at a time.
35
36 +-------+ +-------+ +---------+ +--------------+
37 | bytes | ----> | logic | ----> | machine | ----> | (some state) |
38 +-------+ +-------+ +---------+ +--------------+
39
40 This means (to be clear) under *no* situations I've seen so far will accessing
41 a state directly from the logic be OK. All state interactions must pass through
42 the machine, since we must not depend on a state by name in the logic. That
43 logic is defined in the states themselves.
44
45 State UML class diagram:
46
47 +---------------------------+
48 | state |
49 +---------------------------+
50 | +leave_state(void) : void |
51 | +enter_state(void) : void |
52 | +process(char) : void |
53 +---------------------------+
54
55 `leave_state` is called when process has returned a state other then the current
56 state. This is a chance for you to finalize the logic without
57 having sloppy process code.
58
59 `enter_state` is called when another state has triggered an entry to this state.
60 This is where you would init old data structures, etc.
61
62 `process` handle a char, and deal with as one should. By raising an
63 exception (incomplete_process), you can "redirect" the char.
64 By changing the "xdg_machine_next_state" pointer, you will
65 trigger the enter / leave functions.
66
67 Basic guideliens:
68
69 States must only be aware of states that it transitions to (not even where
70 it's transitioning from), and must only interact with those states by setting
71 the correct machine pointer.
72
73 The exception here is accessing another state's data structure. For instance,
74 in "value", we know that we must have only come from "key", and we really,
75 really need "key"'s data structure. In this case, using the symbols exported
76 in that state's .hh def is allowed. Try to keep this to a minimum, it makes
77 it very hard to keep some of it up to date, or swap out state implementations.
78
79 Current impl:
80
81 +-------------------------------------------------------------+
82 | |
83 | +------------------------------------+-----+ |
84 | v | | |
85 | (entry) ---- "#" ----> (comment) ---- "\n" | |
86 | | \ ^ \ | |
87 | | \ \ + ---- "[" ----> (group) ---- "]" ---+ |
88 | | \ \ \------------------ "\n" --+
89 | | \ +---------------------------------------- "\n" ------+
90 | | \ |
91 | | + ---- [anything else] ----> (key) ---- "=" ----> (value)
92 | "=" |
93 | | "\n"
94 | | |
95 +-> (invalid) <------------------------------|
96
97
98 Yes, I relize this is *VERY* messy. It's not really something that lends it's
99 self to ascii art. Just start at "entry" and work from there.
100
101 Code Style
102 ==========
103
104 My style is fairly straight forward. Just try to make code look like the rest
105 of the code. I know I sometimes violate my own rules, but the big stuff is
106 consistant. Try to maintain that, if you can. I'd be more then happy to help
107 give a bit of help if it's unclear.
108
109 |
110 | int f = 1;
111 | int longvar = 2;
112 | std::string bar = "baz";
113 |
114 | if ( f )
115 | baz();
116 |
117 | if ( foo == baz ) { /* This is a comment about this unclear bit
118 | of code, which should help with something */
119 | baz_foo();
120 | foo_baz();
121 | } else {
122 | groble();
123 | }
124 |
125
126 "XXX:", "TODO:" and "FIXME:" are all valid task tags. Please use these when you
127 find something in the code that's not critical, not really worth a bug, but
128 should be fixed at some point. I tend to use "XXX:".
129
130 Submitting code for review
131 ==========================
132
133 Gudelienes (I will always reject code because one of these is not right)
134 These are in no particular order.
135
136 (1): Write a helpful git changelog entry.
137
138 (2): Provide the code under terms compatable with the COPYRIGHT file. I prefer
139 Expat (since it's the license in the COPYRIGHT), but compatable licenses
140 are OK too.
141
142 (3): Add yourself to AUTHORS on the *FIRST* commit. This is for my protection
143 and records as well as being a nice way for contributors to see their
144 name in the project.
145
146 (4): Add yourself to the license header of each file you modify, along with
147 the date and a *valid* email. Do not change the license copyright block,
148 since the license you've choosen will be Expat compatable (see point 2),
149 since I'm not re-licensing my code.
150
151 (5): If you add a change to the binary's invocation or logic that the user is
152 exposed to, please note the change in the manual page.
153
154 (6): If you see you're out of date, please rebase rather then merge. It's a
155 few seconds of your time, and it helps keep the history clean.
156
157 (7): Use a valid email throughout all the copyrights, etc.
158
159 GitHub Pull Request
160 This method makes it really easy for me to keep track of incoming code in the
161 same tracker I use to maintain this project. As such, this is the way I
162 prefer to see code come in. Some advice (purely advice, this won't cause
163 me to kick code back)
164
165 - Consider using branches to help break features and bugfixes into easy
166 to review and merge blocks. If some pull requests "depend" on others,
167 that's OK. Just let me know, and I'll do the dependency resolution.
168
169 - File bugs early, if you mention you're working on a fix, I'll wait for
170 you to send your code in. I'd rather have a bug then not.
171
172 Format Patch Series
173 This method is 100% fine, as it's the way we do patches in Fluxbox it's self.
174 This may also be helpful if you're not using GitHub for reasons such as it's
175 status as a free software project. Some advice (only advice, I won't reject
176 code that breaks the following rules)
177
178 - Consider attaching format-patches as attachments to a "Hello!" email
179 where you describe what the series does, why it's something that's
180 important and any other feedback you have for me. If you decide to GPG
181 sign any of the mails, this is the one to do it on.
182
183 - If you don't care for the above advice, git-send-email works fine too.
184 Just make sure you have extra-descriptive commit messages.
185
186 General diff
187 I would rather not get a raw diff, but if you must, it's OK. With this,
188 please include your full name and email (or, rather, *a* full name & working
189 email) for me to commit the code as. If you'd rather not expose your email,
190 that's OK. Just let me know. I won't assume the mail address you sent me mail
191 with is that one that you'd like to make public (perhaps you use tags, public
192 accounts, etc), so I will ask if you don't include it.
193
194 Some additional (and more strictly enforced) tips:
195
196 - Be sure the patch applies aginst git head.
197 - Be sure the patch applies with -p1
198 - Unified diff, please (try passing -Nuarp to diff)
199
200 Some nice to do advice:
201
202 - Feel free to add email (or http) style headers to the top of a patch
203 to serve as a "commit message" (see the exampe[1])
204
205 - Most of the time, this *will* be more complex then using git. Think really
206 hard about using git format-patch. It makes it a little harder on me, and
207 much harder for you.
208
209 [1]:
210 From: Joe Hacker <[email protected]>
211 Subject: Adding in "this is a test" to foo1.
212
213 Adding in a little message :)
214
215 diff -Nuarp bar/foo1 foo/foo1
216 --- bar/foo1 1970-01-01 00:00:00.000000000 +0000
217 +++ foo/foo1 2012-03-16 02:07:12.131507334 +0000
218 @@ -0,0 +1 @@
219 +This is a test
220
221
222 Thanks for reading, and thanks for considering contributing to fbautostart.
223 Feel free to get in touch with me by email, irc, jabber, reddit, twitter,
224 identi.ca, github, launchpad, or any other protocol you might happen to find
225 me on.
226
227 Anyway, I know there's a lot here. Treat it like a ref-doc throughout
228 contributing to fbautostart.
229
230 Hope this helps,
231 -- Paul
232
233 </braindump>