Where can one find examples of masterful Ruby code?


#1

Hi

To start shortening the gap between myself - an average Ruby
programmer - and the top Ruby hackers out there, I’m looking for some
good Ruby code to read. They say you should learn from the masters, so
please tell me: who are those masters, and which of their works are
masterpieces?


#2

On 6/1/06, Alder G. removed_email_address@domain.invalid wrote:

To start shortening the gap between myself - an average Ruby
programmer - and the top Ruby hackers out there, I’m looking for some
good Ruby code to read. They say you should learn from the masters, so
please tell me: who are those masters, and which of their works are
masterpieces?

Rubyquiz.com has some very high quality code examples. The Best Of
Ruby Q. book is really good too.


#3

Hopefully you’ll get more helpful answers to this question from someone
a
little more knowledgable, but a few examples of fantastic code (although
often complicated) are the ruby library, rails, and ruby quiz. Ruby
Quiz
also has the added benefit of a discussion and breakdown of each week’s
program by James Edward G. II. Check it out here:
http://www.rubyquiz.com/

–Tyler


#4

Why the lucky stiff. Camping. Markaby. Cartoon foxes. I should read his
code
one day too.

Rails, too, amazing reflecting code. That’s ActiveRecord I’m talking
about.

Whytheluckystiff’s blog “redhanded” has many “masterful code”
spotlights, by
him and others. Check it out.

Time, if I only had a bit more of it…


#5

On 6/1/06, Tyler P. removed_email_address@domain.invalid wrote:

Hopefully you’ll get more helpful answers to this question from someone a
little more knowledgable, but a few examples of fantastic code (although
often complicated) are the ruby library, rails, and ruby quiz.

Being a Rails programmer, I tried reading some of Rails’ code and it
looks like you have to commit to reading a large portion of it to gain
any understanding. At least the core stuff that I sampled
(ActiveRecord, ActionPack) looks very tightly knit together. A guide
about approaching the Rails codebase might be very helpful, and
beneficial considering the importance of codebase accessibility in an
OSS project. Maybe I should raise this issue in the Rails ML.


#6

Alder G. wrote:

(ActiveRecord, ActionPack) looks very tightly knit together. A guide
about approaching the Rails codebase might be very helpful, and
beneficial considering the importance of codebase accessibility in an
OSS project. Maybe I should raise this issue in the Rails ML.

Semi-rhetorical questions: If you are not already well-versed in Ruby,
how do you know you are reading masterful code?

If you are reading masterful code, can one appreciate what makes it
masterful without a firm knowledge of Ruby?

Is the definition of “masterful” conditional? If so, on what?

James


James B.

“A principle or axiom is of no value without the rules for applying it.”

  • Len Bullard

#7

James B. wrote:

Alder G. wrote:

Semi-rhetorical questions: If you are not already well-versed in Ruby,
how do you know you are reading masterful code?

If you are reading masterful code, can one appreciate what makes it
masterful without a firm knowledge of Ruby?

Is the definition of “masterful” conditional? If so, on what?

Shut-up and just point us to the “masterful” code. :slight_smile:


#8

On 6/2/06, ReggW removed_email_address@domain.invalid wrote:
[snip]

Shut-up and just point us to the “masterful” code. :slight_smile:

Have a look at the ruby code distributed with the ruby.

If you are looking for a large scale masterful project consisting of
tons of files, then you will have to look elsewhere.


#9

On Thursday 01 June 2006 21:31, Alder G. wrote:

Hi

To start shortening the gap between myself - an average Ruby
programmer - and the top Ruby hackers out there, I’m looking for some
good Ruby code to read. They say you should learn from the masters, so
please tell me: who are those masters, and which of their works are
masterpieces?

On top of what others have suggested, I think eigenclass.org may provide
a lot
of what you are looking for. Also, the code browser on RAA (Gonzui):
http://raa.ruby-lang.org/gonzui/markup provides a very handy interface
for
browsing through random code. If you see a project you’ve heard about or
used, or one that just looks interesting why not look through?
Certainly, you
may not always be looking at great Ruby code, but I think you can learn
a lot
this way.

Hope this helps,
Alex


#10

2006/6/2, ReggW removed_email_address@domain.invalid:

James B. wrote:

Semi-rhetorical questions: If you are not already well-versed in Ruby,
how do you know you are reading masterful code?

If you are reading masterful code, can one appreciate what makes it
masterful without a firm knowledge of Ruby?

Is the definition of “masterful” conditional? If so, on what?

Shut-up and just point us to the “masterful” code. :slight_smile:

class Master
def ful() “code” end
end

Oh, sorry, it has to fit on one line of course:

class Master; def ful() “code” end end
:wink:

SCNR

robert


#11

On Fri, 2006-06-02 at 20:13 +0900, Robert K. wrote:

Shut-up and just point us to the “masterful” code. :slight_smile:

class Master
def ful() “code” end
end

Oh, sorry, it has to fit on one line of course:

class Master; def ful() “code” end end

Or, not quite equivalent:

def (Master=[]).ful() “code” end

:wink:


#12

On Fri, 2006-06-02 at 05:31 +0900, Alder G. wrote:

Hi

To start shortening the gap between myself - an average Ruby
programmer - and the top Ruby hackers out there, I’m looking for some
good Ruby code to read. They say you should learn from the masters, so
please tell me: who are those masters, and which of their works are
masterpieces?

As well as RubyQuiz and the other suggestions, I’d recommend looking
into Facets (http://facets.rubyforge.org). A lot of the people I
consider to be Ruby masters have written code either for that project,
or that’s found it’s way in there. An added bonus is: it’s lots of small
extensions (facets :)) so you don’t have to understand the whole to
understand the individual bits.

You might have to install it though, I couldn’t find any SCM links on
the project page…


#13

On 6/1/06, James B. removed_email_address@domain.invalid wrote:

any understanding. At least the core stuff that I sampled
If you are reading masterful code, can one appreciate what makes it
masterful without a firm knowledge of Ruby?

Is the definition of “masterful” conditional? If so, on what?

I think you might have your tongue in your cheek asking that last one,
but I’ll answer that it’s only masterful if it’s well documented. That
is: if other devs can’t jump in and easily behold your mastery, than
what sort of a master are you?

What good is pulling of a daring coup in your code if no one sees why
(or if it takes way too long to figure out how) you did it?

—John


#14

On 6/1/06, Alder G. removed_email_address@domain.invalid wrote:

I’m looking for some good Ruby code to read.

I don’t know about “masterful” but I’ve found plenty to learn from
these resources (They all have RSS feeds):
http://blog.grayproductions.net/
http://redhanded.hobix.com/
http://eigenclass.org/

HIH

C


#15

James B. removed_email_address@domain.invalid writes:

Semi-rhetorical questions: If you are not already well-versed in
Ruby, how do you know you are reading masterful code?

If you are reading masterful code, can one appreciate what makes it
masterful without a firm knowledge of Ruby?

I’d say that I’m pretty well-versed in Ruby. I have not yet seen much
masterful code. I’m not sure I could point out a medium-sized piece
of Ruby that’s truly and completely masterful. Sure, the “Quality
Without A Name” turns up here and there, but I just don’t find
something that is completely soaked with it. Maybe I just have too
high expectations. Prove me wrong, please.

Is the definition of “masterful” conditional? If so, on what?

Does masterful code get less and less the more you advance?
Does masterful code only exist in languages you don’t know that well?
(I somehow feel like there is plenty of masterful Haskell code out
there…)


#16

On 6/3/06, Christian N. removed_email_address@domain.invalid wrote:

of Ruby that’s truly and completely masterful. Sure, the "Quality

I’d say that this depends very much on your definition of “masterful”
code. In case it means, code that you’re not able yet to write, than
indeed, in time you will find less and less (hopefully :slight_smile: ). IMO
‘masterful’ code just means, nice, clean and following the best
practices of the language/domain addressed by that code. After about
10 years of Java, I can find ‘masterful’ code in a lot of places.

./alex

.w( the_mindstorm )p.


#17

Christian N. wrote:

I’d say that I’m pretty well-versed in Ruby. I have not yet seen much
masterful code. I’m not sure I could point out a medium-sized piece
of Ruby that’s truly and completely masterful. Sure, the “Quality
Without A Name” turns up here and there, but I just don’t find
something that is completely soaked with it. Maybe I just have too
high expectations. Prove me wrong, please.

The code I’ve seen that struck me as masterful (insert all the usual
caveats about judgment, qualifications, etc.) tended to be short, crisp,
and fairly easy to understand. Sometimes there was an “Ah ah!” moment
in grokking the code.

Most code, though, seems focused on getting a job done, which makes
perfect sense. So I don’t expect to find files filled with line after
line of masterful code; I think it more likely that the more skilled
Rubyists will write a collection of relatively short, clear methods that
make it easier to write the rest of the code needed to accomplish a
particular task. So most of the code appears, at first, quite mundane,
until you realize how much more mundane code would be required were it
not for these enabling methods.

There may be analogies to furniture making, where a piece may not strike
you as especially masterful until you poke around and see how the hidden
joints were constructed, and how they enable a design that in other,
less-skilled hands, would never be stable.

Is the definition of “masterful” conditional? If so, on what?

Does masterful code get less and less the more you advance?
Does masterful code only exist in languages you don’t know that well?
(I somehow feel like there is plenty of masterful Haskell code out
there…)

It may be like music, where the more one knows and the more one has
heard, the harder it is to get excited about new music (though when you
do find something good, it can be really exciting).


James B.

“I often work by avoidance.”

  • Brian Eno

#18

“Alexandru P.” removed_email_address@domain.invalid writes:

I’d say that this depends very much on your definition of “masterful”
code. In case it means, code that you’re not able yet to write, than
indeed, in time you will find less and less (hopefully :slight_smile: ). IMO
‘masterful’ code just means, nice, clean and following the best
practices of the language/domain addressed by that code. After about
10 years of Java, I can find ‘masterful’ code in a lot of places.

Oh. I just call that “good” code. It can be found rather easily,
especially in the Ruby community. :slight_smile:


#19

class Master; def ful() “code” end end

It’s not what it does right, it’s what it doesn’t do wrong.

(right?)


#20

On 6/3/06, James B. removed_email_address@domain.invalid wrote:

in grokking the code.
There may be analogies to furniture making, where a piece may not strike

Does masterful code get less and less the more you advance?

James B.

“I often work by avoidance.”

  • Brian Eno

Obviously, the adjective “masterful” is not well defined; I should
clarify what I meant.

“Masterful code” is a solution for a problem you wouldn’t be able to
solve by yourself, although it only requires knowledge you possess.
Such quality is easily idetifieable by the “aha!” moment you
experience upon encountering it. That “aha!” quality would be
intensified by first attempting to solve the problem yourself. Success
in this stage would also be accompanied by an “aha!” moment.

For example: check if integer i is a power of 2, with an expression no
more than 13 characters long.

Solution: (i & (i - 1))

Note that this solution is not only very concise, but also (on any
reasonable implementation) very fast. Masterful code has a tendency to
be “correct” in many ways.

In a sense I agree with your music analogy, though I believe masterful
code should be more prevalent than inspiring music. Chess would form a
closer analogy, and if no combination surprises you then your name
must be Bobby Fischer (but even he would manage to find opponents to
surprise him by searching the top circles).

You may argue that “masterful code” as such is independent of
langauge. You would be correct to conclude that. The above example
works, with little or no change, in many languages. I was asking for
masterful code in Ruby not because I’m using it, but because of the
reason which lead me to use it:

Ruby seems to encourage masterful code. It allows ideas to be
expressed directly. The other langauge I’d consider to encourage
masterful code is Scheme. But Ruby manages to offer many more tools
than Scheme. An elegant Ruby solution may rely on classes or regular
expressions. In fact Ruby seems to aspire to equip the programmer with
as many tools as possible. Which is a Good Thing. It thus may be the
best language (that I know) for the masterful progrmmer.

Out of the many suggestions raised in this thread, it seems that
following the Ruby Q. would be most appropriate. By such
participation much improvement might be gained. In such competitions,
the winning solutions are frequently required to be “masterful code”
according to the above definition.

Also it seems one should look into Ruby F.s, not merely because it
appears to be a gathering point for Ruby masters but also because it
looks damn useful.

And I should read the source of projects widely considered masterful,
written by programmers widely considered to be masters. Rails seems a
fitting candidate in that respect, being recommended on both accounts.