• Question: do you get in trouble for deleting code

    Asked by anon-278450 to Adam on 3 Feb 2021.
    • Photo: Adam Washington

      Adam Washington answered on 3 Feb 2021:


      If I just deleted the code by itself, I absolutely would get in trouble. Instead, I try to write small bits of code that allows us to replace very large bits of code. As an example, since our program simulates a box full of atoms, a very common task is going through every possible pair of atoms and checking how they act together. If you just have three atoms (H, C, and O), then you have three possible pairs (HC, HO, and CO). When you have a million atoms, you have almost half a trillion different pairs.

      There’s a lot of busywork involved in keeping track of all of the pairs and this was done at about forty different places in the program. I wrote a small bit of code that could do all of the busy work in a general way. I then went through and deleted the forty different places we had the busywork and replaced them with a single line of my new, general way.

      Since there might be half a trillion different pairs to look at, this is usually a very slow process. Every time I make my single, general method faster, I now make the program faster in forty different places, instead of have to make forty different changes.

      That’s part of why deleting code is so exciting for me – it’s usually a good sign that the code everything will be faster and more stable in the future. Whenever I delete the code, I also get to delete all the bugs in that code!

Comments