3 ms·
Static typing can make things clearer, indeed, however Java has really shitty static typing. Also this is a common misconception: > You can know with complete
by bad_user 12y ago
Static typing can make things clearer, indeed, however Java has really shitty static typing. Also this is a common misconception:
> You can know with complete certainty what type of data the code works with, just by looking at it.
First of all, the type is only a limited view of the shape of the underlying data, written from the perspective of the business logic using it. In a micro-services architecture it happens often to see the same data exposed with types that are often very different, depending on what you're trying to accomplish. And too often developers that work with Java are complecting the business logic with the actual data, which is often pure data that's being messed up with short term business logic rules.
And furthermore, Java developers don't work with static type safety. Tell me, what does a String tell you? What does a Double tell you? How often have you seen explicit type-safe numeric types in Java (e.g. lets say values that are in kilowatts, or meters, or other units of measure)? You don't see that, because Java is awful at expressing such types, from the lack of operating overloading, to the completely retarded generics system and the lack of type-classes.
Second of all, the type IS NOT sufficient documentation when dealing with non-determinism and if side-effects happen in your system, then that's non-determinism. And when non-determinism happens, you need to document the protocol of communication and static types in mainstream languages cannot capture that, which is a PITA because that would be far more useful than seeing that this Person has an email address.
- abalone 12y ago> In a micro-services architecture it happens often to see the same data exposed with types that are often very different You mean micro-services that use dynamic instead of strongly typed APIs? That's really more a critique of such architectures than the facility of static typing. > Tell me, what does a String tell you? What does a Double tell you? It tells you you can't use a String where a Double is needed, without unit tests, from the very moment you type the reference in your IDE. You're correct that it doesn't eliminate all possible problems such as validating the unit of measurement, and that it's not sufficient documentation in and of itself. But that's not the goal of static typing. It's there to eliminate a very large swath of problems through simple declarations in code.