News for hackers. Stuff that matters.
Re:New Werkzeug and Flask Releases by bjourne on Thursday June 13, 2013 @07:30AM (#5873449)
Flask is about the most beautiful Python code you can write. Check out any other Python framework and they may have a decent api, but on the inside it is messy and confusing. Reading Flask source code on the other hand is a joy. There's no crazy stuff and few convoluted pieces + lots of comments so it is really easy to hack something if you must. Any Python coder who wants to improve their game definitely should study Flask because it is such a great piece of software engineering.
Re:New Werkzeug and Flask Releases by obviouslygreen on Thursday June 13, 2013 @03:40PM (#5876101)
Check out any other Python framework and they may have a decent api, but on the inside it is messy and confusing.

This is a really disingenuous generalization. If it's not Flask, it's messy and confusing? Telling every framework developer who's not the author of this one library that their code is crap not only isn't a great way to be taken seriously, it's wrong and just kind of mean.

Re:New Werkzeug and Flask Releases by bjourne on Friday June 14, 2013 @03:40AM (#5878750)
The natural state of any large codebase maintained by multiple persons over multiple years is to be messy and confusing. Therefore it isn't a slight to anyone to state that the Flask devs have been able to keep their source code much cleaner than the average.
Re:New Werkzeug and Flask Releases by reinhardt on Thursday June 13, 2013 @06:15PM (#5876930)
> There's no crazy stuff and few convoluted pieces

I dunno, I've recently started getting into it and "convoluted" is one word that has occurred to me more than once. Handlers vs signals, application and request context, context locals, local proxies, etc.. Probably there's a good reason for all these and the docs make a decent attempt to lay them out but overall my unscientific first impression is that it's not exactly a pinnacle of simplicity.

Re:New Werkzeug and Flask Releases by the_mitsuhiko on Thursday June 13, 2013 @07:13PM (#5877249)
> application and request context, context locals, local proxies

Those are just different names for the same thing. Maybe the docs are a bit too in-your-face with the contexts but I rather expose people to it early to avoid issues down the line.

Django for instance does not have equivalents for application and request contexts and the end result is that people often write thread unsafe code and you can only have one application per Python interpreter. Flask does not have those restrictions. You can have as many Flask applications living side by side. And that is possible because of the contexts.

Re:New Werkzeug and Flask Releases by sirclueless on Thursday June 13, 2013 @07:52PM (#5877451)
There is a difference. Having a request or application context that encapsulates state is one thing, an architectural decision that simplifies multi-tenancy and makes many uses of Flask more performant. These are "simple", in that they are an obvious and easily-explained solution to a technical problem that exists by necessity.

Global proxies to local state are another beast entirely. They are "easy" in that they remove the need to pass application and request objects through every called function, but they are not "simple" -- they rely on intimate details and peculiarities of Python's module and import system, and its capacity for thread-local state, not to mention Python's robust context unwinding features in the case of exceptions. Overuse of context-proxies leads to the same software engineering challenges as overuse of globals, in that it becomes difficult to reason about the calling semantics of functions which rely on context state being present, or mutate context state through proxies. For example, in order to test a view function, you will at a minimum need to set up an application context, but also need to set up any custom context your app relies on. It's not always obvious how to do this, leading to documentation [1] that I notice has already been confusing people on the mailing list.

So I wouldn't conflate the two mechanisms. Application- and request-local context is a pre-requisite for multi-tenant applications and a conceptual simplification. Module-level proxies are a cute trick that makes programmers' lives easier, but undoubtedly creates more convoluted semantics and internal operation.

[1]: http://flask.pocoo.org/docs/testing/#faking-resources-and-co...

Re:New Werkzeug and Flask Releases by the_mitsuhiko on Friday June 14, 2013 @08:15AM (#5879447)
I learned that you need context locals in web applications or beginners will write themselves into a corner where they have an architectural problem on their hand they can't fix later on.

Yes, it's not the best solution, but passing things around isn't either.

Re:New Werkzeug and Flask Releases by coleifer on Thursday June 13, 2013 @10:23AM (#5874155)
Not only is the code great, but so is the documentation, the release notes, and the community.
Re:New Werkzeug and Flask Releases by calpaterson on Thursday June 13, 2013 @08:52AM (#5873733)
For what it's worth, the internals of Bottle are very clean (and extremely simple - the entire library/framework is just one file).
Re:New Werkzeug and Flask Releases by the_mitsuhiko on Thursday June 13, 2013 @09:23AM (#5873878)
I know I'm biased on that, but if the internals of Bottle are clean it's doing something wrong :) WSGI/HTTP are incredible complex and in fact, too complex to fit into a single Python file.

There is a good reason for why Werkzeug (which Flask is based on) is 15000 lines of code.

Re:New Werkzeug and Flask Releases by aptwebapps on Thursday June 13, 2013 @10:04AM (#5874057)
It's in a single file which happens to be a little under 3500 lines long ...
Re:New Werkzeug and Flask Releases by habitue on Thursday June 13, 2013 @11:23AM (#5874522)
Right, he's implying that the implementation is not as complete, or is incorrect because the problem space is more complex than that.
Re:New Werkzeug and Flask Releases by coldtea on Thursday June 13, 2013 @04:55PM (#5876507)
He is implying with not any evidence, aka FUD.
Re:New Werkzeug and Flask Releases by irahul on Thursday June 13, 2013 @05:23PM (#5876681)
He is implying with the evidence that werkzeug which he wrote is much bigger than bottle owing to complexities of wsgi/http, and bottle's smaller size means either the implementation is incomplete or the implementation is too clever or both.
Re:New Werkzeug and Flask Releases by coldtea on Thursday June 13, 2013 @08:11PM (#5877541)
Still no evidence in your comment.

Repeating his "I had to make X big to support all of wsgi/http so anyone who made a similar framework but much smaller has made it incomplete or too succint and clever in a bad way" is not evidence.

You say:

>bottle's smaller size means either the implementation is incomplete or the implementation is too clever or both.

That's a statement of fact (actually a dichotomy of facts). What's the evidence to support these are the only two possible options?

The mere fact that Armin had to make Werkzeug bigger "owing to complexities of wsgi/http" is not proof.

To take it as proof is to assume his coding (and understanding of wsgi/http) as the golden standard by which the Bottle developer should be measured.

Who said this is the case? For one, it took him a year after Bottle to support Python 3, so he might not be that focused, anyway.

My problem is that, the way he and you say it, "incomplete" implies broken or lacking, whereas "too clever" implies fancy tricky code that's too succinct for it's own good.

How about the third option that he needlessly convoluted Werkzeug to work around wsgi/http edge cases that no one really faces, whereas Bottle has been pragmatic about it?

Or the fourth option, that Werkzeug is needlessly verbose, whereas Bottle is not "too clever" but just as clever as needed?

Re:New Werkzeug and Flask Releases by jessaustin on Thursday June 13, 2013 @08:50PM (#5877687)
It would have taken less effort just to try out both frameworks, and then you wouldn't need anyone else's "evidence".
Re:New Werkzeug and Flask Releases by coldtea on Thursday June 13, 2013 @11:15PM (#5878086)
>It would have taken less effort just to try out both frameworks, and then you wouldn't need anyone else's "evidence"

I've tried both frameworks, and looked at the code for both, and I'm of the opposite opinion.

Yours is not a very suggestion. It presupposes what is asked to provide evidence for. That's called a circular argument.

Re:New Werkzeug and Flask Releases by aptwebapps on Thursday June 13, 2013 @11:33AM (#5874582)
I doubt he or she was aware it was 3500 lines long. While not the same as 15000, it isn't all that far off.
Re:New Werkzeug and Flask Releases by schleppy_oc on Thursday June 13, 2013 @11:49AM (#5874673)
I am pretty certain that he, the_mitsuhiko (aka. Armin Ronacher), being the main developer behind Werkzeug and Flask knows exactly how long bottle.py is.
Re:New Werkzeug and Flask Releases by aptwebapps on Thursday June 13, 2013 @11:15PM (#5878085)
Yeah, I did't know who he was and I took it as a drive-by comment. I somehow missed the "I know I'm biased ..." bit unless he edited the post after I replied.
Re:New Werkzeug and Flask Releases by ishbits on Friday June 14, 2013 @12:27AM (#5878305)
I've also found Tornado to be quite readable. But my norm is corporate closed source code which is pretty unreadable.
Re:New Werkzeug and Flask Releases by dtwwtd on Friday June 14, 2013 @12:56AM (#5878363)
I agree here, I think Tornado is really quite readable. I was pleasantly surprised the first time that I looked at the source.