Playing on Hard
Return of Return Type Inference

I wrote about return type inference last month. I offered no recommendations but here is one that I think might strike a solid balance between fast writing and improved reading:

  • Specify the return types on all the functions exported from a module
  • Do not specify return types on the functions internal to a module

This works for classes too:

  • Specify the return types on all the public methods of a class
  • Do not specify return types on the private methods

This improves coding because:

  • We have strong specification of public interfaces which makes the reasoning and composition easier.
  • Use type system to our advantage to enforce stable public interfaces - we have to want to change a public interface rather than changing them by some happenstance
  • Implementation details internal to modules and classes keep their flexibility

Last modified on 2024-08-02