Re: Keyword Arguments

Jeremy Tregunna <[email protected]> Thu, 14 Jun 2012 07:14:16 -0600
Newsgroups gmane.comp.lang.io
Message-ID <[email protected]>
On Thursday, 14 June, 2012 at 6:58 AM, Friedrich Dominicus wrote:
>   
> Steve Dekorte <[email protected] (mailto:steve%40dekorte.com)> writes:
> 
> > As objects are about coupling data and logic, if you're passing a lot of
> > arguments(data) around
> > to methods (logic), then it looks suspiciously like you've failed to couple
> > your data and logic.
> >
> > If I were to take the position that all uses of multiple arguments (and
> > therefore keyword arguments)
> > are failures to use proper OO design, could you provide a counter example?
> >
> > For example, in this:
> >
> >
> > def render(view, formats = ["html"], cache = false)
> >
> >
> > formats and cache seem like natural instance variables of the
> > receiver.
> 
> I agree with you but there is one area which I will call functional
> abstraction. You can see often that there are quite some long methods
> which are called e.g as constructors. I think templates for functions
> are a kind of "counter" example. Well yes if it's get too much you may
> recconsider using classes as Commands but still there are examples where
> at least 2 arguments are "needed" sorting blocks eg.
This isn't true. You can write a sort function which iterates over your list, applying a message which takes one argument (i.e., a comparator) to one element and inserting the next element as its argument. For instance, a use case might be:

list(1, 5, 2) sort(<) # Would yield: list(1, 2, 5)

This uses higher order messaging and is entirely possible in Io. This would work quite like Io's sortBy() which takes a block and two arguments at present. This works great for simple comparators. For more complex comparators I can see you needing a different solution however. However, if you always yielded an "elements" name in the context sort evaluated its arguments in, or some other name, you could write:

list(1, 5, 2) sort(myComplexAction(elements at(0)) < myComplexAction(elements at(1)))

And pretty much solve your problem. You can set up symbolic names if you want, but it's certainly doable and not so bad either. If it wasn't clear, "elements" above is a tuple of two items in the list.

Regards,

Jeremy Tregunna