From: George Ogata Date: 2002-08-11T20:24:53+09:00 Subject: Re: ambiguity between local variable assignment and writter method Tom Sawyer wrote: > no, if i were creating ruby now, i would very much consider doing that. > certainly it adds an extra char to all local vars, but it makes things > quite distinct. I think it makes things less distinct. @, @@, and $ appear quite scarcely (compared to locals), and so they stand out. Giving locals a prefix letter blends the whole lot into an unreadable mess. > do you consider @, @@, and $ junk? If they were used on every identifier, yes. If used sparingly (as in current ruby), though, I think it can sometimes (ok, quite often) help you follow code. I guess "that sort of junk" wasn't a fair expression to use. > you know other languages have commands to specify the access level of > variables. so you can't tell the difference just by looking at them. you > code something like 'global avar' or 'public avar'. Well, 'public' doesn't really come into it here, does it? Ruby uses methods for that to mimic the way other languages do it. I wasn't suggesting that we rid them all (I said "minimize", not "eliminate"), just that they should be used only when really needed, and when the alternatives aren't better. Prefix symbols have a side-effect of making things stand out, and when too much stands out, it just becomes noise. >> I'd personally rather lose the o.member = 'something' notation for method >> calling. As David Alan Black mentioned: >> >> >> Isn't it good to have to know when you're calling a method and when >> >> you're assigning to a local variable :-) > > so you think writer methods are the problem? what would they be replaced > with? set_x methods, as is used in most traditional OO languages. They should still be magically generated using attr_*. I understand the motive of member=(), though. Since the interface of a class consists only of methods, o.member = 'x' has no meaning, so why not make that a method too? The problem is when it's used inside a class, when you can omit the "o.", and a gotcha arises from potential ambiguity. I wonder if simply leaving "o.member = 'x'" as illegal ruby would've been better.