NewsCrawler.org

Making the plan a value: refactoring the amazonka code generator

The author added support for idempotency tokens[1] to amazonka, an unofficial Haskell SDK for AWS, using the client token support that AWS provides. This required substantial changes to the generator, a Haskell program that turns botocore service definitions into cabal packages, whose logic had grown tangled as AWS added new API styles.

To simplify it, the author applied the "make the plan a value" technique: a plan is an intermediate data structure that describes what to do before any action is taken, which separates deciding from doing. The author says this turns the deciding part into a pure function that is easier to test, and it allows a --dry-run flag almost for free. The author links the approach to the plan-execute pattern[2] and the routing slip integration pattern.

The generator was replaced incrementally using the strangler fig pattern[3], with a ResponseParser type that lists ported parsers and a DoItTheOldWay fallback for everything else. The generated service bindings served as a golden test suite, since any change to them shows up in diffs. The author adds that the technique works in any language, and that Haskell's laziness can avoid holding the whole plan in memory.

Read the original jackkelly.nameDiscussion

Sources

Published: First seen: Читать по-русски

Open as a page