4 ms·
Show HN: Laboratory, a Python port of GitHub's Scientist library for refactoring
- ByteJuggler 11y agoAnother Python one: https://github.com/staticshock/scientist.py https://github.com/staticshock/scientist.py
- agentultra 11y agoCool! Thanks for the tool! > Imagine you've implemented a complex caching strategy for some objects in your database and a stale cache is simply not acceptable. I hope you have a formal specification of that cache. That will help ensure your design is correct in the first place before you even get to running it in code. I shall be playing with this soon. Cheers!
- lasdfas 11y agoI imagine this can only work on getters? How do you use this when code makes state changes?
- tomtompl 11y agoIt only should be used for code which doesn't have side effects. According to original github lib.
- chucksmash 11y agoFrom Github's Scientist [1]: Because `enabled?` and `run_if` determine when a candidate runs, it's impossible to guarantee that it will run every time. For this reason, Scientist is only safe for wrapping methods that aren't changing data. When using Scientist, we've found it most useful to modify both the existing and new systems simultaneously anywhere writes happen, and verify the results at read time with `science`. [1]: https://github.com/github/scientist/blob/master/README.md#designing-an-experiment https://github.com/github/scientist/blob/master/README.md#de...
- jonathankoren 11y agoPython? Isn't Python dying? ;) https://news.ycombinator.com/item?id=11100251 https://news.ycombinator.com/item?id=11100251
- nubs 11y agoHere's some other ports of Scientist I've come across as well: PHP https://github.com/LartTyler/Analyst https://github.com/LartTyler/Analyst Javascript https://github.com/trello/scientist https://github.com/trello/scientist https://github.com/Runnable/scientist https://github.com/Runnable/scientist https://github.com/jirwin/labrat https://github.com/jirwin/labrat
- taspeotis 11y ago.NET http://haacked.com/archive/2016/01/20/scientist/ http://haacked.com/archive/2016/01/20/scientist/
- jack_jennings 11y agoBefore clicking the link I wondered how this would translate the block-based Ruby API into Python. Using Python's with statement is quite nice here, I think. 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.
- chronial 11y agoI would argue that python provides even simpler syntax to enable functionality like this. @experiment.with(new_function) def old_function() ...
- shoyer 11y agoAgreed -- a decorator seems like a much cleaner way to handle this.
- msellout 11y agoA 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.
- buttscicles 11y agoThis 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.