Two Vexing Problems in Functional Programming
So, as the trend of forcing functional programming into imperative languages continues on its inexorable path, I just can&#x27;t help but bring the old joke to mind more and more often:<p><pre><code>    &quot;Doctor, it hurts when I do this.&quot;

    &quot;Well, then, don&#x27;t do that.&quot;
</code></pre>
You mean, jamming a foreign paradigm into a language, where the advantages of the foreign paradigm are reduced and the disadvantages greatly magnified, hurts sometimes?<p>Have you considered... <i>not</i> doing that?<p>I simply can not apprehend the mindset that goes:<p><pre><code>    1. Wow, map&#x2F;filter&#x2F;reduce sure is fun in this language over here
       designed to work with it.
    2. Now I&#x27;m going to use everywhere I go, no matter how much it hurts
       and no matter what compromises I have to make.
    3. When it hurts, I will blame anything and everything except myself
       for forcing a paradigm in where it doesn&#x27;t belong.
</code></pre>
The paradigm <i>has</i> to be good. It just <i>has</i> to! Even if it hurts! Even if I&#x27;m really not enjoying using it! Even if it&#x27;s murdering my runtime and killing my performance and I&#x27;m in a language where functions take quite a lot of text rather than \x -&gt; x + 1! Even if my code is hard to read and hard to abstract and hard to refactor. Even if the foreign paradigm is critically based on pervasive laziness my language doesn&#x27;t have! Or some other foundation my current language totally lacks! Gosh darn it, <i>I&#x27;m going to use this paradigm in this code if it kills me!</i> Because it was so much fun... <i>over there</i>.<p>I&#x27;m not saying that it isn&#x27;t sometimes useful to borrow paradigms in certain places even in languages that don&#x27;t support it. When it <i>doesn&#x27;t</i> hurt like this, by all means use it as you like. What I don&#x27;t understand is this constant, if not <i>growing</i>, stream of posts about &quot;my gosh, my forced FP programming in this not-FP language is kinda painful here... <i>grimaces</i> yup, it&#x27;s pretty painful all right... <i>grits teeth</i> yup, this is really hurting me and making me really angry and isn&#x27;t fun at all... but I&#x27;m <i>so glad</i> I&#x27;m using this style that is making things hard and hurting me and making me angry, wouldn&#x27;t dream of doing anything else!&quot;<p>I know Haskell. There are many lessons I&#x27;ve taken from Haskell and applied to other languages, like the virtue of very strongly separating IO code from logic, the virtues of taking extra steps to provide and use composability in your APIs, the virtues of certain things being immutable data. But taking these lessons from functional programming languages shouldn&#x27;t mean you ape the surface solutions functional programming uses; you should be thinking about how to <i>idiomatically</i> bring the target virtues into the other languages you use. There will be compromises, but sometimes there will also be things the current language does better than Haskell. (Really quite a lot of things. Haskell&#x27;s great but there&#x27;s many reasons it hasn&#x27;t conquered the world.) You shouldn&#x27;t be so focused on importing the foreign paradigm that you completely throw away the virtues of the environment you&#x27;re in.<p>I do not understand why so many of you are so vigorously adamant that you&#x27;re going to program in the intersection of functional programming languages and imperative programming languages. It&#x27;s an incredibly aggravating place to try to be. The (near) union, applied with the wisdom gleaned from both camps, is much more fun.