Adrian, My main motivation for writing this module is another module I'm working on; in which I have lot's of API functions which take optional arguments. I use Decree extensively in that module (you may want to take a look here <https://github.com/EyalAr/lwip>). Before using Decree, my functions were simply too big and cumbersome. When reading the code of a function, by the time you got to the real meat, you had to read 10-20 lines of irrelevant code. As I wrote to Tom above, I imagine there is some performance hit, but I haven't checked yet. I am sure, though, that by making your functions smaller and more focused, they are easier to maintain and debug.
Thanks for the interest, Eyal. I should note that both Decree and the other module I mentioned are in beta and have not been used in production. But they are heavily tested. On Monday, October 6, 2014 5:47:48 PM UTC+3, Adrian Lynch wrote: > > I like the idea. Have you used it in anger yet? How did it feel in a > bigger code base? Did it get in the way or hinder your dev? > > We're having the same debate on a new app we're developing and we can't > settle on an answer. > > Looking forward to more perspective on this... > > Adrian > > On 5 October 2014 18:25, Eyal Arubas <[email protected] <javascript:>> > wrote: > >> I'm wondering what are some common ways to approach the problem of >> figuring out which arguments the user has passed to a function. >> >> It's a problem I've encountered many times when writing libraries with >> APIs; especially for functions with optional arguments. >> Each such function requires logic to figure out which of the arguments >> were supplied, and assign default values to those which weren't. >> A function with just a few arguments requires a large chunk of code just >> for this purpose. >> >> An alternative approach is to use an `options` object, the fields of >> which represent the arguments, and directly assigned by the user. >> This, however, imo, is less suitable for public APIs. I prefer to have >> function signatures with distinct arguments. >> >> It seemed to me like there should be a programmatic solution to this. >> Each function's arguments should hold certain conditions. Arguments must be >> of certain types, some are optionals, some have default values, etc. >> This led me to develop a module which allows to declare the properties of >> the function's arguments. The module resolves tnd disambiguates the >> arguments passed by the user based on those declarations. >> >> https://github.com/EyalAr/Decree >> >> Decree works by analyzing a list of argument declarations. It then >> figures out all the possible combinations. >> For example, a function which receives two arguments, with the first one >> optional, has two possible combinations - the user can call the function >> with one argument (thus omitting the first one), or with two (thus >> providing the first one). >> A function with two arguments, of which non is optional, has only one >> combination. >> When the user calls the function, decree will match the supplied >> arguments to a certain combination. If no combination is found, the user >> supplied invalid arguments. If more than one combination is found, the user >> was not specific enough, and there is ambiguity. Decree can tell where is >> the problem. >> >> How do you usually approach this problem? >> And what do you think about this solution? >> >> -- >> Job board: http://jobs.nodejs.org/ >> New group rules: >> https://gist.github.com/othiym23/9886289#file-moderation-policy-md >> Old group rules: >> https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines >> --- >> You received this message because you are subscribed to the Google Groups >> "nodejs" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/nodejs/714e2782-1b8b-4203-bcef-36761b65d993%40googlegroups.com >> >> <https://groups.google.com/d/msgid/nodejs/714e2782-1b8b-4203-bcef-36761b65d993%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > -- Job board: http://jobs.nodejs.org/ New group rules: https://gist.github.com/othiym23/9886289#file-moderation-policy-md Old group rules: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/nodejs/89ee28ed-15f1-4281-97b5-64055870d2cb%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
