What’s so great about functional programming anyway?
I&#x27;m sure this is a wonderful intellectual exercise in computer science and math, but if this is to be the advertisement in favor of functional programming, I wouldn&#x27;t consider myself a customer.<p>You start out with code that will not win any beauty awards but it gets the job done. It&#x27;s easy to understand by programmers of any seniority, it&#x27;s simple to debug and reasonably easy to put in an automatic unit test.<p>Next, you add all kinds of vague, poorly named meta utilities that don&#x27;t seem to solve any tangible real world problem. You even mess with built-in JS methods like map. The code is now harder to understand and more difficult to debug.<p>A massive pain is added for some theoretical purity that few even understand or will benefit from. I&#x27;ll double down on my rebellion by stating that the portability of code is overrated.<p>Here we&#x27;re writing code to format notification objects. In our overengineering mindset, we break this down into many pieces and for each piece consider reusability outside this context to be of prime importance.<p>Why though? Why not just solve the problem directly without these extra self-inflicted goals? The idea that this is a best practice is a disease in our industry.<p>Most code that is written prematurely as reusable, will in fact never be reused outside its original context. And even if it is reused, that doesn&#x27;t mean that outcome is so great.<p>Say that the sub logic to format a user profile link turned out to be needed outside this notification context. Our foresight to have made it reusable in the first place was solid. Now two completely different functional contexts are reusing this logic. Next, the marketing department goes: well actually...you need to add a tracking param specifically for links in the notification context, and only there.<p>Now your &quot;portability&quot; is a problem. There&#x27;s various ways to deal with it, and I&#x27;m sure we&#x27;ll pick the most complicated one in the name of some best practice.<p>After 20 years in the industry, you know how I would write the logic? A single method &quot;formatNotification&quot;. It wouldn&#x27;t weirdly copy the entire object over and over again, it would directly manipulate the object, one piece at a time. Error checking is in the method as well. You can read the entire logic top to bottom without jumping into 7 files. You can safely make changes to it and its intuitive to debug. Any junior would get it in about 2 minutes.<p>Clear, explicit code that requires minimum cognitive parsing.