lua-users home
lua-l archive

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


2009/12/18 Michal Kolodziejczyk <miko@wp.pl>:
> On 18.12.2009 18:19, Javier Guerra wrote:
>> - try to design the API so that it doesn't make sense to have more
>> than 1 optional parameter
>
> This is interesting... That would be kind of dataflow programming:

not at all, it's about keeping focus.

what you describe is a nice API style ( try to make it work by
returning useful values), also called method chaining, or 'fluent
style' (i'm not sure if i find this name amusing or nauseating); but
it's not what i was thinking about.

about keeping focus: if a function has too many parameters, and
especially if many of them are optional, it's a hint that either:

a) all these parameters are in fact configuration. if so they should
be in a table anyway, or in object state.

b) the function is trying to do many different things according to the
right combination of present and absent parameters.  in that case,
better split it in two or more functions, each one with fewer
parameters.


-- 
Javier