Lessons and Pitfalls Coming To Node.js From PHP

Having worked almost exclusively in PHP for several years, eventually the Node.js hype caught up with me when my team decided to adopt it for the development of microservices. I was skeptical about that choice mainly because while I was quite open to switching away from PHP, I would have preferred to switch to a language I thought would be actually better. JavaScript was not on my language wish list.

Read more

Share

Functional Reactive Game Programming

Elm is a purely functional language designed for web frontend development. It promises a better developer experience than Javascript thanks to its powerful type system and compile-time type checking. Elm comes with a library for reactive user interface programming, the paradigm made (very) popular by React.js. I first learned about Elm at a meetup hosted by my employer, and was intrigued right away. Functional languages have had a strange attraction on me ever since I was taught Haskell in university, but I had never since found the opportunity to reconnect with them after graduation.

Read more

Share

Improve Your Code with Import Aliases

Ever since PHP introduced namespaces in version 5.3, it has been possible to import classes under alias names. In my experience, developers only make use of this feature when forced to – i.e., to avoid name conflicts. I’d like to propose another potential use for them that I have found convenient once or twice: to improve naming. Let’s say I am working with this JWT library, which has a class with the rather generic looking name Builder.

Read more

Share

Single Use Controllers in Symfony

Jordan Crocker just wrote a post about single-use controllers, a very simple pattern designed to combat the clutter that occurs all too often in the controller layer of typical web applications. Rather than stuffing all actions that refer to the same type of resource into the same controller class, resulting in large and unwieldy classes, a single-use controller only has one single action, which (hopefully) keeps it small and easy to understand.

A stateless class with only one method naturally suggests using the Function Object pattern, which makes it possible to call the object itself as if it was a function. PHP supports this pattern by way of the “magic method” __invoke(), but do the frameworks play along nicely?

Jordan demonstrates how to do it in Laravel, and he mentions in passing that he hasn’t tried to do the same in Symfony. Since I work with Symfony on a daily basis, I decided on a whim to give it a go.

Read more

Share