The difference between good code and great code is the involvement of coding standards, patterns and principles. Let's go through the meaning of each one by one.
-
Coding Standards: Standards give us rules to follow such as whitespacing, file structure, indentation, etc. This is very important in collabarative environment. Choose a standard, make code consistent!
-
Coding Principles: These are philosophies of code. Examples are SOLID, KISS, If Ain't Broke Don't Fix It, keep it DRY, Separation of Concerns, etc. etc. I will cover important ones individually.
-
Design Patterns: These are to best suit the architecture of our software There are basically three categories of Design Patterns: a. Creational Patterns: Help us to make and control new object instances. eg. Factory pattern
b. Structural Patterns: Deals with how we interact and manipulate our object instances. eg. Adapters, Bridges, etc.
c. Behavioral Patterns: Focuses on how code functions and communicates with other parts of code. Eg. Observer patterns.
I will be covering details of each in upcoming blogs!
Generic tips to write better code:
- Avoid encodings.
- Don't use acronyms for variable names.
- Use clear names, be descriptive.
- Use constants for hard-coding.