Functional PHP (2015)
The author advocates for using functional programming in PHP, highlighting benefits like improved modularity, reduced complexity, easier debugging, and enhanced maintainability through small, single-purpose functions and higher-order functions.
Read original articleThe article discusses the author's experience with writing PHP code in a functional programming style. The author found this approach beneficial, as it allowed for clear separation of responsibilities through the use of small, single-purpose functions. By utilizing functional programming concepts such as immutability and higher-order functions like `map`, `reduce`, and `filter`, the code became more modular and easier to maintain. The author noted a significant reduction in errors and complexity, with a maintainability index that improved with the addition of comments. The functional style facilitated easier modifications and debugging, making it simpler to identify and fix issues. Overall, the author advocates for the functional programming approach in PHP, highlighting its advantages in creating clean, efficient, and testable code.
- The author successfully implemented functional programming principles in PHP.
- The approach led to improved code modularity and maintainability.
- The use of small, single-purpose functions reduced complexity and errors.
- The functional style made debugging and modifications easier.
- The author encourages the adoption of functional programming in PHP development.
Related
I Probably Hate Writing Code in Your Favorite Language
The author critiques popular programming languages like Python and Java, favoring Elixir and Haskell for immutability and functional programming benefits. They emphasize personal language preferences for hobby projects, not sparking conflict.
Functional languages should be so much better at mutation than they are
The article explores integrating mutation into functional programming, discussing methods like restricted mutable structures, local mutation, and linearity, while highlighting challenges and the need for a balanced approach.
What's Functional Programming All About?
Functional programming is often misunderstood, focusing on irrelevant details. It emphasizes complexity control and clearer structures, contrasting with imperative programming's challenges, promoting better error handling and refactoring.
PHP is the new JavaScript?
PHP is regaining popularity, primarily due to the Laravel framework, which enhances its development experience with structured features, shifting perceptions in the developer community towards its viability for modern applications.
Functional Programming to Help Write Efficient, Elegant Web Applications
Functional programming enhances web application development through immutability and pure functions, improving predictability and maintainability. Kotlin supports both paradigms, facilitating gradual adoption of functional concepts for clearer logic.
Btw while this code doesn't win a prize, I agree with the author that functional style is worth it in many cases, even for a language as wordy and cumbersome as PHP. I still love PHP - its deployment story is still unparalleled and its standard library came batteries included since forever.
Writing pure FP code (pushing all the side effects to the "edges of the program" in C is possible! But it's going to take a lot of discipline from the programmers: there is no safety-net and lots of dreadful boilerplate.
Impracticle, but possible.
> Instead of fearing the overhead in PHP for function calls,
Already in 2015 in almost all applications this is a premature optimization which is rightly known as the root of all evil. Please. Your app will talk to the network, likely run a database query which is like thousands or millions of times slower than a function call. Further, even if there is a measurable difference the cost of hardware which makes that difference go away is very likely to be smaller and much smaller at that than the cost of the engineering hours wasted during maintenance when wrestling with code which was written with a "function calls are expensive" mindset.
This doesn't mean you don't need to worry about performance and scalability but even that is going to be much easier if you have a well structured code.
Related
I Probably Hate Writing Code in Your Favorite Language
The author critiques popular programming languages like Python and Java, favoring Elixir and Haskell for immutability and functional programming benefits. They emphasize personal language preferences for hobby projects, not sparking conflict.
Functional languages should be so much better at mutation than they are
The article explores integrating mutation into functional programming, discussing methods like restricted mutable structures, local mutation, and linearity, while highlighting challenges and the need for a balanced approach.
What's Functional Programming All About?
Functional programming is often misunderstood, focusing on irrelevant details. It emphasizes complexity control and clearer structures, contrasting with imperative programming's challenges, promoting better error handling and refactoring.
PHP is the new JavaScript?
PHP is regaining popularity, primarily due to the Laravel framework, which enhances its development experience with structured features, shifting perceptions in the developer community towards its viability for modern applications.
Functional Programming to Help Write Efficient, Elegant Web Applications
Functional programming enhances web application development through immutability and pure functions, improving predictability and maintainability. Kotlin supports both paradigms, facilitating gradual adoption of functional concepts for clearer logic.