Design Patterns in Dynamic Programming

Share this article

Via reddit (great site if you suffer attention defecit): Design Patterns in Dynamic Programming by Peter Norvig (Director Research at Google).

In slide form it’s somewhat tricky to extract anything more than the gist of what’s being said but there’s some really interesting stuff here. It’s perhaps easiest to understand in context of this old but (unusually) insightful post on /.;

The dirty unacknowledged secret of design patterns is that they’re strongly coupled to a language. For example, switching from a statically typed language like Java to a dynamic one with forwarding substantially changes the approach to Factory, Proxy, Singleton, Observer and others. In fact, they’re often rendered trivial.

This is the first serious attempt I’ve seen to identify patterns specific to dynamic languages and found myself nodding. For example Partial Evaluation [slide 1] and slide 2;

Intent: Write literate code, compile to efficient code

A prime example of that in PHP would be WACT’s template components which turn declarative template tags into “runtime” PHP spaghetti (that you don’t need to care about). Believe this is also a big selling point in Rails, which has made good use of Ruby’s macro capabilies for stuff like defining object relationships in active records – by way of comparison there, perhaps the closest PHP can get to that is illustrated by EZPDO, which has you place those statements in PHP comments alongside your code, which EZPDO extracts.

That said, not all of this talk fits well to PHP, which doesn’t claim “everything is an object”; functions, for example are not objects and support for programmatically modifying a class at runtime is, essentially, non-existent. There’s a kind of bitter pill here methinks – at the time when PHP5’s object model was being designed, Java had OOP cornered and PHP5 makes it’s pitch in that direction. With languages like Ruby, Python and Javascript (Lisp in C’s Clothing) hitting the mainstream, you might ask “Is PHP dynamic enough?”

Harry FuecksHarry Fuecks
View Author

Harry Fuecks is the Engineering Project Lead at Tamedia and formerly the Head of Engineering at Squirro. He is a data-driven facilitator, leader, coach and specializes in line management, hiring software engineers, analytics, mobile, and marketing. Harry also enjoys writing and you can read his articles on SitePoint and Medium.

Read Next
Get the freshest news and resources for developers, designers and digital creators in your inbox each week