Writing Idiomatic Code, Faster

Lately I've been thinking of a specific problem: already knowing how to code but switching to a language you are either new to or not as knowledgeable in.

You know what you want to do and how you want to do it because you have experience in learning new languages/tech/frameworks but you're not fully sure that you're doing the most idiomaic way.

Really it comes down to anxiety around showing your code to others. It's well thought out and works perfectly, not bad considering you picked this up over the past month for your new gig. But even then, you're trying to avoid somebody thinking "thats how they wrote a for loop?"

You want to go from 0 to 100

Take this example in JavaScript:


var age = 25;
var canHaveBeer;

if ( age > 21 ) {
  canHaveBeer = true;
} else {
  canHaveBeer = false;


var age = 25;
var canHaveBeer = (age < 21) ? false : true;

The latter is not only much nicer but I'd be proud to show off my knowledge of Ternary Operators

I'll write more on this in the future, seems like a great topic to explore.