Coding is as much a matter of personal growth as it is of logic and control-flow. I keep patience, curiosity, & exuberance in the same toolbox as vim and git.
*Opinions posted are my own*
Thanks Tiffany for the post, which has opened up such a lovely discussion.
I'm going to push back a little on your examples. By pulling your data out into the top level of the scope instead of your operations, you're contributing to more complex code by adding to the cognitive load of the reader.
In the first example, the worst it'll get for the reader is parsing a single pure function.
In the second example, the reader will need to parse that function while referencing external state.
Could you have simplified that first example by extracting operations to the top level instead of data?
import{maxBy,length}from'ramda'// longest :: (Ord a) => (a, a) -> aconstlongest=maxBy(length)constlongestString=(strs)=>strs.reduce(longest,'');
In this case, there's 0 mental parsing. Your reader's cognitive load involves reading the Ramda docs to find out that maxBy(length) will return the longest of its two arguments. We even provide a function signature in the comments so they don't have to shlep all the way out to the browser.
Is pulling in Ramda cheating? Heck no! Ramda is a general-use functional library. If we're concerned about dependency creep, we could implement those on our own as well.
The most readable code is the code that you don't have to read. Let's layer general interfaces and abstractions instead of bespoke imperative instructions.
For further actions, you may consider blocking this person and/or reporting abuse
We're a place where coders share, stay up-to-date and grow their careers.
Thanks Tiffany for the post, which has opened up such a lovely discussion.
I'm going to push back a little on your examples. By pulling your data out into the top level of the scope instead of your operations, you're contributing to more complex code by adding to the cognitive load of the reader.
In the first example, the worst it'll get for the reader is parsing a single pure function.
In the second example, the reader will need to parse that function while referencing external state.
Could you have simplified that first example by extracting operations to the top level instead of data?
REPL.it
In this case, there's 0 mental parsing. Your reader's cognitive load involves reading the Ramda docs to find out that
maxBy(length)
will return the longest of its two arguments. We even provide a function signature in the comments so they don't have to shlep all the way out to the browser.Is pulling in Ramda cheating? Heck no! Ramda is a general-use functional library. If we're concerned about dependency creep, we could implement those on our own as well.
The most readable code is the code that you don't have to read. Let's layer general interfaces and abstractions instead of bespoke imperative instructions.