Beautiful Code : Pity he didn't ask here

Well i for one am feeling pretty good that i learned Ruby here and not
from a textbook.

Anyway, nice work. Editors are probably wishing they would have gone
with “Cute Code” or “Decent-Looking Code.”

–alex

On 7/11/07, alex_land [email protected] wrote:

Well i for one am feeling pretty good that i learned Ruby here and not
from a textbook.

That is something very nice to say :slight_smile:

Anyway, nice work. Editors are probably wishing they would have gone
with “Cute Code” or “Decent-Looking Code.”

It is indeed a very ambitious title, the Ruby chapter is very
disappointing but the author pointed out it was for beginners (sic).
For me that makes no sense :frowning:

Oh BTW please do not top post, a huge majority of us prefer bottom
posting :slight_smile:

–alex

Robert

On Tue, 10 Jul 2007, Tim B. wrote:

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 F.'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 C. Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : [email protected]
New Zealand

On Jul 11, 2007, at 6:18 PM, Tom C. wrote:

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 Z.
– Lead Rails Evangelist
[email protected]
– Engine Y., Serious Rails Hosting
– (866) 518-YARD (9273)

On Thu, 2007-07-12 at 08:11 +0900, John C. wrote:

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 F.
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 :slight_smile:

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

On Jul 11, 2007, at 7:30 PM, Tom C. wrote:

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

yeah! i’m always on the lookout for code that runs slow but reads
great - just my style :wink:

-a

On Thu, 2007-07-12 at 10:25 +0900, Ezra Z. wrote:

it’s very nice but performance wise it stinks.
Ah, cool, OK, thanks for the heads up!

Yours,

Tom

On Thu, Jul 12, 2007 at 11:38:00AM +0900, ara.t.howard wrote:

On Jul 11, 2007, at 7:30 PM, Tom C. wrote:

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

yeah! i’m always on the lookout for code that runs slow but reads
great - just my style :wink:

I predict the following code will appear in a codeforpeople example
soon.

some_ara.map(&:fortytwo)

enjoy,

-jeremy>

On 7/12/07, Jeremy H. [email protected] wrote:

I predict the following code will appear in a codeforpeople example
soon.

some_ara.map(&:fortytwo)

Got you finally!!!,
It as all your fault, 42 (or :fourtytwo ) is a mystery constant.
That has to change

ANSWER_TO_THE_QUESTION_ABOUT_THE_MEANING_OF_LIFE_THE_UNIVERSE_AND_EVERYTHING
= 42

It might be a good idea to include the ISBN of the “Hitchhikers Guide
through the Galaxy” into the constant too.

Robert

Martin DeMello wrote:

On 7/12/07, Jeremy H. [email protected] wrote:

I predict the following code will appear in a codeforpeople example
soon.

some_ara.map(&:fortytwo)

That’s definitely one route towards intestinal fortytwod :slight_smile:

That pun was despicable and pernicious, and I am disappointed in you…
for having thought of it before I did.

Hal

On 7/12/07, Jeremy H. [email protected] wrote:

I predict the following code will appear in a codeforpeople example
soon.

some_ara.map(&:fortytwo)

That’s definitely one route towards intestinal fortytwod :slight_smile:

martin

John C. [email protected] writes:

ARGF.read.scan( %r{GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+) }) do |match|
puts $1
end

Kinda late to the party, but I’m amazed noone came up with:

ARGF.grep(%r{GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+) }) {
puts $1
}