Taking a stand with standards

10 Feb 2022

Setting standards

  Going into my Master’s degree, I had limited experience with writing code. I had done quite a few programming assignments, and only a few projects. But most of these were small assignments where functionality was the key factor. Whenever I submitted these assignments I would try to do my best to make sure my code was formatted in such a way that other people could read it with ease. Below is an example of how I try to make my code.

/**
 * Name: example
 * Parameters: 
 * - param: parameter of this function
 * Description: This returns yes or no depending on the parameter
 * Return:
 *        ok: function worked
 *        no: function did not work
 */

function example(param)
{
  if(param)
  {
    return ok;
  }
  
  else
  {
    return no;
  }
}
My coding standards are relatively simple:
  1. Comment above the function giving a brief description on what the function does, a description of parameters, and what the function returns(if applicable).
  2. Comment inside the function if necessary.
  3. Line up brackets so that way it’s easy to see where if,else,for, etc… statements begin and end.
  4. Space out statements. That way you can see the clear beginning and end of them.

  So when one of my graduate classes had us perform a code review, I was a little nervous at first. Our instructor made it clear the purpose of this review was to find issues in the functionality of their code. This meant that code format didn’t matter in this review. The instructor would later go on to say that code formatting is “similar to religion”. But in my undergraduate classes I had two classes in particular which cared how the code looked and how it should be formatted. If coding standards are ‘religion’,were we being ‘indoctrinated’? When should standards be followed? Do coding standards even matter?

But first my linty code

  For the past week I’ve had to complete assignments that use the AirBnB Javascript Style Guide. This is meant to work with the ESLint feature in the IntelliJ IDE. I want to start off by saying all of these applications are great to use, and will definitely help me, more than hurt me in the long run. But I can’t tell you how many times I get a red squiggle mark telling me to line up my brackets, put a space here, or how to format my commas. What I can tell you is that it stresses me out when we’re doing a timed coding exercise and these red squiggles pop up for non code breaking reasons. It’s not that they’re bad, but I feel that these exercises should focus more on what the code is doing rather than how it looks. Especially, if you’re like me and have a particular format that you’re used to. The red squiggle is a deceptive being. It deceives the programmer in to thinking that your code won’t work. It can either signal your code is actually broken, or you forgot to put a space somewhere.

  My overall opinion of having to use ESLint with the AirBnB coding standards is that it will helpful to me as someone who is still new to Javascript. It will catch any spelling mistakes when it comes to function calls. It can tell you when brackets are missing, and even give hints on when to use const and let. I think as someone who isn’t familiar with a lot of formatting aspects of Javascript I’m hoping to learn a few tricks from my naggy little linter.

So who needs ‘um?

  Earlier I asked if standards matter and if they should be followed. In a class setting I think they should, as this can assist instructors on making sure all code is readable and legible. Especially if the class size is large. It’s twice as important if the students have limited to no experience in writing code. So in a sense, we were ‘indoctrinated’ but thanks to multiple classes having multiple standards we also learned that not everyone NEEDS to write with the same format. In fact large companies such as Google have their own style guide. Standards are meant to create consistency, so if you have a consistent formatting in your code, that’s already a good step forward. Because standards allow others to read your code with relative ease. It allows them to be able to comprehend the story you’re telling in your code.