0

Everything is in the title, is the usage of flip function a smell for bad design ?

I'm coming from a JavaScript universe and used to work with lodash/fp or ramda.

Recently, I've written some stuff where two list of completly different types have to work together to create another list.

I've tried to extract some stuff in functions, but the signature look like:

const isNotIn = list => value => _.get(value)(list)

So I've tried to use the flip function (sorry for the syntax, lodash/fp isn't ready for simple flip / curry):

const isNotIn = _.curryN(2, _.flip(_.get));

It makes me feel a bit weird, like I'm missing or smelling something.

Do you have any thoughts concerning the flip function and bad design ?

1 Answer 1

4

While not always a sign of bad design, at some point the point-free style is a pointless style. Eliding arguments and depending on fairly abstract higher-order operations tends to make the code harder to understand. In many cases, spelling out the parameters as in your first example is vastly preferable – although it still curries the function which may or may not be desirable.

Programming is writing code for an audience – not the computer, but other programmers. Consider their backgrounds and skill levels. E.g. if you are working in a team, your code has to be maintainable by other members (present and future). Sometimes its better to raise the skill level of the team, but in most cases it is better write the simplest thing that works, and disregard excessive abstractions.

Citing from a similar answer I wrote a year ago:

So yes, your code was too clever. Please apply your cleverness not to write clever code, but to find clever ways to avoid the need for blatant cleverness. The best designs don't look fancy, but look obvious to anyone who sees them. And good abstractions are there to simplify programming, not to add extra layers that I have to untangle in my mind first

1
  • Nice (self-) quote! I bookmark this one ;) Jul 19, 2018 at 13:54

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.