0

I am learning functional programming, working generally with JavaScript. Many things look promising, like immutable data and stateless flow.

Now, I want to build quite a basic CRUD app as a pet project to practice functional techniques. I am going to use Node for server-side part of the app and vanilla JavaScript for client side.

Being practical and having no will to pass a functional elephant through a needle's eye of web app requirements and realities, I suppose, I don't want to build everything in the app with the functional approach just for the sake of purity and academical perfection.

Should I rather connect functional with imperative, and OOP? If so, are there clear hints for where I should use functional, and where I'd better run OOP? Should I tend to keep domination of one paradigm over others, making one of them a basement of the app, then introducing others on top of it?

Does a CRUD app better fall into 80% of functional and 20% of helper OOP or vice versa? Is it worth and makes sense to wade through the jungle and apply techniques where not applicable, just to say "It's 100% functional app, look at it!"?

What are the signs of preferring one paradigm over another in a context of web?

  • 1
    Disagree with the duplicate, but this probably is either too broad or opinion based. @Sergei My opinion is that the core business logic should be as functional as possible, but interacting with databases, networks and UI are inherently stateful and error-prone things, so you'll have to have a bit of non-functional code at the boundaries between them and your core logic. Assuming you have libraries/frameworks to deal with those ugly things, you could probably achieve "80% functional" by whatever metric you feel like using. – Ixrec Aug 30 '15 at 14:11

1 Answers1

0

Programming paradigms have several goals. Some goals are shared, some not. But mainly it comes down to two absctract ideas:

  • being readable
  • taming complexity

And if you want to, you could summarize the peculiarties of the paradigms into these two categories.

I put the categories on purpose in this order. The primary goal of writing code should be readability, since code is more often read and reread than written. The smartest algorithm is worthless, if you have to find a bug and need hours to think about how it worked.

That said, the answer to your question, whether to choose one paradigm and strictly adhere to it or to mix paradigms, could be answered in that way:

As long as it doesn't impair readability, you are free to mix paradigms

Especially in Javascript, where there is no paradim (like in Java) forced, you are mainly free to mix functional and imperative style and spice your code with some OOP, when it comes in handy.

Does a CRUD app better fall into 80% of functional and 20% of helper OOP or vice versa?

That is just a matter of the implementation, not the app itself.

Thomas Junk
  • 9,405
  • 2
  • 22
  • 45