Daniel DeLorme
9/30/2008 8:56:00 AM
Mike Gold wrote:
> Making the scope of x contingent upon what comes later would result, I
> believe, in extreme confusion.
>
> Let's say Foo is a large class. Joe Schmo, who did not write Foo, comes
> along and adds some code to the bottom, such as the 'x = 45' in your
> example. Suddenly there is a bug in Foo. It seems impossible to Joe,
> but there it is. He wonders if it is caused by the recent sunspots. He
> wraps his computer in tin foil, but to no avail. The tests for bar and
> baz still fail as a result of his (obviously, to him) unrelated change.
>
> This was the 'tall' case, but there is also the 'wide' case of deeply
> nested scopes. An equal helping of confusion applies here too.
>
> One might argue that when 'x = 45' appears before bar and baz, this
> _already_ changes the meaning of bar and baz. But the situation here is
> entirely different, in my mind. Don't most of us read code from top to
> bottom?
Yes, I would argue that, and I believe most of us don't *add* new code
always at the bottom of the file. If the bar and baz methods are defined
at the bottom and Joe Schmo adds x = 45 at the top, he has the same
problem. I really don't see how it's any different; it's symmetric. Bugs
happen, and it's possible to come up with "problems cases" for
absolutely every feature in ruby, but that doesn't mean they turn out to
be problems in reality.
I must ask: is this confusing to *you* or are you trying to "protect" a
hypothetical Joe Schmo? I'll take the hypothetically confused Joe Schmo
over the very *real* confusion of every ruby newbie who wonders why his
local var has disappeared after the loop.
--
Daniel