Library vs Framework (was Dr. Dobb's Python-URL!)

Rocco Moretti roccomoretti at hotpop.com
Mon Aug 15 13:40:20 EDT 2005


Simon Brunning wrote:
> On 8/15/05, Rocco Moretti <roccomoretti at hotpop.com> wrote:
> 
>>Which lead me to the question - what's the difference between a library
>>and a framework?
> 
> 
> If you call its code, it's a library. If it calls yours, it's a framework.

Although that definition probably makes sense from a pure C perspective, 
where practically everything you deal with is a primitive, I'm not sure 
how much use the distinction is with a OO/duck typing language like Python.

Say you have a "library" of objects - you (as a user) subclass one and 
change one of it's functions subtly (say to add logging). Now when the 
library code runs, it'll call into your code. Voila! Framework.

Or say you have a library function which takes a file object as a 
parameter. Instead of feeding it a Python file, you feed it your own 
file-like object. Now it'll call your code whenever you do a 
read/write/seek etc. In fact, since the parameter was probably 
documented just as "takes a file", you're never quite sure which 
functions in your objects will get called, short of reading the source 
of the library - excuse me, it's a framework now.

In fact, since Python works with duck typing, and even basic operations 
like addition and element access can be customized for any parameter, 
there is no guarantee that users' code won't get called when they use 
your "library."

So is the library/framework distinction useful in Python, especially 
w/r/t Andy Smith's remarks?



More information about the Python-list mailing list