Software engineering principles, best practices & introduction to JavaScript.
In this article, i will give you an overall idea about software engineering principles and a quick introduction to JavaScript.
Software engineering principles
Software engineering principles are a list of approaches and best practices introduced by industry experts in the software engineering field. These principles will help you to make quality software products. Let’s take a look at some of the software engineering principles we should follow.
1. S.O.L.I.D
S.O.L.I.D is a list of 5 object oriented design principles. Let’s go through them one by one.
Single responsibility principle — Every function or class should have only one single responsibility. This makes our code easier to understand, maintain and modify.
Open/ closed principle — We should write our code in a way that they are open for extension but closed for modification. That means we should be able to add new features to our code without breaking existing code. And also we should avoid making changes that will break existing functionality.
Liskov substitution principle — The objects of a subclass should behave in the same way as the objects of its super class.
Interface segregation principle — Our code should not be forced to depend on methods that it does not use. We can achieve this by splitting large interfaces into smaller and more specific interfaces.
Dependency inversion principle — Avoid tight coupling between high level and low-level modules. This makes it easier for us to modify our code.
2. KISS — Keep It Simple, Stupid
Try to make your system simple as possible. Avoiding unnecessary complexity will make your system more robust. And it will make it easier to understand and extend the system.
3. DRY — Don’t Repeat Yourself
Avoid writing the same code/ configuration in multiple places. You can achieve this by inheritance, composition and database normalization.
4. YAGNI — You Aren’t Gonna Need It
Avoid implementing things that has no use in the present. Always implement things when you actually need them. It will help you to keep your code simple.
5. DRITW — Don’t Re-Invent The Wheel
If someone has already solved the same problem, make use of it. It will save your time and money.
Now let’s take a look at some of the best practices we should follow in software development.
- Unit Testing
Unit testing is the testing of a single function, class or module in a software application. Unit testing is important because it helps to find and fix bugs very quickly. It also increases the speed of testing and makes development faster in the long run. Any defect in the code can be easily detected by writing good unit test cases. White-box testing, Black box testing and Gray box testing are the techniques in unit testing.
Popular tools for unit testing — JUnit, JTest, NUnit, JMockit, EMMA, PHP Unit
2. Code quality
Code quality defines code that is good and code that is bad. Code quality is subjective and there is no one specific way we can measure it. However, code quality is very important as it affects the overall quality of a software product.
Code that is good (high quality code),
- Does what it should.
- Follows a consistent style.
- Easy to understand.
- Well-documented.
- Can be tested.
Reliability, testability, maintainability, portability and reusability can be considered as some of the key code quality aspects to measure. We can use code quality metrics such as defect metrics and complexity metrics to quantify the quality of our code.
Popular tools for measuring code quality — Helix QAC, Klocwork
3. Code review
Code review is a software quality assurance approach where one or several people check the source code of a program with the aim of improving the quality of the code. When code review is done correctly it can save time and reduce the amount of work required later by the QA team.
Common code review approaches
The Email Read — Sending the source code file to the appropriate colleagues via email for each of them to review.
Pair Programming — Two or more developers work on the same code and check each other’s work as they go.
Over-the-Shoulder — Asking a qualified colleague to review your code while you explain why you wrote it.
Tool-Assisted — Using software tools to review the code.
Popular tools — Github, Gitlab, Bitbucket, Azure DevOps
4. Version controlling
Version control is a system that manages changes to computer programs. Version control systems record changes to a file or a set of files over time allowing you to recall specific versions later. Version controlling is important when a software product is developed by a group of developers.
Benefits of version control systems
- Increase the speed of development.
- Reduce errors and conflicts.
- Developers can contribute from anywhere.
- We can see who, what, why, when changes have been made.
Types of version control systems,
- Local Version Control Systems
- Centralized Version Control Systems
- Distributed Version Control Systems
Popular version control systems — Git, Bitbucket, Mercurial, AWS CodeCommit
Introduction to JavaScript
JavaScript is an interpreted, prototype-based, single-threaded, dynamic programming language which supports object-oriented, imperative, and declarative programming styles. JavaScript is most well known as the scripting language of web pages. But using non-browser environments like NodeJS we can also develop server side applications with JavaScript.
The core client side JavaScript language allows you to,
- Dynamically update page content
- Control multimedia
- Animate images
- Running code in response to certain events occurring on a web page
- And many other things.
The following browser APIs allow you to do many amazing things with JavaScript.
The DOM API — Allows you to manipulate HTML and CSS. You can use this API to dynamically create, remove and change content and styles of a web page.
Geolocation API — You can use this to get geographical information.
Canvas and WebGL API — Allows you to create 2D and 3D animated graphics.
HTMLMediaElement and WebRTC — Allows you control multimedia and many other things.
How to add JavaScript to your web page.
- Internal JavaScript
You can write your JavaScript code inside a <script> element in your html.
2. External JavaScript
You can write your JavaScript code in a separate .js file and then include it in your html.
This is just a brief introduction to JavaScript. In future articles, we will dive deep into JavaScript and its frameworks.