Demystifying Design Pattern in a Functional Way

Explore design patterns through a functional programming lens. Discover how Church's approach differs from Turing's OOP and why it matters for modern development.

3 min read 580 words

As functional programming is taking pace in current software development, there is always a question: what is the difference, and why on earth should I bother about it?

Most of the time, the reason for the question comes from human nature's resistance towards learning new things. And then there are people who can easily learn new things, but even for them, unlearning something and relearning new things is pretty tough. And this makes a problem every time.

Here I am not saying I am going to explain anything as an expert. I am nowhere near an expert, and I also face the same problems as above. But I guess new things are always worth trying.

Now, one of the things that gets projected as a silver bullet for every software solution is Design Patterns. Now, for the facts, they are good, very good. Maybe the best thing that can happen to Object Oriented Programming. But it is showing a concept, and most of the time we lose that concept in an implementation.

If we go into history, there are two ways of solving problems: one is Turing's way (OOP), and the other is Church's way (FP). That is it. They are both ways, and you can achieve goals both ways.

Now here comes the personal choice: what way you like to choose based on given circumstances. Turing's way is good when I have limited resources to process details/data. While Church's way is good when I have a good number of resources to process details/data.

For me, or I guess for all the people from the functional programming community, Church's way is a choice. And the visible benefit of selecting that is the readability and representation of the code I am doing. It is more like what I am saying is what I am writing. And now it is up to the computer to process that. Now, the computer needs to be powerful enough to process almost natural language.

I am not considering natural or logic language here. It is out of scope of this article, blog, and also my brain for now.

And that is why it is getting pace nowadays. We are having hardware resources to process that. Or maybe we can say it the reverse way: to utilize this much hardware, the Church-based approach is far better, as it has benefits towards making things simple.

I have said simple; I haven't said easy.

Now, here comes the problem. I need to unlearn or relearn the concepts I have learned. And I have made it easy for me after working so hard.

Practically speaking, I don't see any way out. But there is no need to completely unlearn it; maybe it can be used in some other way. Like the Design Patterns from the Object Oriented world.

I guess that was easy and simple both. Everything is just functions. Okay, that said, I am sharing a video that everyone in functional programming just loves from Scott Wlaschin.

Functional programming design patterns by Scott Wlaschin from NDC Conferences on Vimeo.

Now, in coming posts, I will try to take every pattern one by one and try to demystify it. Obviously in a functional way. And also try to explore some functional patterns as well. Stay tuned.

Frequently Asked Questions

What is the difference between Object-Oriented Programming and Functional Programming?

Object-Oriented Programming (Turing's way) and Functional Programming (Church's way) are two fundamental approaches to solving problems in software development. OOP is more efficient when working with limited computational resources, while FP is better suited for systems with abundant resources and emphasizes code readability and simplicity. Both are valid approaches, and the choice depends on your specific circumstances and available hardware.

Why is functional programming gaining popularity in modern software development?

Functional programming is becoming more prevalent because modern hardware has become powerful enough to handle the computational overhead of this approach. FP makes code more readable and closer to natural language, which means it's easier to understand what the code does at a glance. Additionally, FP is excellent for utilizing modern multi-core processors and handling large-scale data processing efficiently.

Do I need to completely abandon Object-Oriented design patterns when adopting functional programming?

No, you don't need to completely unlearn OOP concepts. While some traditional OOP design patterns may not apply directly in functional programming, the core concepts and problems they solve can still be valuable. Functional programming has its own set of patterns and approaches that can be adapted to solve similar problems in a functional way.

What is the main challenge when transitioning from OOP to functional programming?

The primary challenge is unlearning established OOP patterns and relearning new functional programming concepts, which goes against human nature's resistance to change. Even experienced developers who can learn new things quickly find it difficult to rewire their thinking patterns after years of OOP development.

Share this article