DEV Community

Cover image for How to Write Clean Code: Refactoring and Best Practices.

How to Write Clean Code: Refactoring and Best Practices.

Balraj Singh on November 14, 2024

We’ve all been there – staring down code that should work but is practically unreadable. And let’s be real: every developer (yes, every single one ...
Collapse
 
vitalets profile image
Vitaliy Potapov • Edited

Thanks for the article!
Here is the eslint config, that I use in my projects to follow the clean code rules:

rules: {
  complexity: ['error', { max: 6 }],
  'max-depth': ['error', { max: 2 }],
  'max-nested-callbacks': ['error', { max: 2 }],
  'max-params': ['error', { max: 3 }],
  'max-statements': ['error', { max: 12 }, { ignoreTopLevelFunctions: false }],
  'max-len': ['error', { code: 120, ignoreUrls: true }],
  'max-lines': ['error', { max: 200, skipComments: true, skipBlankLines: true }],
  'max-lines-per-function': ['error', { max: 30, skipBlankLines: true, skipComments: true }],
},
Enter fullscreen mode Exit fullscreen mode
Collapse
 
balrajola profile image
Balraj Singh

Wow. Perfect!

Collapse
 
sami_hd profile image
Sami

Eslint can check this wow. Thanks

Collapse
 
iamlucky profile image
Lakhan Jindam

Good points!
I think refactoring should be done proactively but if it's affecting your deliverables then at least it should be tracked in your project management software otherwise it keeps on piling and becomes a tech debt eventually :(

Collapse
 
balrajola profile image
Balraj Singh

Proactive refactoring is ideal, but when timelines are tight, tracking it in your project management tool is crucial. It not only keeps it visible but also ensures it gets prioritized before turning into a full-blown tech debt crisis. Balancing progress with maintenance is always tricky, but good tracking helps!

Collapse
 
balrajola profile image
Balraj Singh

You're absolutely right!

Collapse
 
nasrulhazim profile image
Nasrul Hazim Bin Mohamad

a great place to learn about refactoring - refactoring.guru/

Collapse
 
balrajola profile image
Balraj Singh

Thanks for sharing!

Collapse
 
strawbang profile image
Djamel Bougouffa

Thanks for sharing these valuable insights.
Clean code is indeed an art that every developer should strive to master!

Collapse
 
balrajola profile image
Balraj Singh

True that!

Collapse
 
anupk1234 profile image
Anup Khismatrao

Great article

Collapse
 
balrajola profile image
Balraj Singh

Thank you!

Collapse
 
ibrahima_diallo profile image
Ibrahima DIALLO

I would like to have more clarification regarding SOLID principles

But nevertheless, this is a useful article

Collapse
 
krowin profile image
KRowin

Good, solid article, now I know that principles I’ve learned without formal coding education have a fancy corporate like names which I can throw around to refactor the discussion. :)

Collapse
 
dev_patel_c343c404fe29262 profile image
Dev Patel

test