About Jacob Mather

Posts by Jacob Mather:

Code Evolution: Contact Form (part 1) – A2LAMP

So on Saturday, January 19th, I gave a talk about how to take existing code and refactor it into something a little more respectable. It’s a little wandering and has some faults perhaps, but shows you the ropes of how to iterate something over time.

You can find the source code for where we started and where we ended for this talk on GitHub.

Other links:


Looking ahead: SunshinePHP 2013

I am eagerly looking forward to attending SunshinePHP in February. I wasn’t planning to go for the longest time (cost related), but then, among other things, the community attacked.

I’m looking forward to so many things. I have made many friends over the years, in the Symfony community specifically and the PHP community at large. I want to greet old friends, and new ones. Seriously — come shake my hand and say “HI!” Beware — I will do the same to you!

The Talks

There are SO many good talks. Seriously:

And that’s ignoring Rasmus, Cal, and Keith’s keynotes — those will be excellent.

The People

It adds an entirely different dimension to your community involvement (on twitter, on IRC, in mailing lists, on GitHub) when you have met the people you are interacting with. Heck — at Symfony Live 2012 in San Francisco, I used Fabien Potencier as my Rubber Duck! Having that context, having met them in person, deepens the interactions you have with people online, and helps to make them more than just an internet handle. I’m looking forward to seeing so many of my friends again, while also taking the opportunity to meet some new ones as well.

The Venue

Seriously. Florida. In February. Do I really need to say more?

And Finally

If I find out you came to SunshinePHP and didn’t shake my hand, I will personally convince GitHub to delete all of your code be very grumpy.

2012 Recap

So I wanted to take a little time and document what happened in 2012 for myself.

I think the biggest things I want t take away from 2012 are a few key lessons:

Don’t Be Afraid of What Other’s Think

If you spend your life mired in worries about what others will think of what you are doing, you will never get anything done.

Just do.

Too much of our lives (collectively) are spent wondering about what others will think about what we are doing? So what. Who CARES if you are wrong. People are wrong ALL OF THE TIME. What matters is that you are not so attached to your wrong opinion that you don’t change it when presented a valid argument otherwise.

It’s said the most ‘thought to to be smart’ people aren’t smart because they’re right but because they are quick to change their minds.

I, of course, have the luxury of never particularly caring what others have thought of what I say or do. It’s lead to some pretty awful predicaments — but some pretty awesome ones too. Who, among my close friends, would have pictured me as being one of the ones to immediately volunteer for Symfony Jeopardy at Symfony Live? Especially when I am culturally dumb and (at time time) was quite technically deficient. That didn’t stop me from answering the only then-to unanswered question though!

Just do.

Go up in front of everyone, be a goof ball, have fun, laugh, be silly. Anyone who actually cares in a bad way isn’t anyone you want to associate with anyway.

Just do.

Don’t be afraid of what others will think. Seriously. Most commonly, what most other people will be saying is “Gee, I wish I could do that!” And you know why they can’t? BECAUSE THEY ARE AFRAID! 99% of the people who would say anything negative would never have the nerve to do anything like what you are doing. It’s 100000x easier to criticize than to produce. Be sure to check the background of those who give you negative feedback and take their input with the appropriate level of expertise it warrants.

Just do.

Get out in the community

The PHP Community in general is AMAZING. It’s full of brilliantly smart people you can talk to, and gives you external input to your internal processes. If your local community isn’t as as deep into the things you are? Learn to teach them! Learn about how to talk to other developers, how to share your skills and techniques. You’d be surprised what you’re capable of.

If you haven’t spoken to groups before, consider giving a few talks to a local user group. Most likely they’re running their regular speaker lineup through the wringer, week after week, and offering to talk about something (anything!) that you know even passingly well enough to talk about (I once essentially winged a talk about design patterns — shhhh!).

The other thing being in the community will do is give you a feel for the pulse of where things are heading. There are currents and drafts in the community which you don’t catch unless you’re paying attention. See what’s on the horizon, and pay attention. You’ll never know what you’ll miss if you’re not paying attention.

Prove you can ship

I can’t reiterate this enough. The value of someone who can actually ship a product is waaaaay above someone who can only point to minor contributions in a larger project. If you’re one of those nameless cogs in a giant organization, it’s time to join an open source project or build your own thing on the side. Seriously. Nothing shows your value more than being able to to actually ship something. In the world of business, ideas are cheap, and execution is everything. Show people you can execute, and you will open doors.

Know your stuff

Read up on the important things core to being a high quality software developer: Patterns, Anti-Pattens, and Code Smells, among other things. These will teach you the do’s and don’ts of our industry, our trade. They will show you what to do, and often more importantly, what not to do. It’s the same as new inductees into Martial Arts learn Kata’s, new developers need to learn these patterns, anti-patterns, and code smells. It gives you the tools to reflexively approach similar problems in the future, and tools to expand on when you need to create something out of thin air.

Don’t be afraid to be wrong

Look at my blog, or the advice I give out in #symfony — I’m “wrong” all of the time. There’s usually a much more efficient way to do something than I recommend — but I don’t know it! I help people get stuff done. The academic stuff can be left for those Ivory Tower folk. I’m much more interested in what gets stuff done in the trenches. Getting something done is more often much more important than doing it in the best possible way. Working implementations refactor much quicker than potential implementations grow while wandering in the sea of WTF I HAVE NO IDEA WHAT I AM DOING?!. Being wrong is not a bad thing. It means both that you were strong enough in your opinion that you could voice it, and that when presented with solid contrary evidence, you changed your wrong opinion into a right one. How awesome is that?!

Enjoy what you do

We’re in this because we have a passion for either building better code, or building things people love to use, or hell, even just building things. But if you’re not enjoying your work — seriously the door is right over there. Life is FAR TOO SHORT to spend your days doing things you loathe. If you’re going to do something for your career, make sure it’s something you enjoy. I avoided doing development as an actual full career for many many many many many many many many years, because I was afraid that if I took what I loved and made it a job, it would never be the same. Interestingly, I was right — it was never the same. Now I love going to “work” almost every single day. Seriously, it’s that simple. Do what you love and you never work a day in your life. Honest.

Now with that out of the way

You may be asking yourself “But this is a recap — what do YOU do during this year?” Well, let’s see:

  1. I went to Symfony Live.
  2. I started blogging more regularly.
  3. I was more active in #symfony, #silex, #phpmentoring, #protalk, and #symfony-dev (yikes, right?).
  4. I contributed to the Symfony Documentation.
  5. I started attending User Groups regularly (in Lansing, and Ann Arbor).
  6. I gave a talk in front of 100+ people.
  7. I gave a talk over 30+ minutes.
  8. I have at least one person using one of my open source bundles for Symfony2
  9. I have given three people technical feedback on their technical products which have (I feel) reasonably improved the quality of their product (I think I have a knack for this — have sent an email to php|arch to be a technical reviewer — look for this in 2013’s recap!).
  10. I convinced my 4 best business friends to all be business friends together.
  11. I started mentoring officially (Uzo, Luis, and Yitzchok — you guys are the best folks a mentor could ask for, really!).

What do I want to do, going forward?

I’ll tell you what’s on my list.

  1. I want to launch a product (in the works)
  2. I want to give a mainstream talk at a conference (not an unconf talk)
  3. I want to be more involved in the community (you guys are awesome, seriously!)
  4. I want to help more people hate their jobs less (hey, it’s what I do…)
  5. I want to blog more (is this cliché?)

Anyway — 2012 was great, let’s make 2013 even better!

About the Decorator Pattern

The Decorator Pattern lets you to easily extend a given set of objects (either grouped via class inheritance or interface) and extend their functionality in a way that avoids needlessly duplicating code.

Our example today will hopefully be pretty close to form, and while generally contrived, will simply illustrate the use of the Decorator Pattern.

Let’s say for instance, you run a video rental service. Let’s call it… SmedRocks. Now your crazy programmers have already built your inventory tracking system as a web service, and you have no control over how they have implemented it, but you have to fight the good fight and soldier on. Features must be implemented. To make this even simpler, our API has one function:

getVideos – This returns all of the titles we have, no matter if they are currently rented or not.

Now getVideos returns a JSON array like so:

        'title': 'Some Movie',
        'status': 'rented'
        'title': 'Some Other Movie',
        'status': 'available'

I’m sure you can already see the problem with how it’s returning data. Rented movies and available movies are all mixed in! What a pain!

Ok, so let’s look at what we need to do to get started. Let’s make our API. This isn’t how you would ACTUALLY do this, it’s just an example to get us moving along:

class MovieApi
    public function getVideos()
        return json_decode(file_get_contents('http://example.org/rest/getVideos.json'));

Excellent! We can now get our videos, but wait — we’re in the middle of building this and example.org seems to have gone offline. This isn’t going to help us get this going! So let’s refactor real quick so we can keep going on other things.

interface MovieApiInterface
    public function getVideos();
class LiveMovieApi implements MovieApiInterface
    public function getVideos()
        return json_decode(file_get_contents('http://example.org/rest/getVideos.json'));
class OfflineMovieApi implements MovieApiInterface
    public function getVideos()
        $json = '{{"title": "Movie 1", "status": "rented"},{"title": "Movie 2", "status": "available"}}';
        return json_decode($json);

Look at that! We’ve now defined a central MovieApiInterface which both implementations conform to, and have both an online and offline implementation which will also ultimately make writing tests easier.

Ok, now for the juicy part: we need to be able to ask this system for just rented or available movies. We could extend each API implementation, but that’s going to be some duplication we can live without.

Enter the Decorator Pattern.

With the decorator pattern, we can build an object that accepts a MovieApiInterface object in it’s constructor, and provides a uniform higher-level way to interact with our lower-level API.

Again, this is basic code to get you thinking, not optimized production-ready code.

class SpecificMovieFinder implements MovieApiInterface
    protected $movie_api;
    public function __construct(MovieApiInterface $movie_api)
        $this->movie_api = $movie_api;
    public function getVideos()
        return $this->movie_api->getVideos();
    public function getRentedMovies()
        $movies = $this->getVideos();
        $rented_movies = array();
        foreach ($movies as $movie) {
            if ($movie->status == 'rented') {
                $rented_movies[] = $movie;
        return $rented_movies;
    public function getAvailableMovies()
        $movies = $this->getVideos();
        $available_movies = array();
        foreach ($movies as $movie) {
            if ($movie->status == 'available') {
                $available_movies[] = $movie;
        return $available_movies;

Now we have a simpler API that actually conforms to how we will use it in practice instead of how the API designers built the service. This is great! They get their way, and we get ours. Everyone wins.

So how do we use it?

// development configuration
$offline_api = new SpecificMovieFinder(new OfflineMovieApi());
// live configuration
$online_api = new SpecificMovieFinder(new LiveMovieApi());

Now we get the same functionality on multiple implementations, and as an added bonus, our SpecificMovieFinder also still implements the MovieApiInterface allowing us to use it interchangeably with any other service that may need our api down the line!

My good friend Beau Simensen pointed out that unfortunately, my example is a little deficient. I’ll let his gist do the talking:

Thanks Beau!

What are some other places you can think of using this pattern?