Saturday, 14 January 2017

Expressive types, not oppressive types

Uncle Bob wrote a recent post in which he warns programmers against the "dark path" some modern languages have taken - that is to "double down" on static typing. He cites Swift and Kotlin as examples, though his argument is meant to be interpreted more generally.
I share many points of view in common with Uncle Bob. I find the dynamically typed Clojure programming language beautiful and expressive - most of my personal projects are written in Clojure. I think that TDD (test-driven design) is a valuable and important discipline - I work for an agile consulting company where most of our projects include helping clients to get better at testing.

But I disagree strongly with the way Uncle Bob frames this discussion on static types.

Uncle Bob looks at advanced type systems and sees them as more oppressive rather than more expressive. Being able to describe whether or not a function can return null is an opportunity, not a constraint. Being able to use types to describe your code's intent is an opportunity, not a constraint. Being able to reason about the behaviour of a function based on its type signature is an opportunity, not a constraint.
The kicker is that this is almost exactly the fallacy about TDD that we have railed against for years. We call it "test-driven design" because we know that evolving code in response to examples is a great way to inform a design. Folks who have not learnt to listen to their unit tests see them as nagging constraints that prevents them from writing code in the way they'd like. A master of TDD uses tests as feedback for their design.

Anyone who sees unit test as mere "checks" that make changing code needlessly difficult isn't getting the most out of test-driven design. Anyone who sees static types as mere "checks" that make changing code needlessly difficult isn't getting the most out of type-driven design.
Based on his post Uncle Bob falls into the latter category. He sees types as ad hoc antidotes for specific mistakes rather than tools for thought - "Every time there’s a new kind of bug, we add a language feature to prevent that kind of bug."
If that's Uncle Bob's experience of Swift and Kotlin, he should try Elm. Or F#. Or Haskell. If his experience is anything like mine, he would find that more sophisticated types lead to less ad hockery, not more.

In a follow-up post, Uncle Bob is explicit about what he wants in a programming language - "There is a balance point after which every step down The Dark Path increases the cost over the benefit. I think Java and C# have done a reasonable job at hovering near the balance point."
I couldn't disagree more. Java and C# have two of the most onerous and least beneficial type systems. Their complexity and absence of type inference force excessive bookkeeping on the programmer. They lack of basic features like sum types, which denies the programmer an important expressive idiom.
Java and C# represent the nadir of the type system trade-off, not the zenith. Type systems are tools. Better tools help us write better code. We should welcome each and every advance in the tools we use to do our job, because frankly we could do a lot better than what we have now.

To argue that employing more expressive types is a "dark path" that leads developers away from personal responsibility isn't accurate or helpful.

40 comments:

  1. Why do you say C# lacks of type inference? It supports years ago. And by the way, don't say thing like "Java and C# " anymore since they are completely different now, they are just similar in the key C/C++ syntax.

    ReplyDelete
    Replies
    1. Java and C# are still quite similar, paradigm-wise. Garbage-collected, object-oriented, class-based, simple polymorphism, managed runtime. When talking about the type systems you can consider them to be one and the same.

      Delete
    2. Once you learn Haskell, you find out that C# doesn't have anything like type inference.

      Delete
  2. Try F# and you'll see what real type inference is on .Net

    C#'s inference at the level of a single expression is a toy in comparison.

    ReplyDelete
  3. I agree with you. I've read similar responses to Uncle Bob's post:

    http://blog.zdsmith.com/posts/the-dark-path-or-what-if-i-dont-want-to-quit-my-job.html

    And frankly it strikes me very strangely to have such a strong opinion about the badness of types. I certainly like to have control over how strict I want my compiler/interpreter to be with me, but I really like using types to be expressive about my intent.

    ReplyDelete

  4. very useful info, and please keep updating........
    Best Online Software Training

    ReplyDelete
  5. Great blog.you put Good stuff.All the topics were explained briefly.so quickly understand for me.I am waiting for your next fantastic blog.Thanks for sharing.Full Stack Training in Hyderabad

    ReplyDelete
  6. Really you have done great job,There are may person searching about that now they will find enough resources by your post

    Java training in Chennai

    Java training in Bangalore

    ReplyDelete
  7. This comment has been removed by the author.

    ReplyDelete
  8. This comment has been removed by the author.

    ReplyDelete
  9. Outstanding blog thanks for sharing such wonderful blog with us ,after long time came across such knowlegeble blog. keep sharing such informative blog with us.

    Check out : big data training in velachery
    big data hadoop training cost in chennai
    big data training in chennai omr
    big data training in chennai velachery

    ReplyDelete
  10. Great Post,really it was very helpful for us.
    Thanks a lot for sharing!
    I found this blog to be very useful!!
    JAVA training in Bangalore

    ReplyDelete

  11. Thank you for sharing the article. The data that you provided in the blog is informative and effective. Best Devops Training Institute

    ReplyDelete
  12. Thanks for explanation about the literate programmer
    Sanjary Kids is one of the best play school and preschool in Hyderabad,India. Give your child the best preschool experience by choosing the best playschool of Hyderabad in Abids. we provide programs like Play group,Nursery,Junior KG,Senior KG,and provides Teacher Training Program.
    pre and primary teacher training course in hyderabad

    ReplyDelete
  13. This comment has been removed by the author.

    ReplyDelete
  14. Effective blog with a lot of information. I just Shared you the link below for Courses .They really provide good level of training and Placement,I just Had Web Design Classes in this institute , Just Check This Link You can get it more information about the Web Design course.


    Java training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery

    ReplyDelete
  15. This is excellent information. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...

    digital marketing course in hubli

    ReplyDelete
  16. Thanks for Sharing a Very Informative Post & I read Your Article & I must say that is very helpful post for us.
    Data Science
    Selenium
    ETL Testing
    AWS
    Python Online Classes

    ReplyDelete
  17. Hi thanks for sharing nice information.
    if you are lookingpersonal trainervisit my site.

    ReplyDelete
  18. That's really impressive and helpful information you have given, very valuable content.
    We are also into education and you also can take advantage really awesome job oriented courses

    ReplyDelete
  19. Thank you so much for sharing all this amazing information, keep it up.
    are you want to make a career in UI Development. check this UI Development Course in Bangalore.
    Attend The Best Front-end Certification Training In India From AchieversIT. Practical Front-end Training Sessions With Assured Placement Support From Experienced Faculty. and also proving live projects
    AchieversIT Training Institution

    ReplyDelete
  20. This site helps to clear your all query.
    This is really worth reading. nice informative article.
    bu bhopal ba final year result
    mp bhoj ba 3rd year result

    ReplyDelete
  21. great post ! This was actually what i was looking for and i am glad to came here!
    F5 Load balancer Training
    SAP Ariba Training
    MuleSoft Training

    ReplyDelete
  22. I read this post,Thanks for sharing this information.

    Machine learning classes in Pune

    ReplyDelete
  23. Very awesome!!! When I seek for this I found this website at the top of all blogs in search engine.
    data science course in malaysia

    ReplyDelete
  24. Nice to be visiting your blog once more, it has been months for me. Well this article that ive been waited for therefore long. i want this article to finish my assignment within the faculty, and it has same topic together with your article. Thanks, nice share.
    data scientist course in hyderabad

    ReplyDelete
  25. I see some amazingly important and kept up to length of your strength searching for in your on the site
    data scientist course in malaysia

    ReplyDelete
  26. Online Training | Classroom | Virtual Classes
    SQL Server Training with 100% placement assistance
    1860 testers placed in 600 companies in last 8 years
    Real time expert trainers
    Indutry oriented training with corporate casestudies
    Free Aptitude classes & Mock interviews

    ReplyDelete
  27. Thanks for the blog but If your looking to switch your career to the Airline Industry we the Fusion is the best place to pursue. It is one of the best Air Hostess course

    ReplyDelete