Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

11
  • 1
    I don't feel that your forward-paragraph example is a large function; and it is certainly a matter of opinion and taste. And I don't believe that your rule of thumb that every function should fit in 20 lines is universal (or even a good one). I have seen in several languages functions of many hundreds of lines (and the code still being readable and well written) Commented May 19, 2017 at 11:39
  • @BasileStarynkevitch Don't you think that the readability of forward-paragraph could be improved drastically? For example, handling the forward and the backward cases in two loops is a suspect for code duplication. In any case, the structure would be greatly clarified by handling these cases in separate functions. Also, 20 lines is quite lenient. I recall that I read a book (it could be "The C++ Programming Language" by B. Stroustrup) that argued for 7-10 lines. Commented May 19, 2017 at 11:51
  • 1
    Length of named code blocks might be a good metric. We know that at more lines of code, more potential errors. However if you use this metric, you should consider your thresholds independently for each language, because languages expressiveness varies. - It could be possible to improve the presented code. Yet there could be other concerns such as performance, encapsulation, namespace pollution, or version history readability. Or most likely time has not been put into it because it works and they rather work on fixing something or adding something new, or have a life. Btw idk Lisp. Commented May 19, 2017 at 12:27
  • 2
    There is no need to search for hidden reasons why this function is so large. I am pretty sure the true reason is the same reason as why there are so many systems with a big ball of mud architecture - functions, systems and programs grow over time, and are often maintained by devs who do not value refactoring and clean code enough (just look at the reply you got above - do I have to say more)? Commented May 19, 2017 at 19:08
  • 1
    Note you'll also find lots of C and C++ code with huge functions, this isn't tied to the language nor the project. Though those projects with a longer history tend to have such "book-length" functions. Commented May 20, 2017 at 2:17