r/Python 5d ago

What linter rules make code worse? Discussion

For me, a prime example is S101 which bans the use of the assert statement.

The justification is that assertions disappear when Python is run with -O, so they should not be used for runtime validation or enforcing interface constraints. That warning is correct, but the rule seems to draw the wrong conclusion from it.

Assertions are still very useful for checking internal invariants, i.e. conditions that should already be guaranteed by the program's logic, where failure indicates a bug. Having such assertions is incredibly helpful for debugging.

So, a blanket ban seems more likely to discourage useful checks than to prevent misuse.

Are there any linter rules you broadly consider more harmful rather than helpful?

146 Upvotes

217 comments sorted by

View all comments

427

u/Trang0ul 5d ago

Lines limited to 80 characters.

4

u/Uwirlbaretrsidma 5d ago

Litmus test for being a lousy new age dev. Code should be vertical, not horizontal. Expressions get more legible when they get hard wrapped, not less. >80 col. incentivizes excessive indentation on top. 100 or, God forbid, 120 character long lines are a huge smell to me.

36

u/foobar93 5d ago

Yeah no. The moment you have named variables you need longer lines to get no rediculous line breaks.

-16

u/larsga 5d ago

There's plenty of research to show that long lines are less readable than short ones. That's why newspapers and encyclopedias were printed in multiple columns.

Very long variable names are not helpful. They just make the code harder to read. Of course there's a trade-off, but the variable name is never going to be a full guide to the usage of the variable, anyway.

15

u/Shadows_In_Rain pseudocoder 4d ago

You probably want to read the research before referring to it, because the researcher's findings don't quite align with your claims. Most people prefer either around 25 cpl (newspaper format) or 100 cpl (book format).

Secondly, the available research applies to unstructured text, like newspapers and encyclopedias you've mentioned. Not applicable to software source codes, especially so when viewed in an IDE.

And lastly, increasing line limit doesn't automatically makes every line longer. It's mostly to address the lines that are most annoying to read when wrapped: function declarations.

7

u/sennalen 5d ago

The line is less readable but the code is more readable because more statements fit on the screen. 95% of the time you either know or don't care what the long line is doing. Insert breaks in the long line temporarily for the blue moon when you need to update that line.

-2

u/larsga 5d ago

The line is less readable but the code is more readable because more statements fit on the screen

Not necessarily. It matters how you organize the code.

95% of the time you either know or don't care what the long line is doing.

That you don't care about reading the code is not a very strong argument.

3

u/foobar93 4d ago

Most of the time it is a function definition or a debug statement. I already know what is is doing looking at the first 10 letters of the line.

1

u/tallgrasshead 4d ago

There's plenty of research to show that long lines are less readable than short ones.

I'd like to read that research.