lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Jun 7, 2012, at 8:24 AM, steve donovan wrote:

> On Thu, Jun 7, 2012 at 2:06 PM, joao lobato <btnfdp.lobato@gmail.com> wrote:
>> Yes, I can see why method chaining seems easier to follow when reading
>> code, but it is in contravention of [the Law of Demeter] and I don't want to be stopped
>> by the police :-) .

I was at Northeastern University when the Demeter language systems were being implemented. A joke was "why didn't the police give you a parking ticket?" "Because de meter is broken!"

> Well, the Thought Police tend to work according to the letter, not the
> spirit, of the law.

I've had Camper Van Beethoven's cover of "Who Are The Brain Police" stuck in my head all day.

> [1] A list comprehension (for instance) translates into a for-loop
> anyway; why does it then become a less useful screwdriver, or more
> dangerous than a for-loop?

A terse lambda translates directly to a function constructor. I guess my analogy is an appeal to adverse consequences: if we start thinking about list comprehensions, we'll be back in the "OMG LUA APL" mailing list stew.

I think the aesthetic argument is that code should be written vertically, not horizontally, which is another way of saying that statements (not expressions) are the primary organizing style of Lua. I dunno. It's easier to make that argument for, say, Smalltalk, where mutation is the assumption and there is the ";" syntax for repeated calls to a single object, like "local e = expr; e:foo() e:bar() e:baz()". In contrast, "expr:foo():bar():baz()" allows each chained function to change the identity being worked on. (It also requires that participants in the chain return something useful to chain off of.)

Jay