Comment by eviks
11 hours ago
> Limit line lengths: Keep lines within a reasonable length (e.g., 100 characters) to ensure readability. This prevents horizontal scrolling and helps maintain an accessible code layout.
Do you not use word wrap? The downside of this rule is that vertical scrolling is increased (yes, it's easier, but with a wrap you can make that decision locally) and accessibility is reduced (and monitors are wide, not tall), which is especially an issue when such a style is applied to comments so you can't see all the code in a single screen due to multiple lines of comments in that long formal grammatically correct style
Similarly, > Limit function length: Keep functions concise, ideally under 70 lines.
> and move non-branching logic to helper functions.
Break accessibility of logic, instead of linearly reading what's going on you have to jump around (though popups could help a bit). While you can use block collapse to hide those helper blocks without losing their locality and then expand only one helper block.
> which is especially an issue when such a style is applied to comments so you can't see all the code in a single screen due to multiple lines of comments in that long formal grammatically correct style
It’s easier to hide comments than do code wrapping correctly. And comments are usually in a lighter color than code and easy to skip over.
> Break accessibility of logic, instead of linearly reading what's going on you have to jump around (though popups could help a bit)
Extracting function is for abstraction, instead of deciphering some block and tracking its entanglement, you have a nice name and a signature that document its input and output. And maybe a nice docstring that summarizes its purpose.
It does require taste and design skill.
> a lighter color than code and easy to skip over.
How does color and the ease of skipping address the fact that you don't see code because it's pushed off screen? Especially compared to the ease of skipping when you wrap the whole paragraph of comments into a single long line when you don't need to read it.
> And maybe a nice docstring that summarizes its purpose. Which you could just as well have right there where you read the block.
The nice name/signature yes, that can be situationally better
There’s place where you can break the code before 100 or even 80 line limit. And the only reason that you cannot do so with code is excessive indentation (nested scope). Which you will find easily in very long functions.
> Which you could just as well have right there where you read the block.
A function forces encapsulation and make explicit the external factors. A block doesn’t make clear which variables in the parent scope it’s using or if everything in the block is one logical step.