From “Intermediate” to “Advanced”: A rant…

It’s a story as old as time:

When we get a new toy, new car, new hobby, new girlfriend || boyfriend, new furniture, new anything, we just can’t help ourselves…

We press every button, turn every dial, fingerprint every screen, hold hands every date, make love on every piece of furniture, practice to exhaustion every day, buy every extra accessory, etc…

But that’s ok! Because when learning new things, unbridled curiosity is paramount when beginning new chapters in our lives. It’s what makes being human fun! It is the very thing that has led mankind to it’s greatest achievements.

It’s also what makes us incredibly dumb on a long enough timeline. Let me explain…


Do you remember when we started out on our quest to become developers? Remember writing our first recursive function? returning new hot fresh arrays with a .map()? discovering the magic of ternaries?

let awesome = (arr) => arr.map(x => x === 'awesome' ? x : null);

or maybe the “syntactic sugar” of short circuit code?

function reverseString(str){
let dictionary = {};
for(let i = 0; i < str.length; i++) {
dictionary[str[i]] = ++[dictionary[str[i]] || str[i];
}
return dictionary;
}

or the ever so clever code gulf approach using chained method on top of chained method till you’ve attained that elusive “one-liner”?

let getIntergerComplement = n => parseInt(newNum = n.toString(2).split('').map(num => num === "0" ? 1: 0).join(''), 2);

Mmmm…good good times. But bad bad code. Why?


One answer, Efficiency!

You’re not a budding developer anymore! You ARE a bonafide, seasoned, battled hardened, scar bearing, light saber wielding, developer ninja! Act like it.

We use for loops to iterate over strings instead of string.split().map() because we know better.

// Bad: str.split() doubles n iterations.
let arrOfChars = str => str.split('').map(char => char);
// Good: n iterations occurs only once.
function arrOfChars(str) {
let arr = [];
for(let i = 0; i < str.length; i++){
arr[i] = str[i]
}
return arr;
}

Sure it was fun for a time. But now, we have “adulting” to do. We have scalability to think about. Big O, to consider. Recursion V. Looping to ponder.

Making these evaluations is what separates the “Intermediates” from the “Advanced”. We don’t write code because it looks “Clever”, we write code because we recognize that, “Cleverness” is subordinate to “Smart”.

FYI: Looking at the etymology of Smart to Clever we’ll find that Smart originally implied “to be in pain”, whereas Clever originally implied “quick to catch hold.”

Sometimes it’s a painful thing to write Smart code. But at least now you know you’re not an “Intermediate”. Stay Strong & Good luck.

-Toby

// CodeOn