Re:What Pythonistas Think of Ruby
by arockwell on Wednesday February 03, 2010 @10:39AM
(#1097921)
Python doesn't have multiline lambdas, so there is no way to create an api similar to rake's:
I'm not sure what's the closest equivalent syntax you could create in python.
[ Parent
| on HN ]
Python's answer to blocks tends to be the with statement, so your example would look like
with task('name') as t:
# do stuff with t
It's not really the same; the task object doesn't have control over whether the block is actually run, but sometimes it is sufficient.You could almost certainly achieve that with the implementation of blocks provided by this package:
Wow, I've never seen that before. I'm also not sure I'd say a solution that uses bytecode rewriting is really working within the language, but that's a pretty interesting package anyhow.
Well, normally I would agree - but if its entirely abstracted away in a library (and the library is well written) then it might sort-of-kind-of-maybe be ok.
Python itself does varying degrees of bytecode optimisation depending on which version you're using.
that's cool, thanks ... I was wondering about that
Why do you need lambdas to do this? Why wouldn't an inline function work?
This is correct, it would work. People who harp on this probably don't actually use Python for anything.
Not sure what this snippet does, but if it creates a block that is registered as a task named "name", then you can do the same with decorators:
def task(f):
register_task(f.__name__, f)
return f
@task
def name(t)
.....
or similar.Exactly. I fail to understand why people are so dismissive of languages/approaches that do things slightly differently and don't implement equivalent things in the exact same way. What's so special about the rake syntax?