PHPNews

Assertions and assertion libraries

When you're looking at a function (an actual function or a method), you can usually identify several blocks of code in there. There are pre-conditions , there's the function body , and there may be post-conditions . The pre-conditions are there to verify that the function can safely proceed to do its real job . …

Continue reading »

Written by Matthias Noback - - Aggregated on Tuesday September 18, 2018


Final classes by default, why?

I recently wrote about when to add an interface to a class . After explaining good reasons for adding an interface, I claim that if none of those reasons apply in your situation, you should just use a class and declare it "final". PHP 5 introduces the final keyword, which prevents child classes from overridin…

Continue reading »

Written by Matthias Noback - - Aggregated on Tuesday September 11, 2018


Reusing domain code

Last week I wrote about when to add an interface to a class . The article finishes with the claim that classes from the application's domain don't usually need an interface. The reason is that domain code isn't going to be swapped out with something else. This code is the result of careful modelling work that's done …

Continue reading »

Written by Matthias Noback - - Aggregated on Tuesday September 4, 2018


When to add an interface to a class

I'm currently revising my book "Principles of Package Design" . It covers lots of design principles, like the SOLID principles and the lesser known Package (or Component) Design Principles. When discussing these principles in the book, I regularly encourage the reader to add more interfaces to their classes, to make …

Continue reading »

Written by Matthias Noback - - Aggregated on Tuesday August 28, 2018


More code comments

Recently I read a comment on Twitter by Nikola Poša: I guess the discussion on my thread is going in the wrong direction because I left out a crucial hashtag: #NoCommentsInCode - avoid comments in code, write descriptive classes, methods, variables. https://t.co/MuHoOFXCvV — Nikola Poša (@nikolaposa) July 13, …

Continue reading »

Written by Matthias Noback - - Aggregated on Monday August 13, 2018


Objects should be constructed in one go

Consider the following rule: When you create an object, it should be complete, consistent and valid in one go. It is derived from the more general principle that it should not be possible for an object to exist in an inconsistent state. I think this is a very important rule, one that will gradually lead …

Continue reading »

Written by Matthias Noback - - Aggregated on Tuesday July 17, 2018


About fixtures

System and integration tests need database fixtures. These fixtures should be representative and diverse enough to "fake" normal usage of the application, so that the tests using them will catch any issues that might occur once you deploy the application to the production environment. There are many different options …

Continue reading »

Written by Matthias Noback - - Aggregated on Tuesday July 10, 2018


Blogging every week

A very important "trick" in finding the flow in life is: do what you like most . Of course, you have to do things you don't like (and then you need different life hacks), but when you can do something you like, you'll find that you'll be more successful at it. When it comes to blogging, I find that it helps to …

Continue reading »

Written by Matthias Noback - - Aggregated on Tuesday July 3, 2018


Testing actual behavior

The downsides of starting with the domain model All the architectural focus on having a clean and infrastructure-free domain model is great. It's awesome to be able to develop your domain model in complete isolation; just a bunch of unit tests helping you design the most beautiful objects. And all the "impure" …

Continue reading »

Written by Matthias Noback - - Aggregated on Tuesday June 26, 2018


Doctrine ORM and DDD aggregates

I'd like to start this article with a quote from Ross Tuck's article "Persisting Value Objects in Doctrine" . He describes different ways of persisting value objects when using Doctrine ORM. At the end of the page he gives us the following option - the "nuclear" one: [...] Doctrine is great for the vast …

Continue reading »

Written by Matthias Noback - - Aggregated on Tuesday June 19, 2018


Road to dependency injection

Statically fetching dependencies I've worked with several code bases that were littered with calls to Zend_Registry::get() , sfContext::getInstance() , etc. to fetch a dependency when needed . I'm a little afraid to mention façades here, but they also belong in this list. The point of this article is not to bash …

Continue reading »

Written by Matthias Noback - - Aggregated on Tuesday June 12, 2018


Deliberate coding

I wanted to share an important lesson I learned from my colleague Ramon de la Fuente . I was explaining to him how I made a big effort to preserve some existing behavior, when he said something along the lines of: the people who wrote this code, may or may not have known what they were doing. So don't worry too …

Continue reading »

Written by Matthias Noback - - Aggregated on Tuesday June 5, 2018


Remote working

Recently I read Ouarzy's review of Jason Fried and David Heinemeier Hansson's "Remote - Office Not Required". I'd read their previous books, "Getting Real" and "Rework". They're all a joy to read. Short chapters, nice little cartoons. Just a lot of fun, and inspiring too. Not many authors make as much of an effort …

Continue reading »

Written by Matthias Noback - - Aggregated on Tuesday May 1, 2018


Context passing

I'm working on another "multi-tenant" PHP web application project and I noticed an interesting series of events. It felt like a natural progression and by means of a bit of dangerous induction , I'm posing the hypothesis that this is how things are just bound to happen in such projects. In the beginning we start …

Continue reading »

Written by Matthias Noback - - Aggregated on Tuesday April 24, 2018