-
Keep track of what's going on
-
Test each part individually
-
Make changes without unexpected side effects
This is the meaning of the Single Responsibility Principle.
This is a great question, Haider; here are 4 tips I use to improve SRP:
-
Find a good name; often, searching for a good name reveals you have too many responsibilities in your class or method.
-
Writing your tests also helps; if you find yourself asserting multiple things in your tests, that can be a signal.
-
Code Reviews with more seniors help a lot
-
Refactor every time you have the opportunity to improve.