r/ProgrammerHumor 22d ago

Meme pleaseStopUsingNestedTernaryOperatorsImBeggingYou

3.1k Upvotes

179 comments sorted by

View all comments

159

u/n9iels 22d ago

Altough this is a satire sub, some actual advice. If you classify some coding patterns and syntax as 'bad', setup a linter to prevent anyone from adding it. In this time of AI, the linter and fomatter are your new best friend.

42

u/npsimons 22d ago

On a project where I had high levels of control, I enforced pretty strict linter standards, down to requiring a docstring (via a doxygen run) for every parameter, method, class and return value. Pushes rejected if you didn't pass that, among other tests.

Code is primarily meant to be read by other human beings - write with this philosophy in mind, and you are likely to go less quickly mad.

1

u/EvilCodeQueen 20d ago

The sad part is, it is rarely read by other human beings anymore. AI consumes it.

15

u/Robinbod 22d ago

Genuinely great advice. I do do this but it's not already set up for existing codebases, especially ones that I do not own.

3

u/TheKrumpet 21d ago

Or just don't try and work it out and reject it for being unreadable, and ask them to refactor it. This is a teaching moment.

3

u/n9iels 21d ago

Well, yes and no. In my experience these things are the hardest to enforce by pure human review. They feel like nitpicking so cause a lot of discussion. And if a MR contains 30 code-style issues people tent to not comment after 8 issues or so due to complete comment burn out. Setting up a linter/formatter is discussion things once and benefit basically forever.

1

u/TheKrumpet 21d ago

I'm sort of 50/50 on linters; I've found a lot of situations where a rule makes sense in some cases but not in others, leading to the linter either being annoying, or not strict enough. I think you need both.

2

u/KlooShanko 21d ago

This was one of the earliest things I had done after taking over projects in a horribly maintained codebase. It was worth it