Re:Show HN: Laboratory, a Python port of GitHub's Scientist ...
by chronial on Monday February 15, 2016 @06:11PM
(#11106773)
I would argue that python provides even simpler syntax to enable functionality like this.
@experiment.with(new_function)
def old_function()
...
Re:Show HN: Laboratory, a Python port of GitHub's Scientist ...
by shoyer on Monday February 15, 2016 @10:26PM
(#11107714)
Agreed -- a decorator seems like a much cleaner way to handle this.
Re:Show HN: Laboratory, a Python port of GitHub's Scientist ...
by msellout on Tuesday February 16, 2016 @12:22AM
(#11108047)
A decorator must be applied to a function or class, whereas a context manager can wrap an arbitrary section of code. So, it depends on how you want the tool to be used. I don't think there's a clear best design.
Re:Show HN: Laboratory, a Python port of GitHub's Scientist ...
by buttscicles on Tuesday February 16, 2016 @04:49AM
(#11108834)
This was my thought as well, and it's also a bit more awkward if your function signatures differ. Luckily they aren't mutually exclusive and it should be easy to implement a decorator version.
The with statement is one of my favorite additions to the language. It's a really flexible syntax to encapsulate control flow, exceptions, necessary cleanup steps… etc. etc.