Can Functional Programming Be Engineering? by Alexander Granin

September 10, 2024

In the Can Functional Programming Be Engineering? presentation by Alexander Granin, Alexander expresses concerns about the lack of a well-defined software engineering discipline for functional programming languages. He argues that while functional programming has been in development for several decades, its engineering aspects have only started emerging in the last 10 years. Alexander uses the metaphor of “witchcraft” to describe functional programming’s abstract and unpredictable nature, contrasting it with engineering’s focus on process, methodology, and shared language. He also discusses the application of mathematical concepts in functional programming and the need for practical approaches and pragmatism. Alexander emphasizes the importance of understanding the differences between abstract concepts and functional idioms and encourages the use of design patterns and principles from object-oriented programming in functional programming. He concludes that functional programming can be engineering but requires more industrial adoption and practical resources to keep up with the industry.

Can Functional Programming Be Engineering?: A comprehensive overview

The social situation in Functional Programming

Alexander Granin begins by expressing concerns about the functional programming community, noting a lack of a well-defined software engineering discipline within Functional Programing (FP). Despite decades of development, FP has yet to fully establish itself in the engineering domain, something that Alexander argues has only started emerging in the past decade. He uses the analogy of Gadget Hackwrench, a creative and innovative engineer from Chip and Dale Rescue Rangers, to question what truly defines engineering and how software engineering compares to fields like civil or mechanical engineering.

 

Engineering vs. Science vs. Witchcraft?

Alexander’s unique perspective likens software development to a mix of engineering, science, and, intriguingly, witchcraft. Engineering, in his view, is a process-driven activity that demands rigor, methodology, and shared language. Development is broader, encompassing coding, architecture, documentation, and client communication. And then there’s “witchcraft” — Alexander’s metaphor for FP’s experimental, abstract, and somewhat mysterious nature. He suggests that FP often feels like magic, operating outside the predictable frameworks of engineering or science.

Where traditional engineering avoids unnecessary complexity, functional programming sometimes thrives on it, particularly with its deep mathematical underpinnings. Alexander points out that in science, complexity is embraced because simple discoveries have already been made. Engineering, however, focuses on simplification, clarity, and efficiency.

 

Functional Programming as witchcraft?

One of the most thought-provoking sections of Alexander’s talk is his comparison of FP to witchcraft. He explains that FP, with its emphasis on abstract theories like category theory and its use of type systems, often feels secretive and removed from the practical needs of day-to-day business programming. The FP community’s focus on complex math-based theories can sometimes make it difficult for mainstream developers to see its real-world applications. This gap, Alexander argues, is a significant reason why functional languages have struggled to gain wider industrial adoption.

 

The need for pragmatism and discipline in FP

Granin critiques the functional programming community for its lack of practical frameworks and methodologies. While there are many libraries and abstract mathematical concepts in FP, Granin argues that the community has not produced enough resources for best practices, application architecture, or design patterns that developers can readily use. He mentions the success of opinionated frameworks like Scala’s ZIO and the Actor model in Erlang as examples of FP frameworks that provide developers with clear, structured approaches.

According to Granin, what FP needs is pragmatism. Functional programming should embrace practical engineering disciplines, rather than remaining heavily theoretical. He proposes developing a comprehensive methodology called “Functional Declarative Design” to bridge this gap between theory and practice, helping FP gain more acceptance in industry.

 

Design patterns in FP: Not just for OOP

Alexander challenges the popular notion that design patterns are exclusive to object-oriented programming (OOP). He argues that FP has its own set of design patterns, even if they are not as widely recognized or applied. These include functional interfaces and idioms that guide developers to write applications without unnecessary abstractions. Concepts like encapsulation and interfaces, typically associated with OOP, can be beneficial in functional languages as well.

By revisiting these design principles, functional programmers can adopt a more mature engineering attitude, ultimately improving software quality and aligning FP more closely with mainstream development practices.

 

Bridging the gap: Functional Programming and industry adoption

A critical part of Alexander’s talk addresses the slow adoption of functional programming in industry. He emphasizes that while FP offers many powerful concepts, the lack of a structured, systematic knowledge base makes it difficult for businesses to trust and implement FP solutions. Languages like Elm, which offer opinionated and vision-driven approaches, have shown that this level of structure can reduce risks and make FP development more consistent.

 

Engineering principles in FP

Alexander concludes by highlighting that many core engineering principles from mainstream software development can be applied to functional programming. Concepts like SOLID principles — Single Responsibility, Dependency Inversion, and Liskov Substitution — are just as relevant in FP as they are in OOP. FP, according to Alexander, should embrace these ideas to attract more developers and businesses.

He stresses that in FP, engineers must understand when to use abstractions like functors and applicatives and when to avoid them to reduce unnecessary complexity. By distinguishing between essential FP idioms and patterns, functional programmers can communicate more effectively with mainstream developers and facilitate wider industrial adoption.

 

Final thoughts: Can Functional Programming be engineering?

Alexander Granin’s talk raises an important question: Can functional programming be considered engineering in the traditional sense? While it might not fit perfectly within the established framework of engineering, Granin argues that it has the potential to evolve into a more disciplined practice. FP is still in its early stages of developing a structured, systematic approach that can cater to industry needs, but with the right methodologies and frameworks, it can bridge the gap between theory and practice.

Alexander’s vision for FP is one that blends its mathematical elegance with pragmatic engineering principles. By creating tools, methodologies, and frameworks that help developers apply FP to real-world problems, he believes functional programming can establish itself as a legitimate engineering discipline.

 

Additional resources

Check out more from the MeetUp Func Prog Sweden. Func Prog Sweden is the community for anyone interested in functional programming. At the MeetUps the community explore different functional languages like Erlang, Elixir, Haskell, Scala, Clojure, OCaml, F# and more.