lua-users home
lua-l archive

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




2010/9/30 Javier Guerra Giraldez <javier@guerrag.com>
On Wed, Sep 29, 2010 at 5:29 PM, Tim Mensch <tim-lua-l@bitgems.com> wrote:
> The response of "get used to it" (AKA RTFM) is a classic apologist response
> for a bad UI

the answer (mine, at least) is not "get used to it", it's "write
better libraries".

the choice between . and : should be evident from the semantic of the function.

I think that lua-Coat (Yet Another Lua Object-Oriented Model) achieves this goal.
lua-Coat is class based, not prototype based. So :

Class.foo() -- is a class method call
obj:bar() -- is an instance method call
val = obj.baz -- is an attribute getter
obj.baz = val -- is an attribute setter

And the use of CamelCase for class name improves this.

François
 

case in point: LuaSocket:  'system wide' functions like constructors
or so doesn't operate on any 'object', so call them with .   'object
specific' functions, like send(), or accept(), are evidently
associated with a specific object, so call them with :

also, remember that  : doesn't mean 'method call', but 'call this with
an automatic first parameter', so at the same time you're thinking of
what do you have to put to each parameter, you already have in your
mind's local scope the object at the left of the function name, if
it's your first parameter, use : , if it's just a namespace, use .

no ambiguities, no 'go memorize the docs', no traps.   it _is_ a good idiom.

if you don't like it, you're free to write whatever contraptions on
top of the methods; just don't try to convince that you're saving
anybody from anything (beyond laziness to learn a new language)

--
Javier