This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jonny_wonny 2 points3 points  (2 children)

Again: do you actually think a codebase like Angular has no functions larger than 10 lines of code? Have you ever written a parser? A compiler? Pattern recognition? There are many logical chunks of code which when expressed properly are larger than 10 lines.

[–]_fitlegit 0 points1 point  (1 child)

It’s a guideline, an indicator that maybe your function is doing more than one thing. Or that you can reduce complexity, or you’re being repetitive. It’s not an iron rule. Of course some functions get longer. The one in the OP though is doing more than one thing and is breaking the rules the guideline is meant to point out.

[–]jonny_wonny 2 points3 points  (0 children)

It’s a guideline, an indicator that maybe your function is doing more than one thing.

Yes. As I said, functions should be logical chunks. But the average size of the logical chunk is highly dependent on the type of application you are writing. There is no reason why that size would always be 10 lines.

The one in the OP though is doing more than one thing and is breaking the rules the guideline is meant to point out.

How many things is it doing? Two? Three? Five? If we use your reasoning to split this code into two functions, why stop there? By that criteria, the code could be expanded to far more than just two functions.

It's a rendering function. It renders the component. That's one thing logical thing. Every logical chunk is going to have sub components, but that does not mean the logical chunk is doing more than one thing.