[Date Prev][Date Next][Thread Prev][Thread Next]
- Subject: Re: How do you cope with 2 or more optional parameters?
- From: Javier Guerra <javier@...>
- Date: Fri, 18 Dec 2009 14:16:52 -0500
2009/12/18 Michal Kolodziejczyk <firstname.lastname@example.org>:
> 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