📎 Webclip
F# Advent of Code 2023: A random walk in the direction of functional enlightenment
Scott uses a refactor of old Grace CLI code to show how his F# practice has changed. He rewrites grace switch into smaller functions, reduces duplicated logic across output modes, and uses a custom bind for Task<Result<...>> to make the flow easier to follow.
He also uses the refactor to surface older bugs and to argue for shorter, more focused functions. The post treats the work as part of a larger learning process in F#, with examples from CLI handling, server validations, and JSON helpers.
Reading notes#
- The post starts from the author’s frustration with old Grace code and uses that as the subject of the article.
grace switchis refactored first because it is the longest and most complex CLI command, even though that makes it the hardest case.- The old version duplicated most of the logic for different output modes.
- The new version extracts the work into smaller functions and uses a custom
>>=!operator forTask<Result<...>>. - The refactor makes the code easier to understand, but it also reveals bugs that go back to the earlier implementation of
grace watchandgrace switch. - The author describes
getNewGraceStatusAndDirectoryVersionsas too long and hard to maintain. - He says code should not require telling a story to explain why it is shaped the way it is.
- He connects that rule to breaking large functions into smaller pieces.
- He says his F# practice is now better at judging function size and complexity.
- He says he is comfortable using functions as first-class values and using classes only when they make sense.
- He gives examples of validation arrays for server endpoints and small JSON serialize and deserialize helpers.
- He says he has more to learn, including SRTP, type providers, custom computation expressions, category theory, and Haskell.
- He closes by saying he is no longer at the start of the journey, but also not near the end, and that progress over time is worth being proud of.
