Code: Two Spaces || 4?

Andrea Cardona
3 min readJan 4, 2018

--

As a new programmer I must admit I was NOT paying attention to indentations and didn’t take the time to learn the rules nor their proper form. My brain was way too overwhelmed with learning how to loop, create an array, figure out what BASH was, and how to make a hash table(not the yummy breakfast hash you’re thinking of…).

I was just following syntax that I had seen before and quite honestly guessing my way through it all. Yet I quickly realized my lackadaisical attitude and complete disregard was leaving me with tons of novice mistakes — and some really bad habits.

So, it’s time for a change. I’m writing this blog post to you all on the last day of 2017 — as someone who just completed their second week of coding bootcamp — and as a young programming grasshopper — well I can not be making these silly mistakes — dammit I’m embarrassing myself.

2 reasons to follow proper syntax

1. your own sanity:

It’s incredibly important to keep your indentations in order because otherwise you will quickly become familiar with the lovely error message below (perhaps even a few others)…and it will drive you crazy!

Syntax Error Message — my ex-best friend

Programming is incredibly hard as it is, and so avoiding this small syntax issue — I promise will save you a ton of little headaches amongst so many larger ones. Because my indentations were all over the place I often forgot to close my loops, methods and many blocks of code — which caused minutes (that I’m sure have added up to hours…at this point) of going back looking through a gazillion lines of code and fixing my syntax errors.

Ruby at the very least is kind enough tell you exactly what you’re missing here… a pesky little end…but mistakes like these are easily avoidable.

2. For the sanity of others/your peers:

Another huge issue that comes along with sloppy indentation is that hurts the eyeballs of all the people around you….swear (I’ve been kindly told that my indentations were a bit of an eye sore). Now, a big thing you’ll learn in programming is that everything you do especially in the beginning will be driven forward, perfected and built with the help of your programming community — whether it’s the help of your friends, cohort classmates, instructors, mentors, or coworkers throughout your entire career…and the symphony of it all is truly really amazing. So my point is, whether it’s checking error messages, method functionalities, loops (you’re going to be doing a ton of those..) or syntax issues — someone else is going to be looking at your code — and if it’s not easy to look at, it’s going to make the debugging process 10x harder and longer.

3 simple tools to avoid the above mistakes

1. Indentation rule:

Everyone is happy to use just two”(1)

2 spaces — soft tabs!

2. Be a creature of habit:

close out your code blocks…immediately..and make sure they’re aligned! def..end, def…end, loop…end, loop…end, any block…end!! Repeat this in your sleep.

3. Auto-Indent tools:

Atom — and many text editors have an auto-indent, so you have no excuses.

References:

  1. “Origin.” The Unofficial Ruby Usage Guide, www.caliban.org/ruby/rubyguide.shtml#indentation.
  2. Ruby-Style-Guide — Github: bbatsov

--

--

Andrea Cardona
Andrea Cardona

Written by Andrea Cardona

Frontend Developer && Forever Student

No responses yet