Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #31746
| From | Scott Sauyet <scott@sauyet.com> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: Why does savepng workl with eventlistener but not by call from form? |
| Date | 2016-11-27 01:08 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <o1dblq$pr$1@dont-email.me> (permalink) |
| References | (3 earlier) <2828265.aV6nBDHxoP@PointedEars.de> <o1ctld$g60$1@dont-email.me> <4504999.NdOOCcYCMV@PointedEars.de> <o1d4q7$c90$1@solani.org> <1768059.oMNUckLgyt@PointedEars.de> |
Thomas 'PointedEars' Lahn wrote: > Christoph M. Becker wrote: >> Thomas 'PointedEars' Lahn wrote: >>> Scott Sauyet wrote: >>>> Thomas 'PointedEars' Lahn wrote: >>>>> Lesson to be learned: Design functions/methods to accept references >>>>> to parameter/option objects, and not more than 5 arguments [unless >>>>> it is a list of values of equal meaning, see e.g. Math.max()]. >>>>> Otherwise nobody is going to remember the correct argument order, >>>>> you will be sacrificing flexibility, [ ... ] >>>> Why five? That still seems far too many for almost every case. >>>> Three seems to me a much better guideline. Of course everyone will >>>> draw these lines differently for themselves, but I was wondering: do >>>> you have a specific reason for that number? >>> Yes. >> >> Which is? > [... fun and relevant but somewhat long Douglas Adams quote elided ...] > So, why did I pick 5? It just seemed practical at the time, and it > still does. It is a reasonably small number, which is important for a > short code line length, particularly if you want to be descriptive in > your parameter names, but not so small as to be overly restrictive in a > rule of thumb. [ ... ] Would you find a rule of thumb suggesting at most three parameters overly restrictive? > In hindsight, there is also an oft-cited theory in the cognitive > sciences (which I learned of when studying machine-computer interaction) > which is usually interpreted so that humans’ working memory can hold up > to 7 ± 2 items; so, 5 would be a number that every human(oid) could > manage: > > <https://en.wikipedia.org/wiki/ The_Magical_Number_Seven,_Plus_or_Minus_Two> Even that Wikipedia article discusses how much controversy there is around those numbers and even with the basic idea that there really are fixed size limits irrespective to the contents. But regardless of that, all those experiments have to do with being able to repeat back sequences immediately after presentation. For function parameters surely the relevant criterion would be being able to infer the correct order even long after learning them. So I strive to create parameters in a particular order: the one most conducive to currying. I try to place any parameter more likely to change after one less likely to change. Of course this is not always clear, and sometimes there are still judgment calls, but I think it serves reasonably well, and it tends to make it easier to remember the parameter order. Of course it helps that it's extremely rare that I create a function with more than three parameters! ;-) > Finally, I think that I can remember the correct order of 5 parameters > without consuming too much caffeine. Your memory must be better than mine. I have a hard enough time with three, even with the rule above, if there's any ambiguity about which parameter is more likely to change. ----- Of course this is not a serious disagreement. Clearly the main rule is to limit one's parameter list as well as one can. But I'm always curious as to how people decide upon their particular limits. -- Scott
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why does savepng workl with eventlistener but not by call from form? jonas.thornvall@gmail.com - 2016-11-10 14:35 -0800
Re: Why does savepng workl with eventlistener but not by call from form? jonas.thornvall@gmail.com - 2016-11-10 15:47 -0800
Re: Why does savepng workl with eventlistener but not by call from form? JJ <jj4public@vfemail.net> - 2016-11-11 21:05 +0700
Re: Why does savepng workl with eventlistener but not by call from form? jonas.thornvall@gmail.com - 2016-11-11 06:35 -0800
Re: Why does savepng workl with eventlistener but not by call from form? JJ <jj4public@vfemail.net> - 2016-11-11 22:01 +0700
Re: Why does savepng workl with eventlistener but not by call from form? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-11-11 16:21 +0100
Re: Why does savepng workl with eventlistener but not by call from form? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-11-11 16:08 +0100
Re: Why does savepng workl with eventlistener but not by call from form? Scott Sauyet <scott@sauyet.com> - 2016-11-26 21:09 +0000
Re: Why does savepng workl with eventlistener but not by call from form? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-11-26 22:47 +0100
Re: Why does savepng workl with eventlistener but not by call from form? "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-11-27 00:11 +0100
Re: Why does savepng workl with eventlistener but not by call from form? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-11-27 00:57 +0100
Re: Why does savepng workl with eventlistener but not by call from form? Scott Sauyet <scott@sauyet.com> - 2016-11-27 01:08 +0000
Re: Limit number of function parameters (was:Why does savepng workl with eventlistener but not by call from form?) "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-11-28 18:17 +0100
Re: Limit number of function parameters (was:Why does savepng workl with eventlistener but not by call from form?) Scott Sauyet <scott@sauyet.com> - 2016-11-29 02:15 +0000
Re: Limit number of function parameters "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-12-02 20:24 +0100
Re: Limit number of function parameters Scott Sauyet <scott@sauyet.com> - 2016-12-03 01:58 +0000
csiph-web