this is almost a workaround for the lack of named parameters

deadalnix deadalnix at gmail.com
Tue Mar 26 20:34:14 PDT 2013


On Wednesday, 27 March 2013 at 03:29:24 UTC, Timothee Cour wrote:
> Named parameters are only interesting if we can skip some 
> optional parameters.
> This allows the python-like syntax of specifying only a subset 
> of
> parameters; otherwise this isn't very interesting. This is used
> heavily in python and makes code
> * self-documenting
> * avoids DRY (don't specify unused params)
> * avoids boilerplate of introducing auxiliary option structs 
> and fields to it
>
> Here are just 3 examples that hopefully will convince some that 
> named
> params are useful and not ugly.
>
> ----
> //inspired from python's matplotlib; many more options 
> configurable,
> which are set to reasonable defaults
> plot(x=1,y=2,color='red',width=3);
>
> //here's another one (cf inspired by scons / waf build tools in 
> python)
> compile(input=["foo.cpp"] , run=true, debug=true, 
> ldflags="-lcurl",
> output_dir="build");
>
> //other example: setting optional params in a classifier
> trainSVM(input=X, labels=Y, C=1000, crossValidate=true, 
> loss=squareHingeLoss)
> ----

How is that any better than the monadic solution proposed in the 
thread and that dn't require any language addition ?


More information about the Digitalmars-d mailing list