Intermediate PHP

At last night’s Burlington, Vermont PHP Users Group meeting I gave an Intermediate PHP talk where I discussed working with arrays, functions, and objects. You can view the presentation on SlideShare or see the code examples on GitHub. A big thanks to Matthew Weier O’Phinney for helping to put together the presentation (unfortunately he was not able to make it to the meeting due to unforeseen circumstances) and to Office Squared for hosting the meeting. The slides are licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.

New Features in PHP 5.3

At tonight’s Burlington, Vermont PHP Users Group meeting I will be presenting on New Features in PHP 5.3. My talk will cover the primary new features including namespaces, late static binding, and closures. I’ll also talk about the newly bundled extensions, improvements to existing extensions, and some of the new syntax that is available.

Update (11/19/2010): I forget to mention that the original slides and code examples are available on GitHub.

ALA 2010 Web Design Survey

The Survey For People Who Make WebsitesAre you a developer or designer who makes websites? A List Apart is conducting their 2010 Web Design Survey. The findings will be published so that anyone can analyze the results (see the findings from the 2009 survey). From the article:

It’s a story as old as time itself. In 2007, our conference division, An Event Apart, hired a research team to provide facts about the web design profession and those who practice it. We wanted to know who exactly our famous slogan, “for people who make websites,” was talking about. What were our kind of people’s salary ranges, titles, working conditions, educational backgrounds, gender, ethnicity, and so on? And what effect, if any, did one statistic have on another? For instance, did gender have an influence on salary? Was there a connection between educational background and job satisfaction? Did web professionals who worked at start-ups have the same titles as those who worked at universities and libraries?

Take the 2010 survey.

Barbershop Punk

Yesterday I had the opportunity to see Barbershop Punk, a documentary by Georgia Sugimura Archer and Kristin Armfield, at the Vermont International Film Festival (there will be two more screenings this week at the festival). The film contemplates the future of the American Internet and surrounding issues. Following the screening was a panel discussion with Georgia Sugimura Archer (Film Director), Casey Rae-Hunter (Future of Music Coalition), Josh Levy (Free Press), and moderator Jon Stout (Free Speech TV). The panelists discussed the past, present, and future of the Internet as an open platform (video available on CCTV Center for Media & Democracy’s website).

The film follows the story of barbershop quartet baritone Robb Topolski. In 2007 Robb proved that Comcast was blocking peer-to-peer uploads. What makes this an engaging film isn’t the Internet technology and policies illustrated in it, but the human story that weaves theses issues together. I won’t spoil the film with the details, but Robb’s parallel personal story is a large part of what makes this film work.

The film faced a challenge in the fluid nature of the topics it covers. In December of 2009 Comcast and NBC Universal announced plans for a merger. In January of 2010 the U.S. Supreme Court ruled in Citizens United v Federal Election Commission that corporations have a First Amendment right to fund independent political broadcasts in candidate elections. In April of 2010 the U.S. Court of Appeals for the District of Columbia ruled that the FCC overstepped its bounds when they tried to regulate how Comcast could mange its network. The directors attempted to address these recent events with an updated cut of the film.

Barbershop Punk is a great primer on network neutrality issues. While the film clearly has a bias in favor of network neutrality, we hear from many different voices and perspectives throughout the film. I highly recommend that you watch it if you get a chance.

Update (11/5/2010): The Vermont International Film Festival has posted a video of the Network Neutrality Panel.

Found Line at Vermont 3.0

If you live or work in the Burlington, Vermont area then be sure to stop by Vermont 3.0 taking place tomorrow (Friday) and Saturday at the Main Street Landing Performing Arts Center. Found Line will be exhibiting. We’ll be at booth G10 in the Great Room on the third floor. Hope to see you there!

Domain-Driven Design Immersion Class

I just wrapped up a four day Domain-Driven Design Immersion class with Eric Evans (author of Domain-Driven Design) and Paul Rayner. The class was put on by Eric’s company, Domain Language. If you’re looking for training or consulting in Domain-Driven Design, I highly recommend that you get in touch with them. I’d like to share some highlights of the class here.

Putting the Model To Work

Domain-Driven Design is a set of three guiding principles:

I should point out that the word “Model” has many different meanings in software development. Within Domain-Driven Design a Model is a “system of abstractions that describes selected aspects of a domain and can be used to solve problems related to that domain.” Those familiar with the Model–View–Controller (MVC) pattern should note that the word “Model” within the MVC pattern has a different meaning than “Model” within Domain-Driven Design. Within Domain-Driven Design a Model is a conceptual tool used to understand a Domain. An example that was used in the class was the game of baseball. A Model of the baseball Domain would include concepts such as strikes, balls, and outs. The classes and objects representing these concepts would not be the Model.

You might be wondering what the difference is between the Domain and the Model. The goal with Domain-Driven Design is not to create a Model of reality. Even if you could come up with some objective view of reality this would not be very useful. Instead, we are trying to understand (and perhaps develop) the Models that Domain Experts already use to understand the Domain. It’s important to note that Models are only useful for a particular purpose. What are you trying to do with this Model? Trying to use a Model designed for a different purpose will lead to a less than optimal outcome.

The Model Exploration Whirlpool might be a useful reference if you’re looking for concrete guidance on how to explore Models, especially in an Agile or Lean setting.

Building Blocks

Group Entities and Value Objects into Aggregates. Entities are objects defined by a thread of continuity and identity. Their only responsibilities should be around identity and life cycle. Within a customer relationship management (CRM) system a person would likely be an Entity. Note that context matters: a person in another context may be a Value Object. A Value Object “is an object that describes some characteristic or attribute but carries no concept of identity.” Using the CRM example again, a phone number might be a Value Object. Again, context matters: if you’re a telephone company then a phone number may very well be an Entity. Treat Value Objects as immutable. Delegate business logic to Value Objects, identity and life cycle are plenty of responsibility for Entities. Grouping these Entities and Value Objects into Aggregates is useful when defining transaction, distribution, and concurrency boundaries.

An interesting topic covered in the class that I don’t believe was in the book was the idea of Domain Events. A Domain Event is something important that happens within the Domain that may lead to a state change in a domain object. Instead of keeping track of the current state of an Entity, you can instead compute this state from the currently known Domain Events. Using a baseball analogy again, a Domain Event might be a strike. Domain Events can trigger other Domain Events: three strikes triggers an out. The current state of the game can be computed from all of the Domain Events.

Supple Design

Since this has been a topic of conversation here on my blog and on Twitter, I plan on writing another blog post on why Value Objects need to be immutable. However, I want to point out here that if you think you need to change the state of a Value Object then instead have a method on that Value Object that returns another instance of the same type with the new state. If your method takes any arguments then have these arguments be of the same type as the Value Object. This concept is called “closure of operations” and is covered in Chapter 10 of the book, Supple Design.

While I won’t go into the details here, there are several other useful patterns in creating supple designs including intention-revealing interfaces, side-effect-free functions, and assertions. Note that “supple” is not the same as “flexible”. A flexible design can be easily modified, but a supple design is a design that fits comfortably with the Domain.

Strategic Design

Strategic Design involves managing the interactions between Bounded Contexts. In my understanding, strategic design is most applicable in large teams or groups of teams. It starts by drawing a Context Map of the actual current Bounded Contexts, not what you want the Bounded Contexts to be. Some patterns to describe these relationships include Partnership, Shared Kernel, Big Ball of Mud, Customer/Supplier, Conformist, Anticorruption Layer, Separate Ways, Open Host Service, and Published Language. The details of these patterns can be found in the book.

Distillation

There are always multiple Models. Some of these Models my represent your Core Domain. Others may represent a Supporting Domain or a Generic Subdomain. Work with business leaders to create a Domain Vision Statement so that you can identify which is which. One good question to ask a Domain Expert at the outset of a project to get at the Core Domain is, “What keeps you awake at night?” Other questions to ask include:

  • “What makes your system worth writing?”
  • “Why not buy it off the shelf?”
  • “Why not outsource it?”

Once you’ve identified your Core Domain this is where you should focus your modeling efforts. Put your best available internal developers and modelers on the Core Domain and make sure that the Core Domain is isolated in a clean, Bounded Context.

Summary

Don’t settle on not having access to a Domain Expert. Domain-Driven Design is a creative collaboration between Domain Experts and software developers. Cultivate strong relationships with Domain Experts, focus on the Ubiquitous Language, listen for clues in conversations, and be open to shifts in assumptions that destroy your understanding of the Model—this is where breakthroughs come from!

If you’re interested in learning more:

Immutable Value Objects in PHP

Yesterday I tweeted:

Modern object-oriented programming languages need support for immutable Value Objects. #DDD

The “DDD” in that tweet stands for Domain-Driven Design. There were several interesting responses to this tweet. Kevin Schroeder thought that it made a lot of sense but pointed out that “need” was a bit of a strong word. I should have instead said that this would be a “useful” feature. Matthew Weier O’Phinney shared an example of making an immutable object in PHP. Ralph Schindler suggested throwing an exception so as not to silently reject an attempt to modify the object’s state. Nicolas Bérard-Nault had a similar suggestion of implementing PHP’s __set magic method and throwing an exception so that new public attributes cannot be assigned and also not making any methods that change the state of the object. Giorgio Sironi suggested that PHP’s “private” keyword was all you needed to support immutable Value Objects.

The above suggestions are all useful when implementing immutable Value Objects in PHP. I would also add that you need to make the class “final” to truly guarantee that it’s immutable. This is so that someone can’t extend the class and add (or override) methods that change state (although I suppose if you made the __set method final and had it throw an exception that should do the trick since you wouldn’t be able to change any properties).

Regardless, all of these attempts to guarantee immutability miss the point. I don’t need to make sure the class is immutable when its defined, I need to know in my client code that it’s immutable. In other words, I need a contract that says the object is immutable. None of the above workarounds give you an explicit contract that the object is immutable. Hopefully you’re working on a team where you trust that if a teammate tells you that something is an immutable Value Object, it is immutable. In fact, I wouldn’t normally bother doing any of the above tricks to absolutely guarantee that the object is immutable. This is because you still can’t tell by looking at the object that it is immutable without inspecting its implementation. A built-in language feature would be useful because it would provide an explicit contract that the object is immutable.

Vermont Code Camp Wrapup

Chris Bowen, Julie Lerman, Rob Rohr, and Rob HaleA big thanks to everyone who attended, volunteered, sponsored, organized, and spoke at this year’s Vermont Code Camp—we had 23 speakers, 25 sessions, and 125 attendees! Check out some of the presentations, photos, and tweets from this past weekend. A special shout-out to Julie Lerman and Rob Hale for all of their hard work in organizing Vermont Code Camp! We had some amazingly generous sponsors including The University of Vermont’s School of Business Administration, MyWebGrocer, Found Line (my company), DiscountASP.NET, Green Mountain Coffee Roasters, JetBrains, Microsoft, the Vermont Software Developers’ Alliance, Dealer.com, and the Vermont 3.0 Tech Jam (October 15 & 16). Follow @VTCodeCamp on twitter for information about next year’s event.

Introduction to PHP

Matthew Weier O’Phinney and I are giving an Introduction to PHP presentation this morning at Vermont Code Camp. I’ve posted the slides to SlideShare and the example PHP scripts are available on GitHub. If you are at Vermont Code Camp and attended our session, please take a minute to give us feedback on Joind.in.