Crafting Functions
stopa.io
stopa.io
I hope the point of the essay came through, that there is an abstraction spectrum, and where certain ideas fall onto that spectrum.
Thanks for reading!
But yes more important then just composition is to use combinators and segregate your combinators from IO.
Abstraction and composition are great to surface the main characteristics of your algorithm. A compiler then can take those characteristics and verify if they make sense. Different compilers can do that in different amounts, and the Javascript one does the absolute minimum possible. On this case, you get no safety, just more complex code.
Go ask a Haskell developer and the first reaction you will get is probably "wait, you were running getData inside the original function?!"
Haskell developer here, this was indeed my first reaction :P
I agree with the statement that composition won't make the code unreliable.
When I wrote mistake, the kind of mistake I was referring too was a mistake in abstraction boundaries, rather than execution. (for an extreme case consider a DSL: if you abstract a DSL from only one example, you'd likely get the core abstractions wrong)
fileURL = saveFile("export.csv", jsonStr);
(you should be writing csvStr to the file, not jsonStr)One issue that comes up is the function arguments can evolve to be a mess over time with this method.
I like to always use a prop object as function arguments, even when it is simple.
function calculateArea({x, y}) rather than (x, y).
This makes it so things can be added, and be optional, and the calling function clearly can see what those values are being assigned to.
This means that the 100 times you called that function don't need to be rewritten with a new parameter added, and you don't have to have a bunch of null values set for unused cases.
For example, Go is leaning towards such approaches, and I think should be default for the beginning.
Refactor later, when you will see more cases.
It would be good to have the inversion example for a type-based dispatch language/style, rather than the functional style.
C(...).replace(...).replace(...).replace(...).replace(...).trimStart is not a function