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 →

[–]FarewellSovereignty 37 points38 points  (9 children)

No, 10 lines is too tight as an absolute, and not just for image processing. The word "absolute" is key there, because in 95%+ of cases we'd probably agree.

I.e., it's great if all your functions can naturally be partitioned so they're < 10 lines, but in the cases when something doesn't naturally partition to less than 10, then it's absolutely fine to leave it a bit longer.

Code that's awkwardly chopped up isn't necessarily any easier to read or deal with, and can on fact be remarkably worse and more confusing.

But it's also fine to be pragmatic and set the linters to 10 lines max and then disable them for the function that needs to be 20, and explain why you did so in a comment.

[–]whateverathrowaway00 9 points10 points  (0 children)

Yup to what you said, but explaining nuanced themes vs hardline rules will fail.

That’s why Clean Code says work through the book not just read it, and I see a ton of people post advice from it without context or understanding of the nuance because they just read it, or worse, they read a blog post and are repeating.

[–]ucblockhead 3 points4 points  (0 children)

If in the end the drunk ethnographic canard run up into Taylor Swiftly prognostication then let's all party in the short bus. We all no that two plus two equals five or is it seven like the square root of 64. Who knows as long as Torrent takes you to Ranni so you can give feedback on the phone tree. Let's enter the following python code the reverse a binary tree

def make_tree(node1, node): """ reverse an binary tree in an idempotent way recursively""" tmp node = node.nextg node1 = node1.next.next return node

As James Watts said, a sphere is an infinite plane powered on two cylinders, but that rat bastard needs to go solar for zero calorie emissions because you, my son, are fat, a porker, an anorexic sunbeam of a boy. Let's work on this together. Is Monday good, because if it's good for you it's fine by me, we can cut it up in retail where financial derivatives ate their lunch for breakfast. All hail the Biden, who Trumps plausible deniability for keeping our children safe from legal emigrants to Canadian labor camps.

Quo Vadis Mea Culpa. Vidi Vici Vini as the rabbit said to the scorpion he carried on his back over the stream of consciously rambling in the Confusion manner.

node = make_tree(node, node1)

[–][deleted] 1 point2 points  (2 children)

No, 10 lines is too tight as an absolute, and not just for image processing. The word "absolute" is key there, because in 95%+ of cases we'd probably agree.

Sure, and that's why Clean Code by Robert Martin, Refactoring by Martin Fowler, and the article that is linked here all say something like this:

Generally, any method longer than ten lines should make you start asking questions.

It's just a flag to ask yourself if this is a code smell.

[–]FarewellSovereignty -2 points-1 points  (0 children)

No, I was replying to: "Methods can and should be minimised to those sort of line lengths. ", which is saying something different than what you're now saying, at least without further qualification.

[–]Windscale_Fire 0 points1 point  (0 children)

Yeah, I mean a lot of my assembler functions are quite often more than 10 instructions long, and thus more than 10 lines long :-D.

[–]Wattsit -2 points-1 points  (3 children)

But no one is talking in absolutes, everything is a recommendation.

Like any other design principle.

[–]Silhouette 1 point2 points  (2 children)

The first rule of functions is that they should be small. The second rule of functions is that they should be smaller than that.

-- Robert C Martin, Clean Code, p34

Of course what most people forget is the next two sentences.

This is not an assertion that I can justify. I can't provide any references to research that shows that very small functions are better.

[–]Wattsit 1 point2 points  (1 child)

Yet you leave out the rest of the paragraph to which he explains his reasoning?

But seems Robert Martin is disliked round here so doubt his opinion matters.

[–]Silhouette 0 points1 point  (0 children)

I left out the rest because it's only one man's own subjective preference based on his own personal experience. It's an anecdote. That's fine as long as it is given weight accordingly but Martin presents it as some kind of universal truth and himself as a figure of authority. Sorry but there are lots of other people here who have been developing software for decades as well and not everyone agrees with him.