[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Defining APIs, best practices.
- From: Rena <hyperhacker@...>
- Date: Fri, 14 Dec 2012 19:24:06 -0500
On Fri, Dec 14, 2012 at 6:44 PM, Javier Guerra Giraldez
<javier@guerrag.com> wrote:
> On Fri, Dec 14, 2012 at 6:33 PM, Coda Highland <chighland@gmail.com> wrote:
>> If and only if the function detects the difference between (nil) and
>> (). If the function is called enable, and I call it as enable(), I
>> would expect it to enable the object -- that is, the same as
>> enable(true), not enable(false)! So it's messy.
>>
>> For this reason I prefer setEnabled(bool) over enable(bool), which
>> also means the matching predicate is isEnabled().
>
> about semantics and names:
>
> i'd expect a "enable()" function to always enable. and a
> "setEnabled()" to take a flag.
>
> no mess with "enable()==enable(nil)==enable(false)==disable()"
>
> --
> Javier
>
Personally, I feel the most Lua-like method is to provide a .enabled
property via metatables, but that's not always the best idea, when
overhead and complexity might be an issue. In that case I usually go
with enable(x) means "if x then enable else disable end", and
isEnabled() to check.
--
Sent from my Game Boy.
- References:
- Defining APIs, best practices., Jorge
- RE: Defining APIs, best practices., Thijs Schreijer
- Re: Defining APIs, best practices., Jorge
- Re: Defining APIs, best practices., Javier Guerra Giraldez
- Re: Defining APIs, best practices., Coda Highland
- Re: Defining APIs, best practices., Javier Guerra Giraldez