Better Programming

Advice for programmers.

Follow publication

Member-only story

5 Anti Patterns to Avoid When Writing Code in a Functional Programming Language

Edward Huang
Better Programming
Published in
7 min readApr 19, 2022
Photo by Priscilla Du Preez on Unsplash

Functional programming languages have gained so much traction in these past few years.

Many people can see the benefit of writing code that contains features such as functions as a first-class citizen. They embrace immutability in a concurrent environment, running heavy computed tasks without worrying about some concurrency issue, and love to write generic code to be as DRY as possible.

I saw this as a good sign that functional programming language is becoming mainstream again. However, one of the hard parts of writing code in a functional programming language is its design pattern and anti-pattern, which are different from a regular programming language.

I often see engineers writing in a large codebase that I classified them anti-pattern. I had also committed to these anti-patterns when I initially wrote a production-ready application in a functional programming language. Since then, I have read many books about functional programming design patterns and books that have helped me create a more maintainable code.

Overly nested anonymous callback function.

An anonymous function can be good for code-reusability. However, too much anonymous function can hurt the eyes of those engineers who want to extend the functionality. Although DRY is the way to go, sometimes duplication is better than the wrong abstraction.

I have touched codebase where engineers will write a heavily concise and abstract method. The code is something like this:

Can you tell me what the definition of buildRunner is?

Then, this buildRunner is used in all action operations like authorize, capture, and void in the payment processor. I look at it for two days to finally understand what it is trying to do.

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Edward Huang
Edward Huang

Written by Edward Huang

Follow my Newsletter @ https://pathtosenior.substack.com/ | Twitter: @Huan72349Edward | Medium Publication Index @ https://forms.gle/YfyssUruGUKyATXy9

Responses (2)

Write a response

Thank you for sharing this. Very useful 💯👏

--

Saved! It's something I want to get into but software prices are daunting. What do you use? I love your graphics btw - that one at the bottom is clever!

--

This was helpful. Thank you for sharing.

--