On Nov 13, 2007 10:05 PM, -a <ara.t.howard / gmail.com> wrote:

> i also typically prefer
>
>   response = http.response
>   response.foo
>   response.bar
>
> to
>
>   http.response.foo
>   http.response.bar
>
> for two reasons
>
>  1) error reporting
>  2) vars are cheap in ruby, function calls are not
>
> although for simple/short code i do use the second often, reserving
> the former for 'real' code i anticipate maintaining and debugging.  i
> suspect i'm in the minority here.
>

Me too, though that may be an ancient aversion to null pointers in
structure member dereferencing in C as in

  some->null_pointer->in_the_middle->of_a_chain

I also find myself using this pattern:

  if response = http.response # i.e. expecting nil or false on failure
    response.foo
    # etc.
  else
    ...
  end

Your point on avoiding unnecessary method calls is well-made - there's
no telling how much an intermediate call may cost - why repeat it?

Regards,
Sean