A
ara.t.howard
I meant that I believe it was Ara who recommended it as a good name
for an unused block parameter in Ruby.
i'll only take credit if beer is involved ... ;-)
-a
I meant that I believe it was Ara who recommended it as a good name
for an unused block parameter in Ruby.
Gosh, I think I totally disagree on readability grounds.
let's step back for one moment and think about why we all left perl:
%r|GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+)|x
let's step back for one moment and think about why we all left perl:
- wtf is $1 ?
- wtf is ARGF ?
- regexes are, of all things, the epitome of snoopy swearing
let's step back for one moment and think about why we all left perl:
- wtf is $1 ?
- wtf is ARGF ?
- regexes are, of all things, the epitome of snoopy swearing
i always consider using the magic $vars a sign of temporary perl
madness.
Looking at all those \d is kind of hard to parse also. I think the
following
way of expression that pattern is considerably clearer:
%r|GET /ongoing/When/\d{3}x/(\d{4}/\d{2}/\d{2}/[^ .]+)|x
Readability improves even more when Oniguruma allows for named
captures.
You just insulted all of my best friends in one go.
let's step back for one moment and think about why we all left perl:
Speak for yourself. I didn't leave Perl at all. I just added Ruby
to my
repertoire. I'm not sold on the idea that there's One True
Language, and
its name is Ruby. I use different languages for different purposes.
Some languages are generally good, and some are generally bad, but
many
languages are good for at least one thing in a way that other
languages
aren't -- and for that reason among others, I use both Perl and Ruby.
- wtf is $1 ?
- wtf is ARGF ?
- regexes are, of all things, the epitome of snoopy swearing
$1 is the first capture. Seems obvious to me.
ARGF is closely related to ARGV.
Regexen are extremely useful, and removing them from Ruby would be
a bit
like shooting it in the head.
i always consider using the magic $vars a sign of temporary perl
madness.
I always see it as a potential sign of greater maintainability (if
they're used well).
--
CCD CopyWrite Chad Perrin [ http://ccd.apotheon.org ]
John W. Russell: "People point. Sometimes that's just easier. They
also use
words. Sometimes that's just easier. For the same reasons that
pointing has
not made words obsolete, there will always be command lines."
i'll only take credit if beer is involved ... ;-)
It is hard to parse. That's why all RegExes should include a comment%r|GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+)|x
Looking at all those \d is kind of hard to parse also. I think the
following
way of expression that pattern is considerably clearer:
%r|GET /ongoing/When/\d{3}x/(\d{4}/\d{2}/\d{2}/[^ .]+)|x
Readability improves even more when Oniguruma allows for named
captures.
marcel
i've been writing oo-perl for many moons, setting $/ to slurp files
and all that... nevertheless the are features of ruby that attracted
to me it from the context of perl and continue to stand out when
selecting one of the two languages for a particular purpose. the
power of ruby is that of abstraction and cleanliness.
2007/7/10 said:I've also recently adopted the trick of using _ as an unused
parameter name. I believe it was Ara that first suggested this and I
think it's a great idea:
hash.sort_by { |key, _| =85 }=85
All else being equal, if I have call to write OO code, I'll always choose
Ruby over Perl. All else is not always equal, and sometimes OOP is not
the most effective approach to solving a problem, however.
Maybe it was Ara indeed, but the first reference I found on ruby-talk
was a post from Nikolai Weibull almost two years ago. See
ruby-talk:149793.
Hi --
Isn't that the same as:
hash.sort_by {|key,| ... }
(assuming one isn't going to make use of the value in _)?
Maybe it was Ara indeed, but the first reference I found on ruby-talk
was a post from Nikolai Weibull almost two years ago. See
ruby-talk:149793.
wrote:On Jul 10, 2007, at 08:27 , Christoffer Sawicki wrote:
Hello.
count.keys.sort_by{|key| count[key]}
IMHO, the most elegant way to do this is:
hash.sort_by { |k, v| v }.map { |k, v| k }
...where k =3D key and v =3D value.
Cheers,
Ack, pet peeve.
hash.sort_by { | key, value | value } .map { | key, value | key }
If you have to specify "where k =3D key and v =3D value" then these
should have been used in your code.
Always favor readability at the expense of verbosity, both your
future self and whoever else maintains your code will thank you.
I find myself always using |k,v|, when used on something hashlike I
don't think readability suffers.
I've also recently adopted the trick of using _ as an unused =20
parameter name. I believe it was Ara that first suggested this and =20=
That is something very nice to sayWell 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."
Robert--alex
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.