Live data from Hacker News

Make the Type System Do the Work

nathan.ca

1–10 of 141 posts

Re: Make the Type System Do the Work

#2
> The only problem is that you end up with a variable that fails to describe itself better than “I’m a number”.

Our application servers need to know about updated entities, so we broadcast notifications when an entity has been updated - but we prefer to leave it up to the individual applications to retrieve the updated entity as they see fit.

So we're often dealing with numerical ids of entities, and we've had a few bugs arise from code like so

   public void something(long accountId, long websiteId)
When people have accidentally used the wrong long in the wrong place. So we've now moved to using simple wrapper types around aforementioned longs -

    public void something(AccountId accountId, WebsiteId websiteId)
It does come at a little bit of cost as we're passing these things around a messaging system, so now we have to think about how they are serialized (Java serialization is problematic, and there are occasional religious wars about GPB vs. JSON), but it leverages the type system to make it every explicit what this number represents.
Post reply on HN