Less is More…

Learning Javascript has been (mostly) fun so far! I’m happy to get into more of the logic-based languages and leave the color and style-fueled world of CSS and flexbox behind, at least for now.

In Javascript, less can really be more. When working on my homework yesterday, I started by brute-forcing a solution, creating a bunch of variables, and copy-pasting my code for each variable throughout the assignment. I ended up with a whooping 115 lines of code.

While looking over my code, I remembered a quote from my teaching days that is quite applicable to coding:

“If you have to repeat yourself more than 3 times, you’re not doing something right.”

Reviewing my first attempt, I repeated myself multiple times, and I knew it could be simpler. We have already discussed loops, and that would make my code more efficient and compact. With some additional work, I was able to get it down to 42 lines of code, 63% less!