S
SB
I definitely agree that you could probably stumble along by learning
just one way but you'll be left in the wilderness looking at someone
else's code. At least that's how I feel right now.
Ruby's versatility is like English. You can speak English with a very
heavy Spanish accent or German accent and even your grammar could be
heavily influenced but it will still be valid English nonetheless. To
stretch the metaphor further two non-native English speakers coming
from different languages usually have trouble understanding each
other's English.
I still wish there were more books out there on Ruby and Rails.=20
That'll will change drastically in 2006. I'm sure our more
experienced rubyists would benefit from a Ruby Pocket Reference
(actually available in Japanese from Oreilly).
How long did it take most of you to feel comfortable enough in Ruby to
understand other people's code as well?
just one way but you'll be left in the wilderness looking at someone
else's code. At least that's how I feel right now.
Ruby's versatility is like English. You can speak English with a very
heavy Spanish accent or German accent and even your grammar could be
heavily influenced but it will still be valid English nonetheless. To
stretch the metaphor further two non-native English speakers coming
from different languages usually have trouble understanding each
other's English.
I still wish there were more books out there on Ruby and Rails.=20
That'll will change drastically in 2006. I'm sure our more
experienced rubyists would benefit from a Ruby Pocket Reference
(actually available in Japanese from Oreilly).
How long did it take most of you to feel comfortable enough in Ruby to
understand other people's code as well?
ral date: 1/19/2006 9:10 PM) :##: (e-mail address removed) changed the world a bit at a time by saying (ast=
i couldn't disagree more. names, for variables or methods, are of utmo= st
importance to better expresses intention:
puts 'this makes sense even without knowing what set is!' if set.mem= ber? 42
puts 'this is requires a comment' if s.has_key? 42
With all due respect, I would say these tricks are used _after_ you maste= r the API.
The discussion (as far as i got it) was about leaning it (so _before_ mas= tering the API). And having
6 methods with different names is kind of confusing while learning. You a= re loosing a lot of time
trying to identify if there are any differences between them.
I agree with you that after mastering the API these may become handy.
cheers,
./alex
--
.w( the_mindstorm )p.
ps: I guess this is pretty much in the idea of a series of blog posts tha= t happen lately about human
interfaces vs good APIs vs ... (iirc the start was somewhere on Martin Fo= wler's blog)
That may be the best example. Here are some others.
Enumerable:
collect =3D map
entries =3D to_a
detect =3D find
member? =3D include?
find_all =3D select
p signals.detect{|sig| sig.freq > 42}
p list.find{|x| x.freq > 42}
Hash:
store =3D []=3D
merge! =3D update
has_value? =3D value?
Integer:
next =3D succ
IO:
pos =3D tell
Kernel:
fail =3D raise
format =3D sprintf
String
next =3D succ
next! =3D succ!
Thread
fork =3D start
exit =3D kill =3D terminate
for many synonyms consider duck typing usage as well - it's not only ab= out
making sense when reading:
if i have a lib that does this
exit if bug
then i can use it like this
require 'lib'
or like this
successfully_loaded =3D Thread::new {
begin
require 'lib'
true
rescue SystemExit
nil
end
}.value
puts "Thread#exit called in lieu of Kernel#exit - whew" unless succe= ssfully_loaded
the interface polymorism gained by synonyms is often handy.
if i design a table class an initially design it around a hash and use
table.store key, value
in my code, but later decide i need to store multiple values under one = key and
switch to a database backend i can simply have a store method that look= s like
def store key, *values
...
end
and then start using
table.store key, v0, v1, v2
without changing the other code. if i'd used
table[key] =3D value
all over the plase initially i'd have a strange mixture of methods and = would
require a special [] method for storing one value, which would quickly = become
code smell. in this case the abstract idea of 'storing' something unde= r a key
was more appropriate to my design in the first place so using this inte= rface
saved me grief later.
synonyms exist elsewhere for clarity in ruby too
unless =3D=3D if not
thankfully.
regards.
-a