indexpost archiveatom feed syndication feed icon

Book Review, Flask Web Development

2015-01-08

Miguel Grinberg's Flask Web Development: Developing Web Applications With Python is, at the time of this review, one of the few books on the Python micro-framework Flask, and certainly the most well regarded.

Some Background

Before Flask Web Development was a book, it was a series of tutorials on the author's blog. I browsed the series at different times without ever diving deep or following the whole series of tutorials. I was familiar with Python and unfamiliar with the web framework landscape and saw Flask Web Development as a good introduction to a more minimal application framework than something like Django, with the rigor that a series of blog posts would not provide. I was sadly disappointed.

What You Get

Ultimately, the entire book adds little to the content of the blog posts, missing a huge opportunity to dive deep and explain thoroughly how the framework works or how to build real world applications using it. Instead the whole book reads more like the tutorial that it began as, leaving me suspicious of that sort of lineage. The style of writing and content of a blog post is entirely different from a long form technical book and I think Flask Web Development failed to overcome such shortcomings.

Chapter Two is the first place that I came across something that would plague me for the entirety of the book and frustrate me enough to put it down several times while reading.

Flask is designed to be extended. It intentionally stays out of areas of important functionality ... giving you the freedom to select packages that fit your application the best

If there is a single identifiable theme in the book it is that; a kind of bizarre NIH antithesis. In order to "extend" the Hello World application in chapter two the author has you install a third party extension and write a few lines to use it. No explanation of what that library is doing, no explanation of how you would do it without the library, just a pip install and then wedge this library in there. I was irritated but it was only chapter two and presumably this was like one of the blog posts, meant to get you up and running quickly and give you a sense of accomplishment. I was wrong.

Really Wrong

The following is from How This Book is Organized

And to ruin the surprise for you, it breaks down like this:

The entire book is seemingly devoted to writing the glue code necessary to wire whatever collection of extensions the author settled on at the time of writing. I was tremendously disappointed to find it lacks any kind of meaningful coverage of the framework and instead opts for extensions with no guarantee of maintenance or reasoning about how to build such systems yourself. I can't help but think the book will be sadly out of date in short order (the framework itself is not yet at 1.0, how much faith can I have that a third party extension with 10 commits is going to stand the test of time?). It isn't as though you can wave away such criticism on the merits of the writing, because the writing doesn't explain anything meaningfully. If you gloss over the details of the extensions you aren't left with much to read.

Flask is a micro-framework, marketed as a lightweight solution to something like Django, which bakes in an ORM and a great deal of functionality. The only thing I seemed to take away from reading the book was how to install enough third-party code to bloat my own project to the size of a Django project without the benefit of the community wisdom. The Django community has spent ten years honing a framework to suit evolving needs, what can I add to a more minimal project by plucking a project off GitHub and hacking in enough glue code to kick the ball of mud further down the way?

Joel Spolsky has written In Defense of Not-Invented-Here Syndrome, advising:

If it's a core business function -- do it yourself, no matter what

I can appreciate the benefits of leveraging a community to expedite development and I have used Flask extensions myself, but I think it should be a thoughtful act to include one more dependency into a project and instead Flask Web Development seems to reach for that particular hammer at every turn.

I'm not going to pick through the book looking for each thing that annoyed me as there were just so many. I was irritated by chapter two and disappointed by chapter eighteen, never once feeling as though I really understood Flask or its strengths. I could make a CRUD app that looked like the author's examples but it would be rote. As soon as the excitement of "my web app is working" wears off, you are left with the realization that it's not your web app, it's the author's and you still don't really know how it works.

Alternatives

The Docs

The Flask documentation is pretty good, though I always feel like there is an assumption that I understand Werkzeug or at least the architecture that Flask is building on. I don't mind that kind of assumption in a project's documentation, but I can't abide it in a book dedicated to the framework as it just begs the question.

Explore Flask

I read Explore Flask and although it's short, I think it complements the quickstart quite well. The whole thing can be read in one sitting and you can't really complain when it's free. I found the explanation of blueprints more useful than the docs when I was trying to understand them initially.