DEV Community 👩‍💻👨‍💻

Shoaib Akbar
Shoaib Akbar

Posted on

Writing Functions (Uncle Bob's principles)

Some principles to write functions from Clean Code book

  1. The first rule of functions is that they should be small.
  2. The second rule of functions is that they should be smaller
    than that (upto 20 lines of code)

  3. FUNCTIONS SHOULD DO ONE THING

  4. Function Arguments

  • Better if no argument

  • Functions should have maximum of 2 arguments

  • But arguments should not be exceeded by 3
    (They take a lot of conceptual power)

  • It should has same level of abstraction
    (1 level of abstraction)

  • Passing a boolean into a function is a truly terrible
    practice. (Flag as argument)

Keep Learning!!

Top comments (2)

Collapse
detzam profile image
webstuff

You should go deeper and continue this article using a example

Collapse
shoiabakbar profile image
Shoaib Akbar Author

alright, great suggestion

🌱 DEV runs on 100% open source code that we started called Forem.

 
You can contribute to the codebase or host your own.