Stringly typed
Stringly typed
Dark times…
Like -1 for an Int nil value.
int?
Groovy will automatically convert integers into objects, as it sees fit. And one such case is when you assign null to an integer.
There’s some more languages, which try to treat primitive types like objects, to make them more consistently usable. As I understand, nullability is a big part of the reason why it can’t be solved with syntactic sugar, so presumably this would be possible in all those languages.
If I’m not mistaken, Ruby is another one of those languages.
Ah, yeah, very familiar with that article. 🙃
It’s definitely part of the reason why I like these really narrow types. But the other big reason is that your internal APIs start to look like this:
It just makes it almost impossible to pass the wrong value into a parameter. You don’t need to wonder, whether you should pass your port variable into a parameter called bind_port, if you introduced separate types BindPort and RemotePort for them.
Of course, this is a somewhat extreme example. It’s up to you to decide, whether you’re likely to encounter multiple values of the same type and whether it’s therefore helpful to make it impossible to confuse them.