by mcav · 16y ago · 0 comments
Sinatra:
get '/hi' do
"Hello World!"
end
Python 2: @get('/hi')
def hello():
return "Hello World"
Python 3: def hello() -> "/hi":
return "Hello World"I have no idea what that Python 3 snippet is doing... care to share? That looks like something that's hard to Google...
The Python 3 version is using a function annotation.
In Python 2 or 3 you could use a context manager (with statement) to similar effect.
Oh, come on. You're just disagreeing for effect here.
I've never used Ruby but that snippet is clear as day.
The Python 3 snippet suggests to me that the output would be "/hi" though :)
Oh, come on. You're just disagreeing for effect here.
I've never used Ruby but that snippet is clear as day.
The hell it is. I find it quite confusing. I'll take the Python 2 solution anyday, which clearly seperates what is called from when it is called. One of the main problems with the 'my language is so flexible' approach is that inventing concise solutions becomes a goal in itself.It's unclear what "get" is. Is it a function? What does it return? My guess would be that it returns a function bound to the handler of a "/hi" url, but that's a guess.
Fair enough. Arguing over beauty is silly anyway, I just wanted to point out that the entire thing is entirely subjective.
> The Python 3 version is using a function annotation.
Thanks, checking out PEP 3107 now. I've always seen annotations done with the @annotation syntax like the Python 2 snippet has.
The @ syntax is for decorators. Different beast altogether.
Why does that matter? The syntax should be clear to a capable Python developer, not someone who has never used Python.
I'm not suggesting that that particular syntax is or is not clear to said Python programmer, merely that the consideration for a Ruby programmer is useless.
get '/hi', ->
"Hello World"
You can have your cake and eat it too.