DEV Community

Discussion on: Sometimes, the elegant implementation is just a function

Collapse
 
swfisher profile image
Sam Fisher • Edited

Here’s a mixture of facts and opinions :p

Let’s take simplicity of expression and implementation as our goal. Consider that functions are considerably simpler than the proposed alternatives, which add layers upon the primitive idea of a function. It is clearly true that a function is the better choice when it provides equivalent functionality to the more complex structure. The more complex solution adds useless information and therefore obfuscates the purpose of the software.

Another question is whether to use the mathematical definition of a function or consider them to be equivalent to procedures. I prefer the mathematical definition because it is easy to reason about, easy to test, and therefore harder to get wrong.

The idea of elegance can be misleading, suggesting intricacy as a virtue. Elegance really comes from simplicity and compactness, which actually minimize the level of intricacy. The effect of beauty comes from the stucture of the design clearly expressing the problem that it solves.

Collapse
 
mortoray profile image
edA‑qa mort‑ora‑y

Yes, in programming terms we've ended up with the name function and pure function to refer to functions and procedures. I agree that pure functions are an ideal solution, when they apply. I wrote about it in my article on functional programming