Programming nuggets : Modifying us !

Programming nuggets : Modifying us !

It is somewhere around level 2 in programming concepts, when you learn about for and while loops. They explain about how things can progress by themselves from one state to another, one instruction at a time. For the ones who are not very clear about what these looping techniques do, they are a feature in programming which lets you do something over and over again as long as you want it to be done. 

for (initialisation; termination check; modifier){

//something to do here

}

One of the things I have done quite often is forgetting to modify the iterator. I am sure the programmer in you is cringing just like I am right now. And we all know what happens when that is forgotten. The system goes into an infinite repeat of whatever the loop was expected to do and it is executing as long as system resources let us, the UI stops responding, there is no memory left or it just ends up doing the exact same thing for as long as it can with absolutely no change at all. 

These are called infinite loops. Quite dreaded ones because they clearly point out that you weren’t listening in the class when your programming professor was explaining the nuances of a for loop or about how snuggly and why an increment or decrement operator fits. 

But the disastrous consequences of an infinite loop wasn't what struck me on that fine sunny morning. It was about how similar a for loop is to our personalities. Think about this. What happens if you don't change the iterator. Assuming the variable is non volatile, whatever lines of code you wrote inside the block is what will be executed. Over and over again without any change. No matter how times you stop and start, it will continue to be the same. The same results over and over again. 

Isn’t that pretty much how our personalities also are? Not just personalities but any aspect in our lives. If you do the same thing over and over again, without modifying anything, the results are never going to change. As Master Shifu said, ‘ if you continue doing what you have been doing, you will never be more than what you are.’ (Or something like that).

If you continue to eat unhealthy food over and over again with no change, you will continue to fall sick. if you think negative of yourself , you will continue to feel bad about yourself and hence attract negative people in your life. Or like in my case since I continue to leave at 7.10am from my home everyday, I continue to miss the 7.13am bus everyday.

for ( me = version1.0; me <= v2.0 ;){

Me doing something that makes me = me

}

Of course, a lot of the consequences are based on what we write within the block of our loop. But are all things in our control? A key part of this is the non volatility aspect. Non-volatility in programming tells the compiler to not optimise that part of the code because it is susceptible to unpredictable changes from an external entity. The earthly definition of non-volatility is not changing unpredictably. And then there is the same thing in our lives. It is next to impossible to say that the events in our lives will not be impacted by an external agency. However, it is quite possible that the key results we intend to have will not be impacted by anyone else except ourselves. If the bus driver decides to come a couple of minutes later from tomorrow, I can still make it to the bus without changing anything. But that never happens. My bus driver is never that considerate. 

You may feel that there is a positive angle to this. Unlike programming, where usually infinite loops are treated as black holes and are detrimental to the program, infinite loops in our lives can bring out good things. Possibly? For example, if you have the habit of running 5 miles everyday, and continued doing that with no change, it is no doubt that you will develop a fitter body albeit you will have quicker worn out shoes. 

However the positive aspect is not definitive. For example, experiments show that if you continue running for 5 miles everyday, your body gets used to it and stops reacting as effectively as it did in the initial days. I wouldn't know, I have never managed to run 5 miles for more than a day. But presuming they know what they said because they are the experts, their recommendation is to change the routine regularly so that the body continues to react the same way as before. Change being the keyword here. 

for ( me = version1.0; me <= v2.0 ;){

let me do something that makes me = me++

}

Of course, where there is a positive there has to be a negative. Extra brownie points for guessing what happens if there is a change but in the opposite direction. What if you changed the value but the value is now a vector and there is a direction associated with it which is the exact opposite of what you need for termination, to move to the next step of instruction. Does this change in direction/vector make a difference? It probably does but that really depends on what the termination check is. 

To sum it up, is the fact that we can move ahead in our lives based on what we write within the parentheses of the for loop, a philosophical thought or another indication of us being mere lines of code? That is for another blog. But it is comforting to know that to change our lives all we need to do, is to not forget to modify the iterator. 

Happy Weekend !



To view or add a comment, sign in

More articles by Dhivya Raj

Others also viewed

Explore content categories