Clean up on Line 6!

20 Sep 2018

Who Needs Standards, Anyway?

Standards are everywhere. There are social standards people live by. There are a set of standards you must meet at your part time job. There are a set of standards you set for yourself even. I’m sure i’m not the only one that finds that standards can be a bit of a headache. Nonetheless, they are necessary. Otherwise, everything would lack quality. As with everything else, coding has a set of standards. Alligned brackets, proper casing, consistent tabbing, are just a few of those standards. Just thinking about it makes my face scrunch up in frustration. You wouldn’t believe the amount of time I would put into perfecting my code only to find that I was docked off some points for a misplaced bracket. At first, these standards seemed unnecessary to me; if my code works perfectly fine, why should I get docked points for a missed standards? However, with more experience came more understanding and insight. Trust me, when you encounter a messy code, you become thankful of the coding standards set in place. Let’s look at an example:

   if (input == "exit")
     running = 0;
      else {if (input.equals("add")){
          System.out.print("Please input first integer: ");
            int1 = scan.nextInt();
          System.out.print("Please input second integer: ");
            int2 = scan.nextInt();
            result = bar(int1, int2);
          System.out.println(int1 + " + " + int2 + " = " + result);
          }
      if (input.equals("sub")){
System.out.print("Please input first integer: ");
int1 = scan.nextInt();
System.out.print("Please input second integer: ");
int2 = scan.nextInt();
result = foo(int1, int2);
System.out.println(int1 + " - " + int2 + " = " + result);
}

As we can see with this example, some of the loops and brackets are unalligned. Not only does it make it diffcult for others to see what is going on in your code or what your code is doing, but it can make it more diffcult for you when you review it or attempt to improve it. It takes a lot more time to understand which instructions will be carried out with particular conditions. By keeping the loops aligned with their set of instructions, those reviewing the code will understand what you are trying to accomplish. Now, that’s just one example of a messy code. Imagine how hard it would be if the code was even longer. Coding standards are set in place for a reason. An efficient coder is a fast coder. Also, coding is already hard as is, why make your job even harder?

Setting Yourself Up for Success

Of course, a clean code isn’t the only way to be an efficient coder; you must also create a working code. You can’t achieve anything if your code doesn’t do what it’s suppose to. Finding your errors can sometimes be difficult and many IDE developers know that. Enter linting tools! Recently, I started working with ESLint on Intellij. Setting it up was a bit diffcult for me, but once I got the hang of it, I found myself appreciating the tool. Though, I wouldn’t say im comfortable with Intellij just yet. In my personal opinion, the little green check that shows up when ESLint doesn’t detect an error gives me some relief. It makes it easier for me to identify errors and gives me a little assurance. Want clean up those pesky errors? Use a linter!