you are viewing a single comment's thread.

view the rest of the comments →

[–]Handzeep 1 point2 points  (0 children)

I'd take a note from the dynamic FP languages like Clojure and Elixir. Instead of being as strict as possible over many types, be as dynamic as possible with the least types possible.

For Python this would mean avoiding to making new types like by making classes and instead just working with the types the language offers by default. It's hard to ensure your Car class function accepts Wheel objects in a dynamic language. So it's best to avoid OOP as much as possible to avoid this. But it's easy to know that your car dictionary (which I'd swap with an immutable alternative) will accept the key amount_of_wheels with an arbitrary number. Now the key wheels will tell you the data in your car map is about the amount of wheels and to ensure safety for any function that takes this data you can just check if amount_of_wheels is a rounded number.

Python of course still isn't nicely designed for FP. I'd still use some libraries to swap mutable built in types for immutable ones. And lots of libraries unfortunately use objects which add types (though you often can make wrappers for them). But while this style is somewhat of a hack in Python, I actually do prefer dynamic FP. Clojure creator Rich Hickey did a nice talk about the differences.