it should.
Having objects flow across multiple domains isn’t an ideal situation, even if the type checker is giving an A-OK 👌
I am not arguing that you should not use static types, but I am arguing that it is probably helping you less than you think.
It requires less headspace when coupling is reduced because the applications become easier to reason about.
Avoid implicit assumptions by stating them clearly (explicitly) in the code. Then reaffirm assumptions when data crosses boundaries (a type isn’t always enough), which includes boundaries to internal domains and sub-domains.
I often perceive the application’s internal domains and sub-domains, much like I would external ones. Regardless of whether I write my own implementation or use external services or libraries to handle a specific area of responsibility, the interface (e.g. function signature) should be similar. Your objects wouldn’t travel from your code into external services or libraries either.
If the problem doesn’t fit in your head, it is probably time for refactoring. I feel that smart IDEs and static typing postpone the pain that usually leads us to that realization.
Personally, I had more benefit from a REPL, immutable data structures, and a functional concise language than static types in my quest for maintainable and robust software.
Luckily, simplifying and decoupling code works in any language
— not just Clojure.
In the spirit of simple code and refactoring, I feel it is worth sharing the following talk by Sandi Metz with a quote from it:
… code can know less, we can do smaller things.
RailsConf 2014 - “All the Little Things”
Sandi Metz is a genius.
Reflecting on static types
© 2024 by Jacob Emcken is licensed under CC BY-SA 4.0