With all the embeddable buttons, such as Facebook like buttons, and widgets like Disqus comments and whatnot these days, you’d think there was some nice info on how they are actually built. But it turns out no, not really. I found this first hand when we had to build some FB like button style things at work, and had to …
Doctrine 2 and the law of demeter
Doctrine 2 makes it very convenient to access related objects in your code: Just do a $entity->getRelatedSomething()->getThingValue(); However, this kind of pattern makes for easy errors when getRelatedSomething returns null – and as a side effect of this, you can end up with a lot of code which checks if the value exists before accessing it. This in turn can …
You don’t need a service layer: Fat controllers are okay
Here’s a counterpoint to the currently popular view of “fat controllers are bad”, and the current fad of everyone and their cousin implementing service layers: You don’t need one. Fat controllers are okay too.
Link: Refactoring a service class for better separation of concerns
RV David has an interesting post on his blog about refactoring a service class for better separation of concerns compliancy. I also left some ideas in the comments as I’m currently working on something similar.
Using unit tests as requirements when refactoring
What should you do to make sure new code works properly when you’re refactoring old code? I asked myself this question recently, when I needed to refactor a big bunch of procedural PHP code into a neat, testable, OOP-style interface. The conclusion I came into is that you should write unit tests – not to test the old code, but …
Exceptions and abstraction
So you already know how to handle your errors properly. Even if you’re already using exceptions, there are some nuances to the use of exceptions that are important to know and understand in order to write code that is easier to reuse and more decoupled. Let’s talk about exceptions and how they relate to your classes and abstraction.
The “do X or die()” pattern must die
What’s the most common pattern for error handling you see in beginner’s PHP code? – That’s right, do_X() or die(‘do_X failed);. That’s nice and all, as at least you have some sort of error handling, but I think this way of handling errors must go. There is no place for it in modern PHP code – it’s the worst way …
What makes an abstraction good, and why should I care?
You probably know what abstraction means – making a complex process simpler – but do you know what makes an abstraction good, and why it’s important? If you are writing code for a project that lives a bit longer, or has multiple developers working on it, having a good abstraction matters. Lack of a good and consistent abstraction will reduce …
Dealing with different password validation schemes in a single app
If your application is well thought out, you would not want to save any data that isn’t valid. So what do you do, when you need different validation schemes, say for passwords, depending on some special case? For example: Your user passwords need to be at least 8 characters long and contain upper and lower case letters, a number and …
Practical uses for reflection
You may have heard about the reflection feature in PHP. Simply put, it’s a way to get a list of methods in a class, a methods parameters, or other “internal” things like that. But how is this actually useful for any common task in application development?
- Page 1 of 2
- 1
- 2