On Wed, Feb 1, 2012 at 9:16 AM, Robert Klemme
<shortcutter / googlemail.com> wrote:
> Yeah, I'd agree. =A0But why write such obfuscated code?

Here's the code with the thing that doesn't work.  Of course you don't
know the context, but I hope this is enlightening.

  # week_and_day(date) -> [17,1]  week 17, day 1 (Mon)
  # Returns nil if the given date is not in this term.
  def week_and_day(date)
    if not self.include? date
      return nil
    elsif (week, day =3D @t1.week_and_day(date))
      return [week, day]
    elsif (week, day =3D @t2.week_and_day(date))
      week +=3D @t1.number_of_weeks
      return [week, day]
    end
  end

I don't see anything obfuscated about that.  @t1.week_and_day(date)
will return nil if the date is outside the range of @t1, so we will go
to the next part of the conditional.

Here it is in acceptable Ruby.

  # week_and_day(date) -> [17,1]  week 17, day 1 (Mon)
  # Returns nil if the given date is not in this term.
  def week_and_day(date)
    if not self.include? date
      return nil
    elsif (week_and_day =3D @t1.week_and_day(date))
      return week_and_day
    elsif (week_and_day =3D @t2.week_and_day(date))
      week, day =3D week_and_day
      week +=3D @t1.number_of_weeks
      return [week, day]
    end
  end

This one has a clumsy variable name "week_and_day" and an extra line
to unpack it into "week" and "day".  I'm not crying mercy over one
extra line, but I definitely prefer the first version.  It seems more
intentional.

Gavin