Lamenting about data types
Nicola Todorov

Nicola Todorov @todoniko

Location:
Sofia, Bulgaria
Joined:
Jun 22, 2025

Lamenting about data types

Publish Date: Jul 3
0 0

Why most code is more fragile than it should be?

Somewhere, right now, a developer is staring at a failing test or investigating production issue. It will take some time to figure it out. Maybe it was a string or a number passed into the wrong place.
The compiler didn't complain. Neither did the tests - until someone fed it a value they weren't supposed to.
The fix? A few extra if statements. Maybe a test added after the fact.
The underlying cause? Never questioned.

What if I told you ... that bug did not need to exist?
What if your code could make that mistake impossible?
Not caught, not detected, unrepresentable.

I am not talking about science fiction or some weird academic programming language. It's what type systems of Java or C# are already capable of doing - if you let them. Yet most developers treat types like seat belts - annoying at best, restrictive at worst.

Types vs Tests

You've probably heard someone say:

That is why we write tests

Fair enough. Yet let's compare:
A test compares a handful of paths.
A type covers them all.
A test can be skipped or deleted.
A type can't be ignored. (Don't worry TypeScript we love you the way you are)
A test catches problems after you've executed them.
A type prevents you from writing them in first place.

Types are not just for the compiler. They're for you, your teammates, and even your AI agent. They encode knowledge. They reflect rules. They act as living documentation that is always up to date, always enforced and always helpful.

Why isn't everyone doing this?

And this is what keeps me up at night:
We already have the tools. Mainstream languages have type systems that are capable enough. Modern IDEs are fantastic at navigating types. AI coding tools fair better when types guide them.

Yet most teams still passing raw strings around like they're free candy. Still relying on test to catch what the compiler could have prevented. Still debugging issues that shouldn't have been representable in first place.

Why?

Because we humans are inherently sloppy.
We were taught to "just get things working".
We optimized for flexibility and speed - until our systems collapsed under the weight of ambiguity.
We missed the essence:

A good type system doesn't slow you down. It keeps you from speeding into walls.

Plan of action

Over the next few articles, I'll be introducing patterns for type creation that amplify the design process. I will stick to what Java or C# can encode, nothing fancy like dependent types or encoding fizzbuzz in the type system. My aim is practical and applicable.

It is time to stop treating types like red tape. Designing with types won't make you invincible but it will make your code resilient, expressive and correct. Let's start thinking in types.

Comments 0 total

    Add comment