News for hackers. Stuff that matters.
Re:Linear code is more readable by realrains on Thursday September 14, 2023 @11:59PM (#37518199)
I don't think the fact that a function works well is a good enough reason to write a 2000 line function. Sometimes there are long pieces of code that implement complex algorithms that are difficult to break into smaller pieces of code, but those cases are limited to the few you mentioned.
Re:Linear code is more readable by BigJono on Friday September 15, 2023 @01:54AM (#37519008)
Computers execute code in a linear fashion, why on earth would you "need a reason" to NOT abstract something? Just because abstraction is often the right thing to do doesn't make it the base case.

It's like saying you need a reason not to add 4000 random jumps in your assembly code just to make it more difficult to read...

Re:Linear code is more readable by ahtihn on Friday September 15, 2023 @02:08AM (#37519115)
Source code isn't written to be executed by computers, it's written to be read by other humans.

Source code tends to be very far removed from how computers execute anything, so I wouldn't use that as a justification for any sort of code style.

Re:Linear code is more readable by amoss on Friday September 15, 2023 @03:08AM (#37519563)
> Source code isn't written to be executed by computers, it's written to be read by other humans.

It is pronounced "documentation".

Re:Linear code is more readable by osigurdson on Friday September 15, 2023 @01:57AM (#37519034)
I guess all we know is there were 2K lines of code and the commenter thinks that was the right way to do it. It would be necessary to see the code to appropriately critique it.
Re:Linear code is more readable by goatlover on Friday September 15, 2023 @02:35AM (#37519296)
Not just the commenter, but his team as well. It passed code review with flying colors, apparently. The moral of the story is that there always exceptions and developers should not be ideologically committed to one approach above all else.
Re:Linear code is more readable by em-bee on Friday September 15, 2023 @07:07AM (#37521227)
we know more than that: You could argue that every one of those 9 scopes could be a separate function, but then devs would be tempted to reuse them. Yet, each step had subtle assumptions about what happened before.

what we don't know is if it would have been possible to abstract those assumptions away so that functions could have been defined without them.

Re:Linear code is more readable by osigurdson on Friday September 15, 2023 @10:08AM (#37523173)
Even the contrived example in the post can be factored differently (and better imo). How do we know those 9 scopes are appropriate?
Re:Linear code is more readable by PH95VuimJjqBqy on Saturday September 16, 2023 @01:52PM (#37536981)
We do know that if we trust the poster, they said very clearly it could have been done but they didn't consider the value to outweigh the downsides.
Re:Linear code is more readable by em-bee on Saturday September 16, 2023 @08:00PM (#37540091)
yes, i meant we don't know if it would have been possible to extract functions in such a way that they are actually safely reusable.
Re:Linear code is more readable by nomel on Friday September 15, 2023 @02:30AM (#37519248)
> that implement complex algorithms that are difficult to break into smaller pieces of code

My longest code is always image processing. It's usually too hard to break up for the sake of breaking up. There's nothing to reuse between the calls to filters/whatever.

Re:Linear code is more readable by flohofwoe on Friday September 15, 2023 @02:42AM (#37519354)
The default should be reversed, don't break into smaller pieces unless there's a really good reason.
Re:Linear code is more readable by coldtea on Friday September 15, 2023 @03:38AM (#37519784)
>I don't think the fact that a function works well is a good enough reason to write a 2000 line function.

The fact that it works well and reads well (when it does, as in the parent's case), is.

Aside from those factors what else would be against it? Dogma?