this post was submitted on 05 Jan 2025
60 points (90.5% liked)

Programming

17760 readers
499 users here now

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person's post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you're posting long videos try to add in some form of tldr for those who don't want to watch videos

Wormhole

Follow the wormhole through a path of communities [email protected]



founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 4 points 18 hours ago (1 children)

I think to present rules like this as hard rules, with little explanation and no nuance is harmful to less experienced engineers.

A prime example here is the Duplicated Code one. Which takes an absolute approach to code duplication, even when the book that is referenced highlights the Rule of Three:

The Rule of Three
Here’s a guideline Don Roberts gave me: The first time you do something,
you just do it. The second time you do something similar, you wince at the
duplication, but you do the duplicate thing anyway. The third time you do
something similar, you refactor.
Or for those who like baseball: Three strikes, then you refactor.

I've seen more junior devs bend over backwards, make their code worse and take twice as long to adhere to some rules that are really more what you'd call guidelines than actual rules.

Sure, try to avoid code duplication, but sometimes duplicating code is better than the wrangling you'd need to do to remove it.

Making extra changes also leaves extra room for bugs to creep in. So now you need to test the place you were working, and anywhere else you touched because of the refactoring.

[–] [email protected] 1 points 13 hours ago (1 children)

Well it's in the name, they are code smells, not hard rules.

Regarding the specific example you cited, I think that with practice it becomes gradually more natural to write reusable functions and methods on the first iteration, removing the need for later DRY-related refactorings.

PS : I love how your quote for the Rule of Three is getting syntax highlighted xD (You can use markdown quotes by starting quoted lines with > )

[–] [email protected] 2 points 7 hours ago

The site doesn’t define what a code smell is, though. It’s just a list of Don’t Do’s.

That’s kind of the nuance I would be hoping for.

Something like:

Code Smells are clues that something is amiss. They are not things that always must be ‘fixed’. You as an engineer will, through experience in your own codebase and reading of others, develop a sense of the harm imparted by and the cost of fixing Code Smells. It is up to you and your team to decide what is best for your codebase and project.

(The rule of 3 formatting was intentional, given the community we’re in)