Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

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)



Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: