[ruby-talk:02328] Re: Question about attribute writers

From: "Conrad Schneiker" <schneiker@...>
Date: 2000-04-01 10:04:51 UTC
List: ruby-talk #2328
Hi,

Clemens Hintze writes:
> Dave Thomas writes:
> > Clemens Hintze <c.hintze@gmx.net> writes:
...
> I admit this it-could-be-a-variable-or-a-method-call thingy is one of
> the things, that disturbes me also sometimes in Ruby.
...
> I would propose the opposite, if we really want to issue an
> warning. The warning should be issued for the case
>
>    age / 12
>
> where I want to divide the value of a variable 'age'. But because this
> variable does not exists, I will get a method call compiled. Here the
> compiler could issue an warning like:
>
>    warning: ambigues variable access or method call

How about also having Ruby tell us which it picked:

  warning: ambiguous variable access or method call: presuming <whichever>.

> I could by-pass this warning then by explicitely writing:
>
>    age() / 12
>
> But I admit, that this solution would probably issue too much warnings
> because the 'age / 12' syntax is often used!

If you run with -w and want to get rid of warnings, I think you should do so
by making your code more explicit, if only out of mercy for other users or
for your future self a year or two later.

One of the advantages of Ruby over Perl is that it is often more clear or
more obvious what your code is doing. This is one reason that many people
claim to prefer Python to Perl. Ruby should strive to better still in this
regard. So I don't think it is a good idea to worry about making life too
easy for people who do things that are unnecessarily difficult to comprehend
or which are easy to misinterpret if you don't know the details about the
rest of the program. That violates the spirit of object-oriented
programming. So be warned!

> Perhaps it would be better to not change anything, and describe this
> case very carefully in the books and docs.

I am in favor (where it makes sense) of -w warnings for things that have to
be described very carefully.

If you have to decrypt your code, you should really make it more explicit
unless and until someone thinks of a better way for Ruby to handle this.

> Every language has its
> gotchas. We cannot eliminate all of them. This is one of Ruby.

Yes, but I think we should follow the Perl policy of providing -w warnings
of gotchas whenever possible. IMHO, this is one of the things that has made
it possible for Perl to thrive despite its many gotchas.

Conrad


In This Thread

Prev Next