3 ms·
> they can't make the code as easy to comprehend as it would be in a more expressive language. It's a little hard to make a general statement using an vague te
by abalone 12y ago
> they can't make the code as easy to comprehend as it would be in a more expressive language.
It's a little hard to make a general statement using an vague term like "expressiveness".
Static typing can actually make things clearer. That's a kind of expressiveness. You can know with complete certainty what type of data the code works with, just by looking at it. No need to rely on a certain set of unit tests living somewhere else to confirm your assumptions. And if you say "well just read the function docs", how is that any less verbose in the end? It's the same verbosity, minus the compiler guarantees.
On the other hand, there are situations where DSLs can greatly cut down on route programming. Like Apache Pig vs. calling Java APIs. But that's a more extreme example, an actual speciality "domain" to make a specific language for.
I might help to use a more precise term like verbosity. Then we can ask, is this verbosity really helpful (like explicitly declaring types), or can we compact it without losing significant information. Fortunately Java 8 has made some progress with adopting features that cut down on unnecessary verbosity.
- bad_user 12y agoStatic 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.
- lmm 12y agoType safety is valuable, but you can have equivalent or better type safety in a much less verbose language than Java. e.g. I use Scala - it's not quite as concise as Python, but it's pretty close, and the language is powerful enough that I can express more possible effects directly in the type system (Does this method make an async call? Does it access the database? Does it log audit events?) without the code becoming unreadably verbose.