How to Excel in Programming

How to Excel in Programming

I have been asked this question so many times — “Am I a good programmer ?” I always say “It depends”. Programming is an art and a good code is no less appealing than a nice brush work on the canvas. With technology changing drastically, there are a lot of new concepts to learn, however, I believe the key principles always remain the same.

Image for post

Photo credit —

I have been asked this question so many times — “Am I a good programmer ?” I always say “It depends”. Programming is an art and a good code is no less appealing than a nice brush work on the canvas. With technology changing drastically, there are a lot of new concepts to learn, however, I believe the key principles always remain the same.

After being in the engineering line for a while, and working for reputed companies, I can share my experience on few good principles of writing a satisfactory code, and how to always improve along the way

Instead of Copy-Paste, Copy-Understand-Paste

This is a very core and basic principle and is more applicable nowadays when you will get the solution to most of your problem online. Let me share a small example from my life.

In the early 2000 I was working in unix and shell scripting. While analyzing some data, I had to do a group by on a fairly big data set. AWK was very popular to do this kind of quick analytics. So I searched in google — “Group by with awk”. There came my solution

awk '{arr[$1]+=$2} END {for (i in arr) {print i, arr[i]}}'

I quickly pasted this into my terminal and voila — there’s my output. I tested and verified the code on small data set and did not have to change anything. Wow my luck. It was a big thing those days to get perfect results from Google. Being in the same project for a while, I needed this command for multiple times, and like the first time, I google and got my results. Then one day, I needed this command, but there was a slight change — Internet was down. I had no clue on how to logically write the “group by” using AWK. I understood the reason why — I had never, not even for a second tried to understand how the code works. I finally wrote the command myself, but from then on, I put an extra stress on understanding the piece of code that I copy from the internet even if it blindly works. I understand the above may a very minor problem, but it is the way of thinking that is more important. Although, google search is one click away, every time we copied something from the internet, we have a chance to learn and understand something new. In the race to deliver our results, we often forget to pause and understand what we are doing. I guess this could be applicable for the general life itself, but now thats a bit too philosophical. Let’s not go there.

Unit Tests

A beginner or novice engineer may not appreciate the importance of a test case. However, anyone who has been stuck in this line of work for a while will tell you the importance of writing test cases. There are few major reasons why test cases are very important for a nice and durable piece of code:

→ Prevent introducing bugs: In a large organization, there is no guarantee that the person who wrote the code will make all future changes. Sometimes lot of folks work on the same code. Adding more and more code will introduce bugs to some untouched piece of code. Having test cases for each modules and and each conditions increases the changes of catching and debugging these issues early.

→ Making the code modular: Unit Test are written for each unit / module of code. This makes the developer modularize the code, rather than writing all the code in one block.

→ Reusability and Reliability: By unit testing, individual components become isolated from each other, making the codes are more reliable, since it’s been tested in a contained environment. This also makes the code more reusable. This again ties back to the previous point of making code modular.

Adding Comments:

One of the most simplest and easiest change that one can do in their code is add comments. Adding comments help future developers to get a grasp of what this piece of code is supposed to do. By adding comments, I do not mean going back and adding comments after the coding is done — it should be written before the class / method is written. Ideally, each class and method should have a comment. I would also add comments to complex logic to explain why I did it this way. This would help others understand and propose a better way without going through the code at all.

Always Write to an Abstract class:

This is a principle I try to follow to make my code modular. This is mostly prevalent in OOP. Let us look at an example to understand the idea behind this — Suppose you re given a task of writing a data to text file. The easiest option is to define a method SaveToText and call this method.

code programming engineering

Bootstrap 5 Complete Course with Examples

Bootstrap 5 Tutorial - Bootstrap 5 Crash Course for Beginners

Nest.JS Tutorial for Beginners

Hello Vue 3: A First Look at Vue 3 and the Composition API

Building a simple Applications with Vue 3

Deno Crash Course: Explore Deno and Create a full REST API with Deno

How to Build a Real-time Chat App with Deno and WebSockets

Convert HTML to Markdown Online

HTML entity encoder decoder Online

13 Free/Low-Cost Sites to Supercharge Your Programming Self-Education

Although we still talk about programming as a standalone career, the dominance of technology in our lives makes it clear that coding is much more than a career path. In my opinion, computer science is more than a college major or a high-paid job; it’s a skill, essential for thriving in a modern-day economy. Whether you work in healthcare, marketing, business, or other fields, you will see more coding and have to deal with a growing number of technologies throughout your entire life.

How to Structure Your Programming Code

I remember my first fumble with basic on my ZX Spectrum computer back in the 1980s, ploughing through pages of basic commands and example code without any real idea of how I could write programs myself

What Is Code Golfing And Biggest Such Tournaments

Code golf is a type of recreational computer programming competition in which participants strive to achieve the shortest possible source code that implements a certain algorithm. Playing code golf is known as "golf scripting". Code golf challenges and tournaments may also be named with the ... Some code golf questions, such as those posed on general programming ...

Coding 101: Programming Language Building Blocks

This article will introduce the concepts and topics common to all programming languages, that beginners and experts must know!

How to tell if your code actually sucks...

There is no better moment for me than starting a brand new project. Everyone is afraid of adding or removing stuff. I guess we all have known at least one project that anyone wants to touch, or heard the phrase:.