# How to clear karma to your code?

How often does it happen that you encounter bad code and mentally scold the author?
And then come to the conclusion that the code is not so bad, and the author was scolded in vain ... But the sediment remained!

In general, I was meditating just before the monitor, and visited mesuch a code:

```class Graph {   /**    * retrieve min value for y-axis    */   public int getYaxisMin() {     int result = getMinAmount();     result = result / 100 * 100;     return result;    }   /**    * retrieve max value for y-axis    */   public int getYaxisMax() {     int result = getMaxAmount();     result = ( result + 100 ) / 100 * 100;     return result;   }  // Да, это самый настоящий код, написанный не сто лет назад, а в 2010 году,   // и не студентами какими-нибудь, а вполне солидными программистами.   // Так-то!   ... }```

Following this code, of course, the Negative Emotion visits me . Perplexity.
Why should I divide by one hundred and immediately multiply by one hundred?
Why add a hundred and do a hundred? What is going on here? WTF?

### Clue

During the debug, it turns out that this code is working. Since we are talking about integers, when divided by 100, the result is rounded, and when repeated by a hundred, a smaller number is obtained. For example, from 666 it turns out (666/100) * 100 = 6 * 100 = 600. That is, the value is rounded to the nearest hundred.

What is it? The code seems to be there, it seems to work, that is, there’s nothing to blame the programmer for. But at the same time, I spent the energy to figure it out, and most importantly, I said out loud " What The Fuck " which increased my karma by one.

### Karma - Cosmic Law

Mahabharata has such a thing as karma code. The karma of the code is blacker, the more a person said “ What The Fuck ”, looking at him. The Vedas say that the language in which the code will be implemented in the next reincarnation depends on the number of WTFs called up in the previous implementation. If they said “What the fuck” at least once about the code, then the next time he definitely won’t be implemented on Scala, if they said “What the fuck” five times, then Java will shine for him, and if 20 times or more, then be born to him in PHP or even Perl'e.

### Getting rid of karma

How to clear the karma of your code?

As stated in the Vedic texts, any programmer can change the fate of the code if on the day of Bhadr Purnima he discovers the scripture " `import org.junit.Test`" and writes a cleansing mantra:
```public class GraphTest {    @Test    public void yaxisMinTruncatesToLower100()    {      assertEquals(0, new Graph(48, 415).getYaxisMin());      assertEquals(100, new Graph(100, 415).getYaxisMin());      assertEquals(900, new Graph(914, 415).getYaxisMin());    }    @Test    public void yaxisMaxTruncatesToUpper100()    {      assertEquals(100, new Graph(48, 96).getYaxisMax());      assertEquals(200, new Graph(48, 100).getYaxisMax());      assertEquals(500, new Graph(914, 415).getYaxisMax());    } }```

By the way, the Shastras also recommend cleaning up a bit of their own karma by erasing obscene comments and making the code three times shorter:
```class Graph {    ...    public int getYaxisMin() {      return getMinAmount() / 100 * 100;    }    public int getYaxisMax() {      return getMaxAmount() + 100 ) / 100 * 100;    }    ... }```

Well, now the karma of your code has cleared a bit. But on this, our teaching of yoga is not legal. We are only at the beginning of the Path. Next time we’ll look at why our code needs to confess and receive the sacrament on a monthly basis. And better - daily, ideally - even hourly. In ancient writings, this process is called Continuous Integration .

And today the lesson is over.

We summarize the knowledge gained:

Think with your own head, do not believe in any garbage - and you will reach the highest transcendental monastery!

So it goes.