One thing I really like about Java compared to PHP is that there’s an
official coding standard. This is because I don’t really mind which
standard
I use, I just want to be told what to do and have the highest likelihood
that other code I encounter in that language will use a standard that
I’m
used to.
Bearing that in mind… I’m starting to learn Ruby and noticed there
doesn’t
appear to be an official coding standard, nor for Rails. This document
basically claims to be a de facto standard, is that true The Unofficial Ruby Usage Guide? If so I will follow
their conventions. Or is there a better resource? Is the community
fairly
consistent in their coding style? I find the Java community is fairly
consistent, the PHP community rather the opposite.
Well they are more or less same, we used to have our own set of
conventions
on par with other existing scripting languages. This to ensure all the
code-base is in sync
the positive path thru a method, and demote the negative or failing
path. Make
the failing path low or to the right, and run the positive path down
along the
left."
Can you clarify this? I don’t quite understand, but it looks intriguing.
One thing I really like about Java compared to PHP is that there’s an
official coding standard.
If the Official Coding Standard just… jumped off a cliff, would you?
Bearing that in mind… I’m starting to learn Ruby and noticed there
doesn’t appear to be an official coding standard, nor for Rails. This
document basically claims to be a de facto standard, is that true The Unofficial Ruby Usage Guide? If so I will follow
their conventions. Or is there a better resource? Is the community
fairly consistent in their coding style? I find the Java community is
fairly consistent, the PHP community rather the opposite.
Ruby is supported by a real community, not a corporate oligarchy. We
have no
motive to pay some flunky to write up a document full of our leaders’
whims and
proclivities. Yet our coding standard really does exist - it is the
amalgam of
our best literature. For example:
2 spaces for indentation
under_bar not CamelCase
omit unused keywords, such as return
omit top-level parens
the closer to correct English grammar the better
do-end on multi-line blocks
{} on blocks followed by .methods
cram everything onto one line (then wrap it funkily)
You will notice that not all of our standards make sense. Making them
official
would only exacerbate this problem.
Ruby’s incredibly rich syntax powers our style. For example, the
operators ‘or’
and ‘and’ associate more loosely than ‘=’, so we can write:
match.xpath('*').each do |child|
issue = match_nodes(child, node) and
return issue
end
That notation looks unfamiliar, and it saves a couple of lines - without
cramming. It also obeys the perfectly universal coding standard, “Always
promote
the positive path thru a method, and demote the negative or failing
path. Make
the failing path low or to the right, and run the positive path down
along the
left.”
The Official Java Standard doubtless enforced that too…
Hi,
I
'm rather new to Ruby, but most of what it mentions seems similar to
what
I’ve seen so far.
The only thing I question is that it says always to include the
parentheses
around parameter lists. I tend to do the very opposite, only including
parentheses when absolutely necessary. I think Phlip said something
similar?
Unless I totally misunderstood.
So I guess that’s my question to everyone else: do you include
parenthesis
around arguments or not?
The only thing I question is that it says always to include the parentheses
around parameter lists. I tend to do the very opposite, only including
parentheses when absolutely necessary. I think Phlip said something similar?
Unless I totally misunderstood.
Omit the top-level parens. You need the rest, to disambiguate.
As for that document claiming to be the “de facto” standard on Rails
coding style? I think that is just the author’s default coding style.
What definitely turned me off this book, was the chapter about fixtures.
There are some suggestions on coding style which may help to clarify
what you are looking for. It’s a highly-recommended book by many in
the Rails community. Plus, since the author Obie F. is an ex-
Java dev, it’s also a good book for folks coming to Ruby/Rails from
other languages like Java.
As for that document claiming to be the “de facto” standard on Rails
coding style? I think that is just the author’s default coding style.
Some of that stuff is just a bit too much. Phlip’s suggestions on
methods and the 2-space indentation are really the only standards that
I am aware of. Other than that, have fun and love your code. That’s
what Rails is about.
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.