Re:Ask HN: What are the best programming tricks you know?
by b0afc375b5 on Tuesday July 26, 2022 @11:55AM
(#32239982)
Ahh I see. So if I may use an analogy:
I have an html page with all my details, etc. Then say I want to create a markdown version of it, or a pdf version, or a docx version.
The first approach would be to manually rewrite my details to each format, as markdown, as pdf, as docx, essentially duplicating work each time.
The second approach, which is akin to defunctionalisation, would be to separate my details (data) from the format. So that would mean I would store my data in json format, then use a cli tool/program to generate it in html format, in pdf format, or in docx format.
I hope I got the basic idea right.
Re:Ask HN: What are the best programming tricks you know?
by cutthegrass2 on Tuesday July 26, 2022 @04:58AM
(#32235906)
This is a great example, and feel the concept has "clicked" with me because of it. Thank you!
Usual OOP solution is to have a wrapper on piano:
However, if we instead return a description of what to do, such manipulations compose far more easily: And it's easier to test: Wherever you are building a complex mock for testing consider defunctionalization instead.