Colored logo

Typing Your Codebase: A Tale of Two Developers

November 16, 2024

β€’

3 min read

The Type Wars: A Tale of Two Developers 🏰

Hey there, fellow code warriors! πŸ‘‹ Let me tell you a story about two developers who walked into a bar... I mean, a development project. ...Though honestly, both scenarios usually end with someone crying about types! πŸ˜…

Meet Our Heroes

Let's meet Mike and Bob, not to be confused with bob.js or mike.ts πŸ€“. They're both tasked with building a server for non-tech-savvy users. You know, the kind who think "cache" is where they keep their emergency snacks.

  • Bob: Team TypeScript Because he likes his code like he likes his coffee - strongly typed!
  • Mike: Team JavaScript Because who needs types when you have ~~bugs~~ features?

The Plot Thickens 🎭

So here's where our story gets interesting. The frontend team bless their hearts builds this beautiful UI. It's got more animations than a Disney movie and more gradients than a sunset. But there's a tiny massive detail they forgot:

Data validation? More like data YOLO-dation!

The Tale of Two Implementations

Bob's Typescript Kingdom πŸ‘‘

Bob, being the type-safety knight he is, sets up his interface like this:

interface IUSER {
name: string;
age: number;
email: string;
hashedPassword: string;
updatedAt: Date;
createdAt: Date;
}
interface IUSER {
name: string;
age: number;
email: string;
hashedPassword: string;
updatedAt: Date;
createdAt: Date;
}

When someone sends this bad boy to his /api/v1/user endpoint:

{
name: "Mike",
age: "18", // Sneaky string instead of number!
email: "bob@theniitettey.live"
}
{
name: "Mike",
age: "18", // Sneaky string instead of number!
email: "bob@theniitettey.live"
}

Bob's server be like: "Hold up! πŸ›‘ This age is looking kinda sus. Expected a number, got a string. Not on my watch!"

Mike's JavaScript Jungle 🌴

Meanwhile, in Mike's JavaScript wonderland, where types are more optional than turn signals in a BMW, the same request leads to...

Well, let's just say things get interesting:

  • The server might crash surprise party! πŸŽ‰
  • Error messages become more cryptic than ancient hieroglyphs
  • Or worse - it worksℒ️ _*but not really**

The Philosophy Corner πŸ€”

"Handling errors is like putting a band-aid on a wound, but preventing errors is like not getting the wound in the first place."

Michael Perry, 2024 (Move over, Shakespeare!)

Why Types Are Your BFFs

  • Catch errors before they catch feelings - Types are like your code's spell-check
  • Documentation that doesn't lie - Unlike your ex
  • Better than coffee for preventing runtime headaches

The Grand Finale 🎭

So what did we learn today, kids? Using types in your codebase is like wearing a helmet while coding - it might not look cool, but it'll save your brain!

Plus, it's better to have TypeScript yell at you during development than to have users yell at you in production. Trust me, TypeScript's error messages are much nicer!


Bob is smart, Bob uses types. Be like Bob. 🧠

Bob

And that's all folks! 🎬

Signing off, Michael Perry
Definitely not Batman
But if I were, I'd use TypeScript for the Batcomputer, just saying! πŸ¦‡

PS: You know what they say -

...with great types comes great responsibility! πŸ¦Έβ€β™‚οΈ

_definitely not Uncle Ben _

Batman