Avoid creating god classes and long methods

Clean Code #3

As you gain experience as a developer you start to see repeating patterns that crop up over and over again in your solutions.

When you use chunking (design patterns, algorithms and standard functions) appropriately, it allows you to stop thinking about how the code you write does something and instead think about what it does

Source: Why Your Code Is So Hard to Understand


One class should do one thing not everything like StatusChanger or StatusManager, not StatusGod

Keep classes small, a 1000 line class is a pain



Avoid using and in method names like validateAndSave, one method needs to do one thing and one thing well

Don’t Repeat Yourself

There should be one — and preferably only one — obvious way to do it.

~The Zen of Python, by Tim Peters

Lines of Code

Keep methods small, a 50 line method is a problem.

My rule of thumb is: The method should not be more than the size of my screen. (Source: Jeremy Howard fast.ai)

Passing variables

Keep the instance variables as low. If you are passing 4,5 variables you are probably doing more than one thing

Pass an object instead of multiple methods

Don’t pass the variables that you don’t need.

If creating an object requires multiple steps

Convert it into a factory method

Previous: Leave clues (Naming convention)

Next: Make database do the heavy lifting

Index: Tips on writing Clean Code



Ankush Choubey: Full Stack Dev-Cloud/Microservices

25 y.o full stack developer from Mumbai who loves Full Stack Development and Deep Learning. Original Blog at ankushchoubey.com