Beautiful Code : Pity he didn't ask here...

J

John Carter

I personally think that the reason Ruby will enjoy an ever
increasing market share in the programming-languages space is
because it's more readable.
snip<
Gosh, I think I totally disagree on readability grounds.

I perfectly agree with you.

Yet, I find my use of Ruby has changed on that front.

At first I wrote Ruby that was, I thought, in a most readable style.

What I realized later was, it was most readable to someone who knew
C++ well, but not Ruby.

But now I have found I'm headed more to Hal Fulton's attitude as expressed
in his book "The Ruby Way"
http://rubyhacker.com/coralbook/

I try to write the most readable code that is most readable by someone
who knows Ruby perfectly well.

If, on the rare occasions that requires deep knowledge of Ruby... I
will explain that in the comment, not the code.

ie. My code assumes you know everything about Ruby. My comments assume
that you are a newbie.

Now that places a conundrum before someone writing a book "Beautiful
Code" for non-Ruby readers. Talk down to them? Speak a C++/Java/Ruby
pidgin?

Personally I would speak up to them. Scan the libraries for the best
code Rubiest have to offer in the Ruby idiom.... and spend my time
explaining the elegance, power and succinctness of it.


John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : (e-mail address removed)
New Zealand
 
T

Tom Copeland

I try to write the most readable code that is most readable by someone
who knows Ruby perfectly well.

Right on. Today Rich Kilmer showed me some Rails code that Chad Fowler
had written. It was something like:

some_array.map(&:name)

where some_array was filled with objects that had a name attribute, and
Rails reopened Symbol and added to_proc.

At first I thought "oh, that's ridiculous". Five minutes later I
thought "hm, that's rather nice". Five minutes later I agreed with Rich
that it was very clever and we would start using it everywhere :)
Personally I would speak up to them. Scan the libraries for the best
code Rubiest have to offer in the Ruby idiom.... and spend my time
explaining the elegance, power and succinctness of it.

Well said!

Yours,

Tom
 
E

Ezra Zygmuntowicz

Right on. Today Rich Kilmer showed me some Rails code that Chad
Fowler
had written. It was something like:

some_array.map(&:name)

Careful with that one Tom. It's *a lot* slower then writing out the
block since creating a Proc object has some overhead. Syntactically
it's very nice but performance wise it stinks.


Cheers-
-- Ezra Zygmuntowicz
-- Lead Rails Evangelist
-- (e-mail address removed)
-- Engine Yard, Serious Rails Hosting
-- (866) 518-YARD (9273)
 
T

Tom Copeland

Careful with that one Tom. It's *a lot* slower then writing out the
block since creating a Proc object has some overhead. Syntactically
it's very nice but performance wise it stinks.

Ah, cool, OK, thanks for the heads up!

Yours,

Tom
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,773
Messages
2,569,594
Members
45,119
Latest member
IrmaNorcro
Top