Whenever I see Flask code, it just reminds me how unbelievably succinct Sinatra is.
I imagine it's a limitation of Ruby vs Python for creating DSLs, but a basic Flask app just seems so verbose. It's like seeing "Hello World" in Java vs "Hello World" in a dynamic language like python or ruby.
Note that there is no need for the conditional if you just want to serve this route (and there is no need for the conditional block at all if you're just defining view functions), and that this whole block exists once per project.
And that a Flask app is a proper WSGI application (as opposed to a self-running Sinatra handler which has to be quite significantly modified to be Rack-compatible)
As a result, the actual verbosity difference comes down to:
So, as usual, Python not having multiline anonymous functions: for this very case you could write
app.route('/')(
lambda: "Hello World!")
but that kind-of looks like shit and you're hosed if you want to add more stuff.
(one could argue that the Flask version lets you formally write docstrings which standard Python doc tools will understand)
(and if you're wondering, yes Flask could provide support for not needing to define an app or run it for this trivial example, leaving named functions as the only actual overhead over Sinatra. I don't think there's much value in it, but it wouldn't be very hard)
as opposed to a self-running Sinatra handler which has to be quite significantly modified to be Rack-compatible
Huh? Here's the `config.ru` that you need:
$: << File.dirname(__FILE__)
require 'app' #assuming app.rb
run Sinatra::Application
Note that I have no stake in the verbosity claims, as it's not something I particularly care about. But I wouldn't consider this a significant modification.
I guess saving a couple lines is nice, but flask is already so concise, I have no complaints about keystrokes. Plus, for a real app, I imagine the percent more lines would be smaller, though I don't know sinatra's syntax for other stuff.
The intention wasn't to diss Flask. It is a very concise and useful framework. All the comments apply to my original comparison.
public static void main(..){
System.out.println("Hello World");
}
really isn't much more verbose than
print "Hello World"
yet every tutorial on a new language points out how frustrating it is for someone learning the language to type "public" "static" "void" "System" and other keywords/objects/modules without having any idea what they mean just to do something simple.
In Flask I need to instantiate the Flask app, define a function to run and decorate it with a route. That raises all sorts of questions about what a decorator is (which for a casual pythonist may or may not be something they understand - I know my understanding of decorators is sketchy at best). Then I need to explicitly call app.run() somewhere.
In Sinatra, the DSL makes it much simpler. If I receive a "get '/'" request, then "do" the following stuff. "end".
Flask is very concise. No doubt about it. It's stripped down to it's very minimum. Yet Sinatra manages to be even simpler, which is impressive to me.
>Whenever I see Flask code, it just reminds me how unbelievably succinct Sinatra is.
I hereby dub this the programmer equivalent of "sharp knees".
Explanation from the ever inimitable Urban Dictionary:
"A judgment leveled against an otherwise perfectly proportioned, if not slightly trim, and pleasant looking woman. Generally uttered by a male who is way below her class."
This comment is otherwise beneath a reasoned response.
I imagine it's a limitation of Ruby vs Python for creating DSLs, but a basic Flask app just seems so verbose. It's like seeing "Hello World" in Java vs "Hello World" in a dynamic language like python or ruby.