Software writing best practices

Software engineering is made to put rules to developers and programmers to write code in a better way to make it readable, re-usable, easy to modify, to add, to upgrade, and to maintain.

Here are some practices that we should to avoid, instead we have to use software engineering principles to ensure a better code writing

1- Avoid Code duplication, use re-usability instead

Duplicated code is hard to maintain, when bugs are discovered we should fix it in all duplicated code, sometimes part of duplicated code might forgotten so that an in-consistent behavior could appear in that module.

Re-usability relies on abstraction, we have to do abstraction for methods and units to become more reusable, and put it in an accessible unit and share it with other modules. Reusability also could be done as web services level, to write reusable web services among different modules and different systems.

2- Avoid large and complex methods and modules, use single responsibility principle instead

Large methods that contains nested if conditions, and complex units or modules that has multi function is hard to maintain and to understand , it increases the possibility of bugs when modifying code.

Single responsibility principle aim to write smaller methods for single functionality, units and classes has to be written to encapsulate one business function, such as user management class, an authentication class, and different user interface class which represents different layer (presentation layer).

3- Don’t expose your sensitive data and functions, use information hiding

Sensitive data such as databases, files, and lower level methods has to be private, and higher level of modules or other systems should access it through interface to ensure that all consumers (calls for that functions) have go through business logic. direct access to that data and private methods might result in violating business and security rules

Information hiding divides code into two sections: private section that you don’t want others to access it, and interface section, in which you provide the formal access to class/unit functionality. Such interfaces could be public methods or web services Interface.

If one system requires information or want to execute functionality in another system, it has to access it through a web service which ensures executing business logic and security permissions, also it hides details of lower technical specifications such as database engine type. If we modify any details such as database location or engine; consumers shouldn’t be affected if they use proper Interface.

Encapsulation is a tool or methodology to implement information hiding

4- Avoid coupling, do de-coupling instead

Coupling means dependency of a module on another module, or method in another method, or a system in another system. Coupling reduces re-usability because it prevents using of one module or part of code without taking the other dependent module or part

De-coupling minimizes code units relying on others, and makes it independent, easy to modify, it becomes portable and reusable in other modules or systems without modification

This document is still draft, more information or modification could be done later

Motaz

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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