Monday, October 2, 2017

Code Readability and Maintainability



Maintainable code is code that exhibits high cohesion and low coupling.
  • Cohesion is a measure of how related, readable and understandable code is.
  • Coupling is a measure of how related code is, low coupling means that changing how A does something shouldn't affect B that uses A. Generally lower coupling means lower cohesion, and vice versa, so a developer need to find an appropriate balance between the two.

Maintainability is itself a measure of the ease to modify code, higher maintainability means less time to make a change. Coding standards are a way to achieve high maintainability and are developed as a result of previous experiences, they aren't universal and are dependent on developer preferences.

However, the acid test of maintainability is attempting to change the code. To the extent that the code resists, or doesn't resist, your interaction with it defines it's maintainability.

Maintainability has "abilities". Including, but not limited to
  • readability
  • understand ability
  • changeability
  • testability
  • reliability
How do we attain these abilities?

Through application of all those software principles and guidelines you've ever or maybe never heard of.

 For example:
  • Good comments
  • descriptive variable, method, class names
  • Limit methods to no more that a page in length
  • Maximize cohesion and minimize coupling
  • encapsulate that which stays the same
  • encapsulate that which changes
  • code layout/formatting guidelines applied consistently
  • One entry point only, and one exit point only.
For good maintainability one must consider all of them, all the time, at every level of the code, and apply them in an (not "the") appropriate mix. 

No comments:

Post a Comment

My First Day with Uki DN Cohort 1

 "Hello WORLD!"