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 Quiz 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 Facets, 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.
···
On 6/3/06, James Britt <james_b@neurogami.com> wrote:
Christian Neukirchen wrote:
> James Britt <james_b@neurogami.com> 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.
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 Britt
"I often work by avoidance."
- Brian Eno
--
-Alder