re: What's the difference between a library and a framework? VIEW POST


I agree.

One of the first frameworks I encountered was Twisted Matrix (single threaded async network library for Python) and one of the reasons why its learning curve was deemed steep at the time was because the entire app had to be designed around it: non blocking calls, use of deferreds (similar to promises), event driven, callbacks and so on.

So, as K said, you had no choice but to plug and adapt your code to it. The more you tried to use it as a library the less the chances to make it work.

The simplest example from the homepage:

from twisted.internet import protocol, reactor, endpoints

class Echo(protocol.Protocol):
    def dataReceived(self, data):

class EchoFactory(protocol.Factory):
    def buildProtocol(self, addr):
        return Echo()

endpoints.serverFromString(reactor, "tcp:1234").listen(EchoFactory())

the only "non framework", business logic, code is what to do with the data received on the TCP connection, in this case it's echoed back with this line self.transport.write(data).

This to me is a clear example of a framework.

Maybe in other cases the line is less defined.

code of conduct - report abuse