DEV Community

loading...
Cover image for How My Coffee Maker Taught Me to Love Types

How My Coffee Maker Taught Me to Love Types

mariowhowrites profile image Mario Vega ・2 min read

TypeScript.

That one word had hung around the edges of my consciousness for months. VS Code would suggest the .ts extension for every new file I created, and every time my answer would be, "Not today." Looking up the implementations of JavaScript functions would bring me to TypeScript type definition files, which always looked a tad too intimidating to parse. I'd read quotes about the growing inevitability of typed JavaScript and think that that inevitability didn't apply to me. When had I ever run into a problem that typing would solve?

Little did I know that the evangelist that would convert me to the typed way would be my own coffee maker.

Like many work-inclined people I know, coffee fuels a large part of my working day. And like many developers I know, I follow my creative inspirations wherever they might take me -- often into the small hours of the night. At the end of my working hours, I typically set a pot of coffee on autobrew for the following morning so I can start my next day without missing a beat.

One day a couple weeks ago, I woke up to a calamity: coffee grounds everywhere. Coffee grounds in my coffee, coffee grounds on the counter, coffee grounds trailing down my cabinet doors and pooling on the kitchen floor below.

As it turns out, in my early-morning code-addled stupor, I had forgotten to put the filter back into my coffee after cleaning it. It was in that moment of cleaning coffee grounds that I realized why I had to start typing my JavaScript immediately.

Effectively, I realized that my coffee maker was like vanilla JavaScript. It was happy to let my delirious, inattentive self set my coffee up however I wanted. There were no checks to make sure that I had put in a new filter, no checks that I had put in new coffee grounds, no checks that I had put in water, no checks whatsoever to ensure that I would actually have coffee in the morning and not a waterfall of wasted grounds. Any problems that resulted from my coffee setup would have to be handled when it was time to brew, not while setting up and actually had the time and (some of) the attention span to fix things.

If my coffee machine had been strictly typed? Sure, maybe I would have been annoyed that my machine was bleeping at me to fix my improper setup when the only thing I wanted to do was go to sleep. But I would have fixed things all the same, and my diligence would have been rewarded with morning coffee.

There are few things more important to me than coffee, and properly-working code is one of them. So, while the jury's still out on when we'll see strong typing make its way into home appliances, I decided right then and there that I would start my journey into TypeScript.

Discussion

pic
Editor guide
Collapse
maciekgrzybek profile image
Maciek Grzybek

Is that… CoffeeScript?

Collapse
adam_cyclones profile image
Adam Crockett

TypeCoffeeScript now that would be interesting.

github.com/michaelficarra/CoffeeSc...

Looks like that's a thing, funded project aswell.

Collapse
mariowhowrites profile image
Mario Vega Author

I did, in fact, originally include a CoffeeScript pun in this post. It felt forced, so I took it out and left the setup for a particularly astute commenter ;)

Collapse
fischgeek profile image
fischgeek

I've seen this post float by my feed a few times. Finally I decided to read it. I must say, you have a talent for story telling. I was riveted. Fantastic story and really well done. Thanks for the good read!

Collapse
steveblue profile image
Steve Belovarich

What a great story! You combined my two favorite things TypeScript and Coffee ☕️

Bringing types to JavaScript is possibly the best part of TypeScript. I also love how TypeScript allows you to code with future spec as well. The TypeScript compiler is pretty incredible too.

Cheers!