4Developers 2016: Podejście funkcyjne w projektowaniu oprogramowania (Tomasz Kowalczyk)
Presenters detail vulnerability discovery and exploitation in 4Developers 2016: Podejście funkcyjne w projektowaniu oprogramowania (Tomasz Kowalczyk).
Summary
## Overview
Tomasz Kowalczyk presents a pragmatic approach to functional programming concepts applied directly to software design, specifically in PHP. Rather than covering functional programming theory (monads, type theory, etc.), the talk focuses on how to think functionally about code to improve readability, maintainability, and reliability in real-world projects.
## Key Topics
**Core Concepts** The speaker introduces immutability—the idea that state changes should be explicit and create new entities rather than mutating existing ones—and higher-order functions (map, filter, reduce), which operate on collections of data. He emphasizes that this presentation is not about pure functional theory but about practical application of these principles.
**PHP-Specific Challenges** The speaker notes that PHP's array_map, array_filter, and array_reduce functions have a significant limitation in PHP5: they throw warnings (not catchable exceptions) when the callback function encounters errors. He mentions this was fixed in PHP7. He also discusses potential PHP optimizations through inlining that could mitigate performance concerns from creating intermediate collections.
## Technical Details
**Code Refactoring Examples**
1. **Filtering Active Users**: Starting from nested loops with conditional continues, the code is refactored first into named anonymous functions with chained filter calls, then further improved using collection classes with fluent syntax (e.g., `Users.filter(notHidden).filter(notBlocked)`).
2. **Data Transformation**: Extracting tag IDs from users is shown progressing from nested loops to functional chaining of map, reduce, and filter operations, making the business logic explicit.
3. **Reduce Operation**: Summing user points demonstrates the replace of accumulator loops with the reduce operation.
**Higher-Level Applications** Beyond code-level examples, the speaker illustrates functional thinking at system level: request lifecycle in Symfony (superglobals → request object → routing → controller execution → response), serialization/deserialization as a composition of normalization and formatting operations, and SQL queries as inherently functional (SELECT, JOIN, WHERE as filtering operations).
## Key Advantages
- **Named Operations**: Prevents code "rust"—the accumulation of conditions and loops that become unmaintainable. Named operations make business logic clear. - **State Transformation Guarantees**: Each functional operation transforms data from one well-defined state to another, providing mathematical certainty about outcomes. - **Paradigm Shift**: Shifts focus from "how to do it sequentially" to "what operations compose to achieve the result," enabling easier composition and reuse. - **Thinking in Sets**: Encourages developers to think about collections transforming through operations rather than imperative step-by-step procedures. - **Explicit State Management**: All state changes are visible; any non-obvious mutations (via closures, reflection) become immediately apparent. - **Operation Reusability**: Once defined, operations often become useful in unexpected contexts, providing consistent results across the application.
## Arguments and Objections
The speaker addresses three main counterarguments:
1. **Both Approaches Work**: Acknowledges that imperative and functional code produce the same results. Success requires team buy-in, genuine arguments about code quality, and organizational will to prioritize maintainability.
2. **"This Isn't PHP Style"**: Counters that PHP has evolved like all languages; just as assembly was acceptable decades ago, modern software engineering practices should be adopted to meet industry standards.
3. **Performance Concerns**: Notes that each operation creates intermediate collections, which is a legitimate concern. However, discusses potential PHP optimizations (inline/inlining of function bodies during compilation) and argues that performance concerns are moot if the data volume is reasonable (e.g., processing 1000 users per request).
## Recommended Resources
The speaker recommends Nikic's iter library (available in Composer) which provides functional primitives like map, filter, reduce, take-while, take-until, all, first, etc.—operations that transform collections in a functional style.
## Conclusion
Functional programming concepts, when applied pragmatically rather than dogmatically, improve code clarity and reduce errors. The key is to stop thinking sequentially ("do this, then that") and start thinking transformationally ("transform data through these operations"). This applies at code level and extends to thinking about entire system architectures functionally.
Related talks
PROIDEA Events·45 min
Ula Mitas
Ula Mitas details 4Developers 2022: Psychologia w projektowaniu - czy zachowania można zaprojektować?.
PROIDEA Events·12 min
Ola Kunysz
Ola Kunysz details 4Developers 2021: Jakość oprogramowania to nie tylko kod i testy.
PROIDEA Events·58 min
Industry experts analyze emerging threats surrounding 4Developers 2015: Funkcyjne zabawki w obiektowej piaskownicy (M. Malinowski).


