14 Comments
User's avatar
Raul Junco's avatar

Clean Functions are the foundation of Clean Code!

Well explained, Daniel!

Expand full comment
Uriel Bitton's avatar

These are amazing tips.

Clean code is a great book one I've enjoyed thoroughly!

These tips are a great reminder of clean code lesr we forget after years of habit!

Expand full comment
Saurabh Dashora's avatar

Amazing tips Daniel!

Expand full comment
George's avatar

Clean code explained, nicely. I 'll leave only this as food for thought:

Regarding the fewer params in a method, sometimes it might not be the best practice.

Assume you are a consumer app and you have 2 different domain objects to handle, you might not want to couple these 2 different domains together and passing primitive params can be more beneficial.

Another case is when writing performance-first operations, creating objects could add redundant overhead.

Expand full comment
Bilal Ben Benyoussef's avatar

good article, thanks

Expand full comment
Ansharah Asif's avatar

Thanks for the sharing. Great Tips!

Expand full comment
Делян Маринов's avatar

I agree too many parameters to a function can be furstrating, but passing "the whole jungle" just to take "one banana" from can be even worse. I would pass 5 params or if you need to get those 5 params from 5 objects I'd rather think for some DTO that would fit the bossiness case better. Thanks for the reading ☺️

Expand full comment
Wana's avatar

In all areas Cleanliness is next to Godliness

Expand full comment
Aniket Gupta's avatar

i think everyone uses boolean param functions. IMO the suggestion you have given is awesome. The second best part was, it is not at all necessary to break down a function to too many small function, rather identify the functionality.

Can you also give some information about pure functions?

Expand full comment
Mirza Abazovic's avatar

IMO "Instead of booleans, use Enums, making your code self-documenting."is

use two functions with descriptive names (follow the rule 2).

Usually when You have boolean as param in function You have inside "if" and if You replace it with enum logic will stay (some kind of "if")

By dividing into two functions

It will make your function logic simpler and function will be more SRP, and you will avoid complexity in function.

It helps with rule 1 - keep them smaller.

Of course follow also DRY for code that is the same in two new functions (maybe there is a smaller third one function inside)

Expand full comment
Fejan Malek's avatar

Great post this is really helpful for the monolithic architecture

Expand full comment
Recep Taylanhan's avatar

Clean code is really important for a long term big project. I also shared my thoughts on writing clean code on Medium. Hope this will help https://levelup.gitconnected.com/clean-code-ready-to-fix-your-javascript-code-825deef7db72

Expand full comment
Bilal Ben Benyoussef's avatar

good article

Expand full comment
Ravi Raizada's avatar

I also have written something along the same lines @Daniel Moka, please check once and suggest any new ideas.

I am new to Substack and passionate about clean code.

https://open.substack.com/pub/raviraizada/p/how-to-write-clean-and-maintainable?r=44lxf&utm_campaign=post&utm_medium=web&showWelcomeOnShare=true

Expand full comment