Why Version Control tho?
Introduction
The one thing that has bought humanity to where it stands now is our ability to document our status at every point. I mean just think about it. At every point , some human before their death passed on what knowledge they had along with what mistakes they made - so that the next generations can build upon it. Science works like that! We record whatever we have now - along with our limitations so that the future us can study and improve it. So one thing we understand - documenting what we have is pretty important,isn’t it?
How this connects to coding
Now lets go into a specific niche- coding. In writing a code - one thing is for sure - the code CANNOT be perfect in one go. If it is - its either a miracle or you are a god. But we can’t rely on either of them. So we make improvements in the code ; and for that of course , we need to change it. But WHAT IF….
We suddenly realize a past version better suited the needs of a client. Ah man got to redo all the work. This is unfair. To be honest I would never wanna do that.
Well then what can we do. I got an idea. At every point when the code is working and we feel this is a safe point - just take a copy of the entire code and paste it somewhere else (say in a versions folder in your disk). Then work on another copy . So that whenever you have another version you can save it too and if you need to rollback - you have for yourself a copy of the entire code and no work needs to be done!!
Wow- problem solved !!…Or - is it?
Now how to submit that final code when your final folder is ready. Well copy it in a pen drive and name it saasfor314 and hand it over VERY politely to your manager as you sit down for digging into another personal project of ricing your Arch Linux setup. But guess what - the client is not satisfied. They wanted blue color - how can you forget that. Okay now this time just get it back and correct it - submit saasfor312_final and…wait what - not satisfied still . Okay… saasfor312_final_complete..
You see the English grammar is patient enough to provide you with enough combinations to extend it indefinitely - but not my sanity. We need something better.
And that’s not all !!
Because coding is not a single man sport. Its a team sport. And we need to account for other team members for where one guy will have the authentication page ready while your female colleague is working on the design and front end . Now they both need to make changes! How will they work on it together.
Imagining each one having their own version in their own system sharing files by the name of -
divit_auth_final-3.2.100%final.js
shalini-blue-button_addded.jsx
And sharing them in pen-drives - even in same room - would become hectic - so forget about your dream remote job.
You know someone’s got to hire another person to maintain all this.
Okay I mean email looks like a solution but still - who’s gonna handle all this mess?
And now god forbid - GOD FORBID if two developers need to work on the same file - just imagine the sheer amount of universal collapse that is capable of causing to the entire system.
I mean take this code for an example.
int n=date.now()+5*1000;
//wait 5 seconds
while(date.now()!=n)
{
wait(1000);
}
Now here in this code - a simple mistake of a single symbol can cause this to go into an infinite loop (think how I will reveal the solution at the end of the blog).
Now just imagine if a single symbol could cause this much chaos - how much can working on the same file break?
And say if the code does break - well how do you as a manager know who to fire? I mean we gotta save the company as much as we can right?
So like what do we even want?
Like I personally wish there was a system which could:
- track my project history for me (with efficient storage if possible)
- track what changes are there compared to the last version and when were they made
- track what changes were made by whom
- ensure when two “versions” of same project file meet - they can be effectively looked over as to what sections are conflicting and doesn’t move forward until we manually resolve them - I mean it doesn’t seem very easy but hopefully we can do something about it.
Well guess what?
It exists!! And that is what we call a version control system - out of which Git is the most popular being used today by almost everyone who works with coding or programming in general.
/*Answer to code problem - we need date.now()<n because we need to break it when time goes more than or equal to n - so we need < sign instead. (because processing delay can cause change in time in orders of 1ms which could technically break this code) */