this is almost a workaround for the lack of named parameters
J
notavail at notavailable.com
Sat Mar 23 17:27:30 PDT 2013
On Saturday, 23 March 2013 at 19:56:17 UTC, deadalnix wrote:
> On Saturday, 23 March 2013 at 15:55:36 UTC, John Colvin wrote:
>> On Saturday, 23 March 2013 at 15:00:13 UTC, bearophile wrote:
>>> foobar:
>>>
>>>> Code that needs named parameters to be more readable is
>>>> poorly designed code in the first place.
>>>
>>> Have you used a language where the usage of named arguments
>>> is idiomatic, like Python, Scala or Ada? They are sometimes
>>> useful even for well designed code, like functions with two
>>> arguments.
>>>
>>> Bye,
>>> bearophile
>>
>> A simple example is matplotlib.pyplot.plot
>>
>> There are so many possible flags and parameters that can be
>> passed in order to get the exact behaviour you want, but
>> commonly you'll only want a few set for each call. You don't
>> want to have to set all the other preceding parameters, you
>> just want to go e.g. plot(data, linewidth=5)
>
> Can't the monadic style thing do the trick ?
>
> Named!plot.linewidth(5).call(data);
>
> This is doable with actual D using compile time reflection.
Good point, and I'm sure we all develop our personal sense of
'code smell' based on our own past experience. I find adding lots
of enums to be like doing RAII in C++: I find it a pain to have
to pollute namespaces with extra enums (classes), just to get
readability/safety.
To me, the builder/monadic style is clunky and harder to read. I
find
plot(data, linewidth = 5)
to be clean, clear, and more concise.
More information about the Digitalmars-d
mailing list