DEV Community

Shoaib Akbar
Shoaib Akbar

Posted on

4 2

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

alright, great suggestion

Billboard image

The Next Generation Developer Platform

Coherence is the first Platform-as-a-Service you can control. Unlike "black-box" platforms that are opinionated about the infra you can deploy, Coherence is powered by CNC, the open-source IaC framework, which offers limitless customization.

Learn more

👋 Kindness is contagious

Please leave a ❤️ or a friendly comment on this post if you found it helpful!

Okay