WilliamJames
3/4/2009 4:39:00 PM
C. Dagnon wrote:
> Ruby has definite positives over Java and even other scripting
> languages, but many negatives too. One negative is the inconsistency
> of how rules seem to be applied in the language and accompanying
> toolsets. Here are a few that have bitten me:
>
>
> 1. I almost immediately got started with Ruby on Rails and loved the
> idea of partials, but then I found that the ||= idiom doesn't work on
> partials' parameters.
>
> <% my_param_a ||= 1 # Errors out
> my_param_a = my_param_a ? my_param_a : 1 # works
> -%>
>
> That seemed odd as I thought both were equivalent, and it broke some
> of the trust I had for Ruby.
Rails isn't Ruby. If I wrote a program in Ruby that erased every file
on your hard-drive, would you blame Ruby or me?
> Not as much as early Rails' use of 2
> separate variables for RAILS_ENV, but...
>
>
> 2. Then when using blocks to process an array I tried to use another
> Ruby control structure:
>
> arr=[1,2,3,4]
> arr2 = arr.collect{|ii| return 0 if ii == 3; ii+1}
This makes no sense. Correct:
[1,2,3,4].map{|n| if 3==n; 0 else n+1 end}
==>[2, 3, 0, 5]
[1,2,3,4].map{|n| 3==n ? 0 : n+1 }
==>[2, 3, 0, 5]
> # result: LocalJumpError: unexpected return
>
> That also caught me off guard - I need the block to return a value, to
> evaluate to a value - but suddenly I'm told that 'return' doesn't mean
> what I think it means? At least not inside a block (or Proc.new)...
>
>
> 3. Originally I was taught that symbols were the salvation of memory
> and key problems - and they certainly sounded like it. Up until the
> point a few days later when one (Rails?)
Rails is not Ruby. Rails could be be the worst piece of crap in the
universe and it still wouldn't be Ruby's fault.
> map used Symbols and another
> used Strings. Ouch.
> Without any explicit typing abilities in the language (optional or
> otherwise?) it seems like the only solution is to return to basic
> string matches:
> regex = Regexp.compile("^#{matcher.to_s}$", Regexp::IGNORECASE)
Horrible.
sym = :foo
==>:foo
"can FOO be found?"[ / #{ sym } /i ]
==>" FOO "
> key = map.keys.find{ |key| key.to_s =~ regex }
> Yuck.
>
>
> 4. And what's up with Ruby incorrectly naming their Map 'Hash'?
You beg the question. You must be very ignorant of "scripting"
languages. Hash is short for Hash Table, what is called in Awk
an associative array.
> Or is
> my C.S. idea of a Hash too limited? Granted in Java they have
> HashMap, but if you enter one value and get a second one out it is a
> Map, regardless of how the keys are stored. A 'Hash' would instead
> be a type of set.
A hash is a number returned by a hash function. An item's hash is
used to determine in which bucket of the hash-table it is put.
>
>
> Please let me know how I can supplement my possibly deficient Ruby
> education :) Relevant discussions or sections of "The Ruby Way"
> appreciated!
>