all Technical posts

How Functional Programming Concepts Stimulates Creative Thinking

Functional programming can be closely related to how we solve problems in our head. The trick is to let the creativity flow, instead of frantically holding onto rigid concepts. We'll go over this today.

Logic will get you from A to B: imagination can take you anywhere

Programming is in its essence a creative process. There are so many books and courses on how to write stable and secure code, but not so many about the flexible problem-solving process. I am not talking about the specific code syntax or statements (if-else, loop, switch etc.) per se: I am talking about the initial brain processes that analyze the problem. Design patterns are so common and built-in that people want to solve everything using them. I was one of those people, and this is one of the most used practices in code development. Design patterns are there because they have worked before and have grown into these reusable and reliable patterns. There’s nothing wrong with this – unless you want to write even better code.

What I’ve come across in working on object-oriented projects is that the code becomes very strict and rigid. Just as in everyday life, we try to compartmentalize and categorize everything without actually seeing anything. Sometimes the code is so static that the creative ideas are boiled down to only fragile versions of what they were. You see this again and again: the idea is there but the used framework holds you back. More than half a decade ago, I found the answer to this problem.

Letting go of everything you fear to lose

Functional programming was the answer. Looking backwards, the reason for this was simple: functions are smaller than objects. Object-oriented programming works and lets you express your ideas through objects, but if those ideas are bold enough, this programming technique can be a burden rather than a helpful tool. We must remember that the code language and practices are only a vehicle for the solution, not the solution itself. If the vehicle is not suited, we have to try something else.

On one hand, providing support for code solutions that always have the same code structure and patterns is easier, but even with creative processes, there is still a way to provide guidance and direction. Creativity does not mean that everything is a surrealistic painting. Functional programs and F# in particular are perhaps even more structured, as the file order and code order matters when compiling. An experienced F# programmer will therefore always look at the lowest line in the lowest file, because that is the starting point where everything comes together.

It is only when functions are much smaller building blocks that ideas are more easily expressed in such a system. Remember LEGO and DUPLO bricks? Small LEGO bricks feel like functions, while larger DUPLO bricks are more like objects. You can build similar constructions, but once the construction becomes more complex, you want to look at your problem with a more clinical approach. And just like the creators of LEGO say: “Everything can be built with LEGO.”

Free your mind

Once you understand that there is more to programming than objects, you can start by looking at your problem in a new way. Forget for the moment dependency injection, inversion of control containers, repositories, interfaces, and other typical OOP constructs. Look at your problem with a clear and open mind. Is it about conversion or enrichment? Is it about connecting one system to another? Is it about coming up with a centralized language? Identify your values in your problem and think about what actions those values should undertake. The actions become functions, unbounded by classes or services. Thinking about your problem in a functional manner is a really freeing feeling — as if the unlimited potential is contagious.

This is the true reason why functional programming stimulates creative thinking: you start inside your mind and come up with new ways to interact with your problem, instead of trying to brute force it into existing concepts.

Conclusion

We like to think of ourselves as liking change, and that we are brave enough to incorporate it into our daily work. Functional programming is one of those changes that people are not always eager to implement. Why? Probably because it radically changes the way we approach code solutions. It can be scary, of course. OOP is a strict framework of patterns and designs that you can pick and use. What FP does is step away from these common patterns, letting your mind speak for itself. You will see that the solutions it brings are simple, to the point, and most of all more readable and closer to the problem you are trying to solve.

A good practical example of how functional programming stimulates creative thinking in full is my other post on the beautiful F# Expecto paradigm, where I talk about how tests can be written in a more maintainable and easier way if we let go of rigid testing frameworks.

Be brave, try functional programming techniques. It will feel strange at first, but that happens with all change. Over a very short period of time you will see that it frees your mind to be as creative as you possibly can. Imagination has no boundaries.

Thanks for reading!
Stijn

Subscribe to our RSS feed

Hi there,
how can we help?

Got a project in mind?

Connect with us

Let's talk

Let's talk

Thanks, we'll be in touch soon!

Call us

Thanks, we've sent the link to your inbox

Invalid email address

Submit

Your download should start shortly!

Stay in Touch - Subscribe to Our Newsletter

Keep up to date with industry trends, events and the latest customer stories

Invalid email address

Submit

Great you’re on the list!