Beyond The Code

Apurva
2 min readAug 23, 2021

--

There are people who write code that runs, and then there are people who write good code that runs. Most of the time we’re pondering about what is the difference between the two, when “code that runs” is believed to suffice every need of the industry. However, this is not the case. Whenever you write code, you need to explain it, make it clean and test it. This article discusses about the same.

  1. Writing Clean Code: Writing code is like writing a user manual, or a recipe. While reading a user manual or a recipe, you would prefer a step-by-step demonstration of procedure rather than a complex paragraph. Similarly, while writing code it should be understandable and the intent should be step-by-step accomplishment of the assigned task. The first step of writing clean code is making the code modular. Modular code means dividing the code into modules(functions) where each function performs an assigned task. This helps you to understand the approach and steps of the code. Optimising your code helps to reduce the time taken to execute your code. While writing code, it should be kept in mind that one must write it in such a way that it takes minimum time and space to execute.
  2. Adding Comments to your code: This is the most common yet ignored rules of writing good code. However, if you have ever worked in a group project you would know! Understanding a program or even a piece of code without comments can be challenging, since the reader isn’t aware the purpose of the code. Therefore, after dividing the code into meaningful modules, it is a good practice to describe the purpose of each module and explain the meaning of operations in the module. This makes the code readable and comprehensive.
  3. Testing your code: Testing your code has a number of advantages and serves as a foolproof shield to your code. It is important to understand that while a certain code may work under normal circumstances, it might not work in edge cases. For example, a function with two parameters might not yield appropriate results when one parameter is set to some arbitrary value, or not declared or declared as zero when it works as the divisor(It might throw an exception). Therefore one must think of all possible test cases and test the code against them. Assert keyword in Java and Python are used to test manually whether a function is returning appropriate results or not. Similarly, there are a number of tests that can be performed for your code.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

--

--

Apurva
Apurva

Written by Apurva

Coder by day, poet by night!

No responses yet

Write a response