re: Write Unbreakable Python VIEW POST

re: So as soon as you have IO you will not get "purity" on a higher level. I just found it a it a bit weird to explain functional concepts on an IO b...

Yeah, agree. The challenges I have with teaching Functional Programming:

  • many don't use it
  • many don't know it's a different "thing"
  • many are forced to use non-functional languages
  • most non-FP languages have no good way to handle side effects in a pure way
  • using FP could still help them in non-FP languages

That last point is what I'm trying to help people with. They don't need to be 100% pure to glean benefits of code that is more deterministic.

Even using the pain of Dependency Injection still massively benefits unit testing by removing their need of mocks. Stubs are big, no doubt, but Mocks are larger and harder to reason about.

Completely removing Exceptions allows all their functions to break more predictably in a very imperative way. Some people coding, or learning, still think and code in this way. Go's way of error handling is exactly this. We can give people the Algebraic Data Types of Result and Maybe, allow them to use those FP concepts, yet they still use them in an imperative way. So they don't have to change much about their style, yet they reap benefits.

Even something as simple as using PyDash over Python's native loops has huge determinism benefits.

Until managed effects like Elm has get ported to things like Python/Ruby/Lua, et. all, you basically have the same 3 choices:

  • give up and learn a pure FP language
  • use the Effect pattern
  • use DI

There IS hope, too, as I've seen some Effect style patterns implemented in JavaScript to make things like Promises (wanna be Monads) easier to use and not eager. People aren't going to leave Python. It's our job as FP lovers to help bring the awesome, and "make it work" in their world. I get being pragmatic technically breaks all the math... but I feel it's worth it.

Hi, good point. What about summarising this as an extra paragraph, and also comment that the way you use "pure" might not be the exact definition?

Code of Conduct Report abuse