openSUSE talk:Ruby coding conventions
Indentation
Strings
Why not use parentheses for multi-line strings instead of pluses? I find this style a lot more readable. vim and emacs can also auto-indent it like this when they find parentheses.
script = ("#!/bin/sh\n"
"rm -rf /\n"
"echo 'Surprised?'")
Current style convention:
script = "#!/bin/sh\n" + "rm -rf /\n" + "echo 'Surprised?'"
EDIT: This doesn't work. Tried it in ruby 1.8.7. However, You could something like this:
script = ( "#!/bin/sh\n" + "rm -rf /\n" + "echo 'Surprised?'" )
Methods
The same things goes for method calls. Why not use:
foo(bar, baz,
qux, quux)
instead of:
foo(bar, baz, qux, quux)
Consider a somewhat extreme example:
Current style:
long_method_name_with_many_arguments(big_argument="a lot of text that goes here",
another_big_argument="with a lot more text here. "+
"This is more text and then more and more text", short_arg="foo",
bar="faz", faz="bar")
something_else
a_different(thing)
Proposed style:
looooong_method_name(big_argument="a lot of text that goes here",
another_big_argument="with a lot more text here. "+
"This is more text and then "+
"more and more text",
short_arg="foo", bar="faz", faz="bar")
something_else
a_different(thing)
EDIT: Both of them hurt my eyes. Besides the fact, that one should rethink the need of writing a method with that many arguments, that have a fallback string that long, here is how it would look like, if you'd indent it nicely:
looooong_method_name(
big_argument = "a lot of text that goes here",
another_big_argument = (
"with a lot more text here. " +
"This is more text and then " +
"more and more text"
),
short_arg = "foo",
bar = "faz",
faz = "bar"
)
Strings
The more I write code with double quotes around each String, the more I hate the looks of it. Single quotes result in a much cleaner look. Is it just me or could we (please) change this rule?
Proposal: Use single quotes unless you need the double quotes for interpolation.