How to code — 1 ?

Thalapathy Krishnamurthy
2 min readOct 2, 2019

--

In the beginning was data and then came code.

I will write a series of blogs on ‘coding’. The idea is to take a journey by writing code for various problems and learning the gems as we go.

Before you go ahead, I must warn that ‘coding is not all that easy’ as is being portrayed. It is boring, tedious, gets messy and harder to fix as time goes by. I would like to show you in reality how it happens and not to pep you up to write meaningless example code. We will do it the serious way, the way you release software for real use.

One of my pain areas in my daily life is that of backing up my folders on my PC onto a external drive. Every time I have to copy these folders, wait for the whole thing to complete and then remove the old copy from the external disk to free up its space.

I would like to write a program, let us call it bakitup, that will do this copying automatically. This is really easy. Let us describe the steps by a pseudo-code.

Get the input folders containing the files to backup, as input from the user. Get the output folder or the destination where the files of the input folder need to be copied. This is normally the external hard drive. This is also given by the user as input to bakitup.For each input folder, find the files under them. 	If there are folders, then find the files under those folders and so on, until all the files under the given input folders and its sub-folders are obtained.	Maintain the folders and files / folders under them in a key — value map. This is because when we copy these to the destination, we need them to be in the exact way it is appearing in the source or the given input folders.for each key in the map (folder) do the following to copy the folders and files under them into the destination to create the backup.	Create a folder under the destination folder with the same folder name (in the key of the map).	for each file under this folder in the map, 		Read the file. This brings the file contents into memory from disk.		Write the file under the destination folder created.

I am 100% sure you did not read the above. See how boring it starts to become already. I just showed you a direct pseudo code to go closer to coding.

If we translate the above pseudo-code into a python code, yes, we will use python in this series, we have our first version of bakitup.

But before we get to the code, see post 2 where I talk about expanding on the business requirement into technical requirements.

--

--

Thalapathy Krishnamurthy
Thalapathy Krishnamurthy

No responses yet