Comments: Why Twisted?

Learning Twisted is an investment. The standard library protocols are often less complete or correct and almost all of them are built to work synchronously, which means they don't scale all that well and are harder to use in combination. There's also MANY protocols in Twisted that aren't in the standard library, like SSH.

It really depends on your priorities. If you aren't interested in the performance or the learning experience, and the stdlib covers what you need, you might as well stick with it. The standard library is definitely the easier route, at least until you get the hang of Twisted.

(btw: this comment spam filter is dumb, it won't take my email address because it starts with my name!)

Posted by Bob Ippolito at February 5, 2006 06:53 AM

The standard library protocol implementations are also almost all client-side, except for a web "server" which barely even works, let alone scales. Even so, the stdlib does not contain even simple clients like an IRC client, let alone more complex things like SSH, OSCAR, MSNP, or Jabber.

You may be on to something though. Looking at the Twisted website, the documentation just assumes that the reader has an application that they know the stdlib is not adequate for. It doesn't contain much in the way of advocacy or description of what makes Twisted special, or what Twisted makes possible. The "Why Twisted" page seems to be arguing for Twisted in favor of a C++ server rather than one written from scratch in Python. Perhaps we need to update it.

Posted by Glyph Lefkowitz at February 5, 2006 07:40 AM

Bob, there are way too many frameworks existing now. I am not against frameworks, it is just that before buying into its programming model, it would be nice to know the benefits that I will be getting. In getting Twisted, you have to wrap your mind around how it works... and that takes time. (pun not intended). By the way, I apologize for the spam filter.

Glyph, setting up a socket server just takes a couple of lines with 'socket'. I guess if you want to do servers for the other protocols, Twisted would be a nice savior. I figure most people coming to Twisted would be coming with a Python perspective already. If you ask a C++ only programmer to approach using Twisted, chances are good that they would say f***ou**. There is something about human behaviour that automatically fears the unknown and immediately denounce it.

Posted by Hoang at February 5, 2006 07:56 AM

"there are way too many frameworks existing now"

By what metric? Who is it bad for that there are so many frameworks? The free availability of so many frameworks is fantastic. Unfortunately it may necessitate a role in society that has not previously existed, the "framework reviewer", since it is so much work to decide which is the right one to use. There have long been publications dedicated to figuring out what car to buy, or what computer to use, why not what framework to program for? (IOW: Guido is absolutely right that we need some kind of shootout for web frameworks. It's not the frameworks that are the problem, it's the confusion.)

"setting up a socket server just takes a couple of lines with 'socket'"

To set up a socket server that is unportable and buggy, sure. But even that assumes a familiarity with the POSIX "framework", which is certainly great, but pretty low-level. Even basic requirements then become a burden. Your socket server doesn't handle SSL. How do you integrate it? Etc, etc.

"If you ask a C++ only programmer to approach using Twisted, chances are good that they would say f***ou**"

I have had pretty good success convincing C++ programmers to use Twisted. I've found that the best way is to avoid mentioning that it's in Python until the last possible moment - describe everything it does in painfully technical detail (the trick of listing errno values, as I did recently on a comment on my blog, is a good trick to use). When you finish the description of how the buffering algorithm avoids unnecessary copies, they'll be sagely nodding, and then the one-two punch, "and of course it is in Python, which makes it very robust".

"There is something about human behaviour that automatically fears the unknown and immediately denounce it."

Like you are afraid of Twisted? ;-)

Posted by Glyph Lefkowitz at February 5, 2006 11:45 AM

You are correct to belive that Twisted is a massive learning investment. I have been using it for more than a year now (on some quite serious large scale projects) and still only feel like I am begining to get to grips with it.

Is it worth it? Yes, yes and yes again. It is very powerful - there is support for a lot of protocols and it is trivial to implement your own. It gives you the tools to scale your application and much more besides. I am constantly discovering new parts of twisted that do 'just what I needed'. Don't lump it in with all the other 'frameworks' either - there is nothing else quite like it.

It is not however for the faint hearted. The documentation only touches lightly on the (massive) available functionaltiy. The source code is going to become very familiar to you. And buy Abe Fettigs book. Now. You will need it.

Posted by markw at February 6, 2006 04:53 AM

Touche Glyph.... my comment are that C++ programmers have an aversion to Python, not Twisted necessarily. Getting large corporations to buy into Python is a tough hill to climb in the first place.

Thank you for making me aware that the basic python libraries regarding networking protocol are wobbly. That would certainly make it reason enough for Twisted's existence. I do have a Python background so jumping into Twisted isn't a problem. As you may have noticed, it is in answering the question of "Why Twisted?" from a new-comer point of view that is the basis of this discussion. Like Markw mentioned, before investing lots of time into learning Twisted, it would be nice to know what it would buy me. I'm pretty sold on it just from this little educational discussion that we are having.... but you can see that any serious new comer would also pose the same question in the future.

Posted by Hoang at February 6, 2006 09:02 AM

Ditto. For example, should I learn Django, Turbo Gears, or Twisted? I need to build a dynamic, dabase driven, low traffic website. Would you recommend Twisted over the others I mentioned, why?

Posted by Roger at February 6, 2006 03:22 PM

First, I'm using the three right now in several projects (big and small).

If you want to do just a website, I'll go with django. I choose it over turbogears cause IMHO turbogears is just not there yet (catwalk will make things better).

The way I see it Twisted is more oriented to networked applications, not websites (even though nevow is nice).

My 2c

Posted by hernan at February 8, 2006 01:06 PM

I just poached these links from comp.language.python. Hopefully they are additional help for those trying to get Twisted.

pyzine - getting twisted
twisted intro
onlamp article
twisted patterns
applications

Posted by Hoang at February 10, 2006 10:14 AM
MT::App::Comments=HASH(0x622680) Subroutine MT::Blog::SUPER::site_url redefined at /kunden/homepages/26/d89284986/htdocs/jotsite/cgi-bin/mt/lib/MT/Object.pm line 125.
MT::App::Comments=HASH(0x622680) Subroutine MT::Blog::SUPER::archive_url redefined at /kunden/homepages/26/d89284986/htdocs/jotsite/cgi-bin/mt/lib/MT/Object.pm line 125.
MT::App::Comments=HASH(0x622680) Subroutine MT::Blog::SUPER::archive_url redefined at /kunden/homepages/26/d89284986/htdocs/jotsite/cgi-bin/mt/lib/MT/Object.pm line 125.
MT::App::Comments=HASH(0x622680) Subroutine MT::Blog::SUPER::archive_url redefined at /kunden/homepages/26/d89284986/htdocs/jotsite/cgi-bin/mt/lib/MT/Object.pm line 125.
MT::App::Comments=HASH(0x622680) Subroutine MT::Blog::SUPER::archive_url redefined at /kunden/homepages/26/d89284986/htdocs/jotsite/cgi-bin/mt/lib/MT/Object.pm line 125.
MT::App::Comments=HASH(0x622680) Subroutine MT::Blog::SUPER::archive_url redefined at /kunden/homepages/26/d89284986/htdocs/jotsite/cgi-bin/mt/lib/MT/Object.pm line 125.
MT::App::Comments=HASH(0x622680) Subroutine MT::Blog::SUPER::archive_url redefined at /kunden/homepages/26/d89284986/htdocs/jotsite/cgi-bin/mt/lib/MT/Object.pm line 125.
MT::App::Comments=HASH(0x622680) Subroutine MT::Blog::SUPER::archive_url redefined at /kunden/homepages/26/d89284986/htdocs/jotsite/cgi-bin/mt/lib/MT/Object.pm line 125.
MT::App::Comments=HASH(0x622680) Subroutine MT::Blog::SUPER::archive_url redefined at /kunden/homepages/26/d89284986/htdocs/jotsite/cgi-bin/mt/lib/MT/Object.pm line 125.