4 ms·
"9.The use of pointers should be restricted. Specifically, no more than one level of dereferencing is allowed. Function pointers are not permitted." I disagree
by joesmo 12y ago
"9.The use of pointers should be restricted. Specifically, no more than one level of dereferencing is allowed. Function pointers are not permitted."
I disagree that JS developers can't get anything out of this. The rule clearly states that first-class functions (function pointers in C) should not be used. Whether that's a good or bad idea to follow is another matter, but the author's interpretation that it doesn't apply to JS is wrong. IMO, it's likely to reduce complexity and bugs quite a bit so it seems like the rule should be generally followed if one follows the rest of the rules, despite giving up such a powerful and flexible feature.
- marrs 12y agoPerhaps I'm misunderstanding you, but it sounds like you're saying that you'll reduce complexity by avoiding jquery, underscore, and half of the built in API. This is the opposite of my experience.
- debacle 12y agoCyclomatic complexity is different from execution complexity.
- marrs 12y agoImplying that execution complexity is increased? Is a function not dynaically bound at the last moment anyway, regardless of how it is called? Where is the increased complexity?
- debacle 12y agoYes. Every time you introduce a new library, the deterministic nature of a system is challenged. It's kind of a silly point, though - the browser itself introduces more execution complexity than any JavaScript library could.
- marrs 12y agoOh, I see what you mean now. I was referring to those libraries as an example of a useful application of the pattern. My point was, if you disallow passing functions, you disallow those patterns.
- lscharen 12y agoTotally agree on this point. My feeling is that Rule 9 roughly maps to following the Law of Demeter in that you shouldn't chase properties down more than one level, e.g. Good: var something = obj.property; Bad: var something = obj.property1.property2.property3;
- adestefan 12y agoOnce again this has more to do with the idea that everything must be deterministic. Using a pointer when it's not absolutely needed is just one more place where a non-deterministic runtime issue can crop up.
- PixelsCommander 12y agoThis is the missing thing, will add. Thanks guys!
- siscia 12y agoI agree that if we apply rule 9 to JS we would end up with something extremely different. However don't use first-class functions in my opinion it would means to not pass function around, in anything. So no callback and no a lot of nice "trick" that JS use (and I really enjoy.) I don't think that JS can live with rule 9.
- PixelsCommander 12y agoYep, applying this restriction on functions is something I would avoid to suggest as they are a cornerstone of modern JS development. However another part of rule seems to be something to consider.
- debacle 12y agoThere's a reason, though, that people call it "callback hell." Many people are irresponsible with first-class functions.