Skip to content

4Developers 2016: Real-World Gobbledygook (Paweł Szulc)

Paweł Szulc

WirelessPROIDEA Events46 minBeginnerOpen on YouTube ↗

Security researchers examine technical aspects of 4Developers 2016: Real-World Gobbledygook (Paweł Szulc).

Summary

### Overview In this presentation delivered at the 4Developers 2016 conference, the speaker addresses the perception among mainstream object-oriented developers that functional programming consists of academic jargon ("gobbledygook") detached from real-world software engineering. Through a narrative centered on a senior developer named Jimmy who is building an auction service without access to Stack Overflow or external libraries, the presentation demonstrates how common object-oriented design patterns can lead to bloated domain models and tight coupling. The talk then shows how core functional programming abstractions—specifically type classes and ad-hoc polymorphism—offer a clean, modular solution to decouple domain logic, serialization, and calculations.

### Key Topics - **Demystifying Functional Concepts:** Translating high-level abstract vocabulary (type classes, semigroups, monoids, ad-hoc polymorphism) into practical programming concepts. - **Limitations of Subtype Polymorphism:** How standard OOP approaches (such as adapter patterns and interface inheritance) cause domain entities to accumulate unrelated responsibilities like JSON serialization, calculation logic, and conversion methods. - **Type Classes and Separation of Concerns:** Using type classes to define behaviors externally to the data models rather than embedding operations directly inside class hierarchies. - **Ad-Hoc Polymorphism and Implicits:** Leveraging Scala's implicit parameter resolution to cleanly pass type class instances without cluttering business call sites. - **Algebraic Abstractions (Semigroups and Monoids):** Recognizing patterns such as combining values and folding lists using associative operations and identity/zero elements.

### Technical Details - **Domain Setup:** Jimmy designs an auction model comprising orders (general order, complex order, canceled order) and products (regular, discounted, out of stock). Initially, algebraic operations and evaluation are added directly to the class hierarchy via inheritance. - **The Bloat Problem:** Requests for new capabilities—first computing averages across generic numeric types (`BigInt`, `BigDecimal`, `Double`), then serializing entities into JSON (`toJson`), and finally evaluating business logic (`evaluate`)—lead to classes weighed down by non-domain responsibilities and messy adapters. - **Type Class Refactoring:** - The speaker refactors the solution by introducing separate parameterized traits: a numeric type class with operations like addition and division, a JSON serializer trait (`Json[A]`), and an evaluation trait (`Evaluate[A, T]`). - Implementations (instances) are declared independently from the domain classes as singletons/objects. - In Scala, these instances are supplied via implicit parameters, allowing domain classes to remain clean, immutable abstract data types (ADTs). - **Simplification via Semigroup/Monoid:** For order reduction (`simplify`), Jimmy implements folding by defining an associative binary combination operation (`add`) alongside an identity element (`zeroValue` representing an empty/canceled order). The speaker explains that this corresponds directly to mathematical semigroups and monoids.

### Takeaways - Functional programming concepts like type classes, monoids, and semigroups are not merely academic theory; they function as generalized design patterns for solving common software engineering challenges. - Keeping domain models as pure data structures (ADTs) and separating behaviors into type class instances ensures high cohesion, loose coupling, and clean extensibility without modifying existing classes. - Complex-sounding category theory terms often map directly to straightforward operations (e.g., combining two elements of the same type associatively), making functional patterns directly applicable to everyday programming.

Related talks