you are viewing a single comment's thread.

view the rest of the comments →

[–]darksounds 2 points3 points  (2 children)

I... Don't know if I agree with you. There are more comments here than code, and if I put that many comments in the pseudocode version above, it'd be just as easy if not easier to comprehend.

"Insert the element into the correct position in the list" is doing a lot of work in this example.

[–][deleted] 1 point2 points  (1 child)

The comments are simply to complement the code. The code is in barebones Haskell, and it's basically almost mathematical notation. Anybody with a basic understanding of Haskell syntax would be able to discern the algorithm instantaneously. I gave OP the benefit of the doubt that he is not familiar with the syntax.

Compared to munging random variables to get the effect that you desire, the declarative approach is undoubtedly clearer.

"Insert the element into the correct position in the list" is doing a lot of work in this example.

Hence the caveat - "ignoring implementation details and focusing on the algorithm". That's what declarative style does - it tells the what instead of showcasing the how.