theInsomniacGameMaker

View Original

Copy-Paste: Almost a Boon to All

I was taking my Data Structures and Algorithms class. That day’s lecture was about creating a Singly Linked List in C++. Coming from C#, and being relatively new to C++, some concepts were tricky to understand. The unfamiliarity to the C++ realm made me a little tense when coding in C++.  

I had written most of the code for making the Singly Linked List and I was running my code through the unit test given to us by our instructor to check our work.

While running the code, the program would just ignore an if-check. I started the normal debugging process but to no avail. I used the Visual Studio Debugger to run through each step in the whole script to see why I was skipping the if-check, but even the debugger would just skip over it.

My code was

if (listCount == 0);
{
    isListEmpty = true;
    ......
    ......
}

After struggling for half an hour with it I decided to take some help from my friend. Since we had some hints for the lab, we essentially had the same idea. So I knew I didn’t have the algorithm wrong.

I just couldn’t figure it out. I thought maybe there was some problem with Visual Studio so I restarted. I copy-pasted the code in a different function. I virtually did everything. Given up, I tried putting a small if-check with different code in that place. That worked! So, I knew there was something wrong in my code. Not being able to understand I decided to write the whole function from scratch and it worked! Infuriated, I started comparing the code I had previously written to the final code. I saw the silliest mistake I ever made, I put a semicolon immediately after the if-check. I never felt stupider.

Copy and pasting the code was copying my mistake too. This mistake was so infuriating at that moment. Out of this whole incident I learnt one thing; never copy-paste code.