Hacker News new | ask | show | jobs
by jhall1468 3004 days ago
> The point of type checking is that it has to be rigorous, it doesn't do anything for you if it doesn't check types.

I don't always need to check types. I don't need to know that isReady returns a bool. It clearly returns a bool. This idea that type checking has to be absolute is because in statically typed languages it does, not because that's a forgone conclusion.

2 comments

> I don't always need to check types. I don't need to know that isReady returns a bool. It clearly returns a bool.

I'm sorry but you're mistaken, friend. I checked the signature of that function and it actually returns an enumeration of ready states:

    enum class Ready { Insert, Process, Clean };
    const Ready isReady();
Static typing is extremely useful for knowing what things return - names are not.
> Static typing is extremely useful for knowing what things return - names are not.

Only if you completely ignore convention (that is prefixes return bools) then, sure, it's not useful. But if you just want to break conventions, then all of this is moot because you are guaranteed to do stupid stuff outside of that.

Even if you don't want to break conventions, you might do it by accident. If you don't have a compiler (or a static checker of some sort), there's no one there to keep you consistent.
You are assuming that your usage of isReady will be flawless every time. What if you call a function updateUser("username", isReady()) but it turned out you remembered the order of arguments wrongly. Then the type checker will tell you as you can't pass a bool to a string argument and vice versa. This type of error is super common in %-string formatting.

It won't help if all the arguments have the same type unfortunally but at least it catches something. Just like unit tests, they won't catch everything so the more checks we have and the earlier we run them the less risk there is something slips through to production.