How to code? — 4

Thalapathy Krishnamurthy
3 min readOct 15, 2019

--

Human brain is good at generalizing things. Code is born inside it.

See post-3 for background.

I will summarize the requirements in a more succinct way.

1. Bakitup is a backup and restore application for Windows 10.
2. Bakitup allows the user to configure the source and target folders and the frequency of backups.
3. Bakitup should maintain the state of the backup to restart from the last backed up point when it runs again.
4. Bakitup should backup all modified files ordered by their modified timestamp.
5. Bakitup should not restore files that have a later modified timestamp than their backed up timestamps.
6. Bakitup should run automatically as per the frequency set by the user whenever the user turns on the PC.
7. User can intervene anytime and decide to trigger a backup of configured folders or new folders by adding them.

Now the list above looks more rounded and we can move ahead with the coding.

But hang on. There is one more question. We say bakitup will run on PCs. And we also say it should back up on an external drive. Why not we backup the files onto the cloud? What if someone does not have an external drive? Should we not allow for backup to cloud, say a dropbox or a google drive or onedrive?

This brings an interesting aspect of coding or design called ‘Abstraction’. The target where we backup can be anything. We may choose to support only an external drive to begin with. The difference lies in the way we code this portion which copies the files to the destination folder. We will do this in such a way that new backup destinations like cloud can be later supported by plugging in dynamically without causing a re-coding of the bakitup application.

To give you an idea of how we can achieve this,

Assume the target storage or drive where files are copied are passed into the bakitup with a prefix that denotes the store. For example, if we tell that the target is od:\mybackup, bakitup will call the one drive plugin. Or if the target is specified as gd:\mybackup, bakitup will call the google drive plugin. The prefix is mapped to the function or library or the chunk of code that specifically knows how to copy files onto that target store and this mapping is maintained outside of the bakitup application in a configuration file in JSON as

{
"od":"onedriveBackup"
"gd":"googledriveBackup"
}

The above is just a sample to show function names that can be dynamically called by bakitup based on configuration. There is more to it in terms of defining the function signature, deciding the authentication (sign in) to those systems etc. We will come back to it more on this. For now, we will assume that we need to code this portion in a way that it does not restrict us to only do backup on a external hard drive.

By now, you would have started realizing that, coding is not just about mastering a programming language. It is more about the problem you are trying to solve and thinking about the different aspects of it to define the scope or boundary, consider interesting future extensions and allow for it while coding, drop things that are not immediately important and may need more time to understand, identify things that are absolutely needed and so on.

We will write code in post-5.

--

--

Thalapathy Krishnamurthy
Thalapathy Krishnamurthy

No responses yet