Hacker News new | ask | show | jobs
by IceDane 1650 days ago
Flask is arguably objectively an extremely poorly written library and there are lots of alternatives out there that are much better, like FastAPI.

This is also pretty much obvious from the get-go. When handling a HTTP request, the morally correct function is something like a function which takes a request as a parameter and returns a response.

In flask, for no good reason, a lot of things that are only accessible inside a request get put into global objects, and if you try writing code that accesses them outside of the right context, it will simply crash. You might accidentally refactor such code to the wrong place and you will have no idea until it crashes. This kind of design on top of a dynamically typed language is kind of like drinking poison and then shooting yourself.

Flask is full of insane things like this and it boggles the mind that it ever got as popular as it has. I suppose there weren't many alternatives.

1 comments

IIRC, Flask was originally written as a joke. It was also created in the era when using thread locals was still somewhat common but going out of style. I've always been a bit stumped as to how it got so popular. I usually recommend Django + DRF, Pyramid + SQLAlchemy, or FastAPI, depending on the project.