From: Robert Dober Date: 2007-07-20T00:39:26+09:00 Subject: Re: Are we cool? method_missing in enumerator On 7/19/07, Tanner Burson wrote: > On 7/19/07, Trans wrote: > > > > > > > > On Jul 19, 2:45 am, dbl...@wobblini.net wrote: > > > Hi -- > > > > > > On Thu, 19 Jul 2007, Trans wrote: > > > > I think I've come up with a good alternative that is safer, but still > > > > reads well (as of 1.9): > > > > > > > arr.map.x + 3 > > > > > > > What do you think? > > > > > > I'm afraid there's too much "invisible ink" there for me. > > > > Well, what does that mean? Clearly you find it uncomfortable in some > > manner. Is it just the magic-dot again? Or something else? Is the > > original > > > > arr.map + 3 > > > > okay? Or are both too much "invisible ink". What is wrong with it/them > > more concretely? > > > At a glance, I can't tell if arr is a object with an attribute named map > that you're adding 3 to (and never storing). Does this return a value, or > does it modify in place? If it returns a value, then you'd end up with a > statement like > > new_arr = arr.map + 3 > > without knowing a lot of specifics about arr, map, and this magic, I would > totally assume that map is an attribute of arr, and you're adding 3 to it. > > This sort of shortcut is the kind of thing I would use in a DSL where > certain context is assumed, but wouldn't use in day to day programming, it's > just too ambiguous. This is indeed true, the art might be to find the balance (how is it going David? ;) between conciseness and readability. Your DSL example is excellent because it restricts users to a circle talking the same jargon, more generally I think one has to think about who will read the code. Consistency comes in too ( I did not do it on purpose ) if you write all your code like that a potential new team member or maintainer will learn your ways quickly... Robert -- I always knew that one day Smalltalk would replace Java. I just didn't know it would be called Ruby -- Kent Beck