In order to keep the source code readable and clean we use a number of coding conventions. Before sending a patch for inclusion in the Nitro source code tree, please make sure that you follow the conventions.
General
Try to keep the source code lines less than 64 chars length. However, do not get out of your way to enforce the constraint. One or two longer lines here and there are ok.
Identation
Please don’t use tabs. Use 2 spaces for identation.
Comments
Leave one blank line after your comment line.
Reference-example
This aims to be an universal example for good source code (to be extended as need arises…) ((a nitro-specific example would be better… maybe i will add one later))
# This is a comment about the following class.
class
Foo
attr_accessor
:foo
,
:bar
# A small comment about what #foo does.
def
foo(x, y = 1)
out = ""
y.times { | t | out << "printing #{y} times _#{x}_\n" }
return out
end
# bar has absolutly no use i could think of, that is why it has
# this awesome creative name :)
# examples:
# bar([1,2,4,6], 1)
# => [1, 2, 4, 6, 13]
# bar([1,2,4,6], 3)
# => [1, 2, 4, 6, 13, 26, 52]
# bar([1,2,4,6], 6)
# => [1, 2, 4, 6, 13, 26, 52, 104, 208, 416]
def
bar(x, y = 2)
y.times { |i | out << x.inject {|sum, n| sum += n } }
end
end
More conventions
- Blocks use { } if its a one liner, otherwise use do...end
- Surround equal signs with spaces, @myvar = ‘foo’, not @myvar=’foo’
- Surround hash assignments with spaces, :foo => ‘bar’, not :foo=>‘bar’
- Class.method(my_arg)—not method( my_arg ) or method my_arg
- Follow the conventions you see used in the source already.

Updated by ~gmosx on 2006-01-30 18:42:30, 0 archived revisions, diff.
