Re: fn:slice()

I think there is a basic principle:

*The most significant (in meaning) arguments for the function should be
positional *(maybe in order of significance).

*Only insignificant add-ons, such that we can live without them, should be
specified as keyword arguments* -- for convenience if someone needs to
alter universally-accepted defaults.
The word *convenience *is very important here, because having more than 2
such named arguments actually starts to bring *inconvenience*.

If a function must have more than 2-3 significant arguments, this is a
design smell. It means that some of the arguments are actually properties
of another object, so we need to narrow the context.

Thanks,
Dimitre

On Fri, Dec 4, 2020 at 9:06 AM Christophe Marchand <cmarchand@oxiane.com>
wrote:

> I'm currently reading Clean Code[1] from Robert Martin. He says that a
> function should never has more than 3 parameters, and that we should make a
> lot of efforts to avoid functions with more than two parameters. Ok,
> examples in this book are in Java, an OO language, and not a functional
> language, but, in my opinion, as a teacher and a user, I'd prefer 3 simple
> functions with a name that clearly identify what the function do, than a
> function that can make a lot of different things.
>
> Having read this thread over two days let me with a strange fealing : I'm
> not sure I totaly understand what's the goal of this slice function ...
>
> > We should also be able to write a brief description of the clas in about
> 25 words, without using the words "if", "and", "or", or "but".[2]
>
> I'm not sure we'll be able to give a brief description in 25 words of such
> a swiss-army-knife function.
>
> [1] Clean Code - Robert C. Martin - Pearson Addison-Wesley ISBN-13:
> 978-0-13-235088-4
> [2] See [1] Chapter 10
>
> Christophe
> Le 04/12/2020 à 11:15, Michael Kay a écrit :
>
> Which do you prefer?
>
> Option A
>
> A single (swiss-army-knife) slice() function as proposed yesterday
>
> Option B
>
> Three functions:
>
> * fn:items-at($seq, xs:integer+) returning the items at the given positions
>
> * fn:slice($seq, start?, step?,  (end | length)? ) accepting some
> combination of start, end, length, and step, each supplied as an integer
>
> * fn:range($seq, (before | until)? (after | from)?) accepting predicates
> for the start and/or end of the selected range
>
> This retains most of the useful combinations, but each of the functions is
> much simpler. (I've used an informal notation to indicate which
> combinations of parameters are allowed). Negative positions allowed for
> items-at, start, and end.
>
> Option C
>
> Two functions:
>
> fn:slice($seq, $positions as integer+)
>
> where $positions might be (3), (-1), (1 to 5) or ( 1 to 5 by 2).
>
> fn:range($seq, (before | until)? (after | from)?) accepting predicates for
> the start and/or end of the selected range
>
>
> Michael Kay
> Saxonica
>
> On 4 Dec 2020, at 03:52, Mukul Gandhi <gandhi.mukul@gmail.com> wrote:
>
> On Fri, Dec 4, 2020 at 8:04 AM Dimitre Novatchev <dnovatchev@gmail.com>
> wrote:
>
>> While this function is obviously very powerful, its complexity affects
>> the learning and confidence of use.
>>
>> This leads to not-confident / hesitant / unhappy developers.
>>
>
> I agree to above mentioned concerns.
>
> But +1 to introduction of fn:slice() function to XPath/XSLT.
>
>
>
> --
> Regards,
> Mukul Gandhi
>
>
>

-- 
Cheers,
Dimitre Novatchev
---------------------------------------
Truly great madness cannot be achieved without significant intelligence.
---------------------------------------
To invent, you need a good imagination and a pile of junk
-------------------------------------
Never fight an inanimate object
-------------------------------------
To avoid situations in which you might make mistakes may be the
biggest mistake of all
------------------------------------
Quality means doing it right when no one is looking.
-------------------------------------
You've achieved success in your field when you don't know whether what
you're doing is work or play
-------------------------------------
To achieve the impossible dream, try going to sleep.
-------------------------------------
Facts do not cease to exist because they are ignored.
-------------------------------------
Typing monkeys will write all Shakespeare's works in 200yrs.Will they write
all patents, too? :)
-------------------------------------
Sanity is madness put to good use.
-------------------------------------
I finally figured out the only reason to be alive is to enjoy it.

Received on Friday, 4 December 2020 17:24:59 UTC