Code limit 10.20.300

For any intermediate developer It is comparatively easy to write any block of code as per the requirement or business logic but the things which needs to be targeted first while writing code includes readability, testability and maintainability.

Every new developer might have done a mistake of dumping lot of code in one method or lot of irrelevant code in one class. Some automatic code analysis tools like SonarQube can warn us to reduce method lines up to 30 or reduce lambada expression lines or limit cases in switch block etc.

10-20-300 has following interpretation,

10 : Strictly no more than 10 attributes in any class.
20 : Strictly no more than 20 lines in any method.
300 : Strictly no more than 300 lines in any class.

10-20-300 rule can stop from dumping more code in any class and can ask developer to look for an alternative or it sometimes just sends a signal “time to re-factor”.

To be honest, such things can not be followed too strictly or can not be considered as a rule of thumb. This does not make you write maintainable or readble code but as you limit your code at first place, it will start making difference gradually.

This digits should trigger that you are moving in a way to increase the possibility of creating problem in either maintainability or readability. Because no developer praise the code which is hard to modify and difficult to interpret. This digits are totally based on my experience and does not have any concrete research base. The effectiveness of digits can vary up to some point as per the scenarios or use cases.

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s