5 ms·
> Typically, this means no more than about 60 lines of code per function. Uncle Bob would be very upset by this statement. He advocates a maximum of 4-5 lines
by laurencei 12y ago
> Typically, this means no more than about 60 lines of code per function.
Uncle Bob would be very upset by this statement. He advocates a maximum of 4-5 lines per function to ensure readable code in his Clean Coders video series. Anything more, and you need to refactor into smaller functions.
- zoner 12y agoThat was a loose statement in the book, 60 lines might be long, but in extreme cases, it's ok.
- brudgers 12y agoPerhaps Uncle Bob is engineering for the real world and applying 10 as the factor of safety. Space flight engineering runs more thinnly along the envelop. With the JPL Standard's requirement that all functions validate every argument, one line per declaration, and two assertions on average per function, six lines will disappear pretty fast. Uncle Bob is preaching software engineering as engineering to the heathen masses. The JPL Standards are a sermon for the choir. Uncle Bob doesn't, so far as I know, advocate C for all critical code.
- anton_gogolev 12y ago> He advocates a maximum of 4-5 lines per function to ensure readable code Yeah, and you end up with myriad of functions which are used once and only once and it becomes impossible to actually find code which does something useful.
- nly 12y ago... and good luck naming all those functions.
- pjc50 12y agoSee sibling comment about domain-specific language; there's nothing wrong with long function names if your autocomplete is working. Codebase I'm working with has names like "auditNullRecipeCursorAtEndOfOrderLineAdditionsIfRequired" and "getUnselectedSiblingWithSametabIndexOrCreateRepeatedChildIfLessThanMax"
- im2w1l 12y agoIt's hard to notice typos in names that long. Can you immediately tell where the typo is in auditNullRecipeCursorAtStartOfOrderLineAdditionsIfRequired ?
- pjc50 12y agoI can't tell at all. Fortunately, as long as someone hasn't declared another function with the typoed name, either Intellisense or the compiler will tell me. I have a much harder time with "_tcscpy_s" and similar suites of functions where a single-letter typo is likely to be a different function with the same signature.
- im2w1l 12y agoI changed ...End... to ...Start..., which could be a plausible real world bug.
- prodigal_erik 12y agoI don't have a tool that relieves me of needing to read all those names, so not having to type them isn't that helpful. Domain-specific languages are productive; their parts combine in ways giving novel results. A list of a million verbs you can only ever use for one purpose is not a language in that sense.
- mrweasel 12y agoI've tried to apply this to my coding, maybe not 4-5 lines, but definitively keeping to short functions/methods. You're right that you end up with a myriad of functions, may of which you only use once, but I was surprised how often I actually been finding myself reusing something. I have much more code reuse than I originally figured. One thing that might be an issue, depending on your temper is that your code almost becomes a DSL. Programs are pretty much stringed together by this "myriad" of custom functions, that might not be useful outside this one program.
- raverbashing 12y agoYeah, he can be "upset" as much as he wants, he doesn't build robots that go to other planets. How about we stop blindly accepting whatever UB says, most of what this man says is crap, really