Effective Refactoring - HedgeDoc
  1883 views
<center> # Effective Refactoring *Originally published 2019-01-25 on [docs.sweeting.me](https://docs.sweeting.me/s/blog).* </center> The title is misleading, because this is actually about how to design your code *beforehand* so that you can do effective refactoring *later*. Use subtle queues to create natural API boundaries in your code. This is a good thing, not an antipattern: ```python EXAMPLE_TASKS [ do_thing_to_text, do_some_other_thing, do_another_thing, ] for func in EXAMPLE_TASKS: func(**some_context) ``` Or even better: ```python def do_all_things(data, do_thing, do_some_other_thing, do_another_thing): if do_thing: data = do_thing_to_text(data) if do_some_other_thing: data = do_some_other_thing(data) if do_another_thing: data = do_another_thing(data) return data ``` This is a great pattern. To the novice programmer, this might look repetitive, like it's in need of some DRYing, but actually this is an extremely friendly pattern for refactoring later, as it requires very little thought for a programmer to come in and understand exactly what's happening, and where the boundaries are between concerns. This pattern allows your application to be "strangled" by a lator refactor with greater ease: https://www.martinfowler.com/bliki/EventInterception.html https://www.martinfowler.com/bliki/StranglerApplication.html http://matthewrocklin.com/blog/work/2019/06/23/avoid-indirection https://overreacted.io/goodbye-clean-code/



Recent posts:


Back to top