What Is Larry Thinking? #58 => Design Patterns and More!

July 30, 2012

In this edition…

About This Newsletter

Hello, hello! I hope your summer is going well (for those of you in the northern hemisphere). Mine is flying by quickly, but I really look forward to the last half of the year. Lots of exciting work things happening for me in 2012! (I realize that sounds vague and enticing, which is partially my intent.)

In this newsletter I have a couple of thoughts from you, a couple for your, and some things to share around the Interwebs. As always, questions, comments, and all feedback are much appreciated. And thanks for your interest in what I have to say and do!

What Were You Thinking? => Skills Required for Jobs Today

In the previous newsletter, I wrote about the skills that seem to be required in order to get jobs today. As part of that article, I discussed an email I received from Rachel, who was out hunting for PHP Web development work. Since that newsletter went out, I’m very happy to say that Rachel landed a job, and she shared with me what the employers were looking for. Specifically, Rachel said:

They were expecting me to show that I was a fast learner, I only needed to show that I had a strong background in PHP, MySQL and only working knowledge of HTML, CSS and Javascript. (The role was Junior PHP Developer). They also wanted to know if I had knowledge of website design practices.

Rachel went on to list skills that were desirable, but not required: “knowledge of relational database structures, jQuery, Linux, and Yii or utilising a MVC architecture.”

In the job interview, Rachel was expected to describe some of the Web sites she had created and what she had learned from that process that was relevant to the job she was applying for. She also went through the steps she would take to create a new project from scratch, starting with the design, through to testing.

Congrats again, Rachel! Hope the job is going well so far.

Separately, Paul had emailed me about the subject as well. He shared his experience in getting an IT job, for which he had the interest but not the best qualifications on paper. His solution: he became a “gofor/tea boy” for the computing section of the company. It allowed Paul to meet the right people and see what they did. Within eight years Paul had gone from tea boy to manager. Paul would definitely recommend this approach to people trying to break into IT.

I had a similar (almost) experience when I was working at the main library at Georgetown University in Washington, D.C. My actual position was in administration: overseeing maintenance, the mail operations, supplies, and so forth. But my friends were in the IT department. I asked a lot of questions, helped them solve any issues with the only two Macs in the building (this was 1997), and volunteered to do whatever was needed. Had I not left the library when I moved to Pennsylvania, my understanding was they were going to add another position to the department, which apparently would have been mine.

A lot to be said for taking the indirect route sometimes…

What Are You Thinking? => Stripe

While I was out in San Francisco a couple of weeks ago, I met up with the good people at Stripe. In case you’re not familiar with it, Stripe is a relatively new payment gateway system. Stripe’s rates are competitive and it’s super-simple to use. Like, crazy-simple.

Ironically, someone asked about Stripe in the forums some time back and, at the time, I had not yet used Stripe. Then a client for whom I was doing an e-commerce site chose Stripe, and I learned about Stripe in a hurry. Because of that work for that client, I ended up communicating with Stripe just before my trip, and I arranged to meet up with them while out in the Bay Area. (It turns out that my first PHP book was the first programming book that Patrick, the Stripe CEO, ever bought, which is a great thing to hear.)

Anyway, Stripe is full of very nice people, I had a great meeting with them, and the product is top notch. I’m planning on doing some tutorials and other writing about Stripe in the future, and wanted to know if you already had any questions or comments about it.

(To be completely transparent, I have no commercial relationship with Stripe. They’re just good people with a good product, and I’m always looking to write about and share good things.)

On the Web => True North PHP Conference

The inaugural True North PHP conference has been announced to take place in Toronto, Canada, on November 2 and 3, 2012. I have proposed doing a presentation on the Yii framework, introducing the framework and explaining what’s new in Yii2. To buy tickets to the conference, see the True North PHP Web site. To propose your own talk for True North PHP, head to their UserVoice page.

At the UserVoice site, you can also vote for what presentations you think are worth having. Even if you have no plans on attending, but would like me to give a Yii presentation, you can vote for my submission.

On the Web => Learning JavaScript Design Patterns

Some time ago I came across an excellent resource titled “Learning JavaScript Design Patterns”, written by Addy Osmani. Mr. Osmani was a JavaScript developer for AOL, is a member of the jQuery core team, and is a strong writer. “Learning JavaScript Design Patterns” is a book-length document, available for free online. In it, Mr. Osmani:

  • Introduces the concept of design patterns
  • Covers the fundamental design patterns (e.g., Singleton, Module, Prototype, Factory, Mixin)
  • Shows the implementations of the most common design patterns in both JavaScript and jQuery

I think the ideas and the details are well explained, although the subject matter itself does put it beyond the average JavaScript beginner. But if you’re solid with your JavaScript skills and are looking into design patterns, it’s well worth your time. In fact, I would say that if you’re interested in the subject of design patterns, regardless of the language in use, the introduction that Mr. Osami provides to the subject is a must read.

On the Web => Boagworld

Luke, amongst others, has recently recommended boagworld.com as an extremely helpful resource, particularly the podcast. Luke mentioned that he really identifies what the author, Paul Boag, writes about when it comes to working with larger clients and corporations, in particular. I’m not that familiar with the site or the author myself, but am always happy to pass along a strong recommendation.

On the Blog => What It Means To Be A Writer

Sometime back, I started a new series on my blog, titled “What It Means To Be A Writer”. In the series, I’m trying to coordinate and finalize the many thoughts I’ve shared about the experience of being a technical writer. The first part is “Defining Your Book”. In it, I explain how to come up with a book idea, which is step 1 in being a writer (it’s not until much, much later that people will come to you with book ideas, if you’re lucky). Part 2, “Getting a Book Deal”, explains how to pitch your book to publishers.

Forthcoming parts of the series will discuss:

  • Agents
  • Contracts (and negotiating contracts)
  • The writing process
  • Life after the book is written

I get enough questions about this subject that I thought it warranted its own series. If you have any particular questions or comments on these subjects, please let me know.

On the Blog => “PHP Advanced and OOP” Table of Contents

I just submitted the final chapter of the third edition of my PHP Advanced book, now titled “PHP Advanced and Object-Oriented Programming”. The final table of contents have been posted on the blog, for those interested in how it turned out.

Q&A => How Do You Install Unix Tools on a Mac?

I’m a big fan of the Mac as a computer and an operating system, and have been for years. Way, way, way back in the day, one used a Mac at some personal sacrifice, particularly as a programmer. I’m talking about the OS 9 days, which wasn’t really the greatest operating system in the world. I believe there were ways to get PHP running on OS 9, but I’m not so sure about MySQL. And then along came OS X…

The wonderful, amazing thing about OS X is that it’s a version of Unix (specifically, FreeBSD), making it, in my opinion, the best version of *nix that you can use. For my wife, who is not a computer geek, she just has a nice Mac that’s easy to use and feature-rich. For me, I have that, plus access to the same Unix tools that I’m used to using on servers. (I sometimes use Mac servers for clients, too.) Obviously this all starts with Apache, MySQL, and PHP. But I use vi as my text editor when connected to a server over SSH, and I can use vi on my Mac. I can program in Ruby on a server; I can program in Ruby on my Mac. I can compile software on a server, just as I can on a Mac. Except when I can’t.

As I recently tweeted, it always throws me off when I go to install or compile something on my Mac and find that I can’t (i.e., I get all sorts of strange errors). Although Mac OS X is a version of Unix, it doesn’t necessarily have all the tools you might expect. To fix that, the first thing you should do is install Xcode. Xcode is Apple’s IDE. It’s a pretty good program, even before you consider that it’s free! (It’s available in the App Store.) Once you’ve installed Xcode:

  1. Open it.
  2. Select Preferences from the Xcode menu.
  3. Click Downloads to go to that tab.
  4. Next to “Command Line Tools”, click Install.

This will solve many of your problems. Sometimes, though, a program or utility will be installed but not find-able when needed. For example, for my “PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide” book, I installed a few PEAR classes. That installer sometimes couldn’t find utilities that were needed (and that I knew had been installed). In those situations, you must first find where the actual utility is installed. For example, this command (executed in the Terminal) locates the phpize utility: whereis phpize.

Once you’ve identified the actual location of the utility in question, you can either change your PATH to include it, or create a symbolic link from the utility’s expected location to its actual location. The particulars for doing either will depend upon the utility in question.

Finally, there are situations in which the necessary utility is just not installed, even by Xcode. In those cases, the two easiest solutions are Macports and Homebrew. Both do a good job of easily installing compatible versions of various utilities.

My thanks to Robert for suggesting that I write about this in a newsletter!

Q&A => How Do I Learn Design Patterns?

A long, long time ago (in a land far, far away), Iris had asked me how one best learns design patterns. Having finally written about the subject myself (there’s a chapter dedicated to it in the PHP Advanced book), I’ve thought about the subject enough to put together a coherent answer.

First, in case you’re unfamiliar with the concept, design patterns are accepted best practices for solving particular problems. A lesser known fact is that the first book on the subject was actually about buildings and city planning. You see: design patterns are really about having a common language to describe and solve complex problems, regardless of the arena.

Design patterns in computing revolve around object-oriented programming. And, I would say, design patterns are on the higher end of OOP: not that easy to pick up (hence, Iris’s question).

In order to learn design patterns, you must be extremely comfortable with OOP. If OOP terminology and code aren’t second-nature to you, you won’t be able to grasp design patterns. From there, my best recommendation is to take small bites.

The first thing to understand is that design patterns are not like recipes; they don’t provide specific code that can be cut and pasted. No, design patterns are a combination of:

  • A name
  • A description of the problem
  • A description of the solution
  • The issues involved with the particular solution

There are aspects of the solution that result in specific code (e.g., a design pattern might suggest that a specific method be defined), but no two implementations of the same pattern will be exactly the same. For that matter, two different descriptions of the problem can differ as well.

The seminal work for design patterns in programming is the book “Design Patterns: Elements of Reusable Object-Oriented Software” by Erich Gamma, Richard Helm, Ralph Johnson, and John Vlissides. The authors are collectively known as the “Gang of Four”, or GoF. Unfortunately this book isn’t too accessible, particularly because it uses C++ and Smalltalk for its examples. This is a landmark book, though, and the 23 patterns it identifies in three categories—Structural, Behavioral, and Creational—and commonly used terms in the OO community. Eventually, you should read this book, but not immediately.

No, to start, I would recommend that you learn a single design pattern. Good, approachable ones include Singleton, Factory, and Iterator (all covered in my “PHP Advanced and Object-Oriented Programming” book). I would recommend that you pick one, read as many tutorials about it as you can, and then become completely comfortable in implementing that pattern in PHP or your chosen programming language.

Once you’ve grasped one pattern, try another.

Design patterns, in my mind, have many similarities to both OOP in general and to database normalization. Like OOP, design patterns get praised a lot, perhaps overly so. Like OOP, design patterns aren’t always necessary. Still, in time you should be familiar with both OOP and design patterns so you can make that right decision to use one when it is appropriate.

Second, design patterns are like database normalization in that the descriptions of the process are often hard to follow and two different people will describe the same thing in slightly different ways. But once you “get” design patterns, you just get them, and implementing them becomes much more natural and easy.

Larry Ullman’s Book News => “PHP Advanced and Object-Oriented Programming: Visual QuickPro Guide”

As previously mentioned, I’ve finished the first draft of the “PHP Advanced and Object-Oriented Programming” book. (This is the first submitted draft; there are multiple drafts before that point.) The bulk of the focus in this edition is OOP, including a new advanced OOP chapter, a new chapter on design patterns, and a new chapter that creates an example site (a Content Management System, or CMS) using objects. I’ve also updated all the code, fixed any little issues, cleared out some deadwood, and covered any other new, important developments in PHP since the second edition came out.

As of the time of this newsletter, I’ve also done the rewrites on six chapters (out of fourteen). After that, chapters get turned into PDFs, and those are reviewed.

My understanding is the book will be available in late September. I know this is behind schedule, but that’s pretty much my middle name by now. Sorry for the delay for those waiting anxiously for the book.