- From: Christophe Marchand <cmarchand@oxiane.com>
- Date: Fri, 4 Dec 2020 18:05:59 +0100
- To: public-xslt-40@w3.org
- Message-ID: <40e068f4-18cb-c536-0936-0181099e9434@oxiane.com>
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 >> <mailto:gandhi.mukul@gmail.com>> wrote: >> >> On Fri, Dec 4, 2020 at 8:04 AM Dimitre Novatchev >> <dnovatchev@gmail.com <mailto: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 >
Received on Friday, 4 December 2020 17:06:26 UTC