Blog Post RSS ?

Blogs » PHP » Design Patterns in Dynamic Programming
 

Design Patterns in Dynamic Programming

by Harry Fuecks

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?”

Share and Enjoy:
  • Digg
  • del.icio.us
  • Facebook
  • Google Bookmarks
  • Ping.fm
  • Twitthis

Related posts:

  1. How to Pick the Perfect Programming Editor Craig provides a list of essential features every web developer...
  2. Developing CodeBurner — An Exercise in Exploratory Programming When building CodeBurner, the new Firefox plugin that displays HTML...
  3. Are PHP Namespaces Really So Bad? Namespaces have caused a divide amongst developers who either love...
  4. Will Server-Side JavaScript ever catch on? Server-side JavaScript appears to be a logical choice for web...
  5. Is Ruby’s Popularity Fading? Ruby has enjoyed a ton of hype over the last...

This post has 17 responses so far

Sponsored Links

SitePoint Marketplace

Buy and sell Websites, templates, domain names, hosting, graphics and more.

Follow SitePoint on...