News for hackers. Stuff that matters.
Re:Design Patterns in Python (Free Book) by est on Wednesday December 28, 2011 @08:23PM (#3402173)
We really don't have to attach design pattern concept in a dynamic language.

    PIL.open = lambda filename: PIL.getattr("open_" + filename.split('.')[-1].strip())
so

    PIL.open('whatever.jpg') == PIL.open_jpg('whatever.jpg')
We don't do this in C++/Java because object & methods are compiled into address, and you can't concatenate arbitary memory/VM address directly like getattr()

Factory pattern is basically a huge pile of lookup table of if's and switch's, unless you use some clever voodoo in reflection, it's just a bridge to map semantic vars to memory/VM addresses.

Which in a way, is a user-level re-implementation of a dynamic language engine (poor man's version)

There are no comments on this comment yet.