r/programming • • May 05 '19

10 OOP Design Principles Programmer Should Know

https://hackernoon.com/10-oop-design-principles-every-programmer-should-know-f187436caf65
2 Upvotes

44 comments sorted by

View all comments

Show parent comments

2

u/Zardotab May 06 '19

I've yet to see practical examples of FP improving typical code. It often assumes unrealistic conditions or conditions only true in a niche. It's also hard to debug the innards of FP, or at least learning how to debug the innards takes an excessive amount of time. I'm still open to the idea, but have yet to see strong justification for typical environments.

1

u/ScientificBeastMode May 06 '19

I definitely think it depends on the company, the team composition, the codebase, and the languages under consideration.

I’m curious about the details of your experience considering your issues with debugging. Personally, I’ve found the debugging aspect to be much more pleasant with FP-style systems.

1

u/Zardotab May 06 '19 edited May 07 '19

depends on the company, the team composition, the codebase, and the languages

Indeed. The success often depends on how you use & manage the tool more than the tool itself.

I just can't find examples relevant to domains and projects that I see. I'm not predicting the weather 8 days ahead or starting the Next Great Dotcom, I'm merely tracking the workflow of widget processing for Drab Company Inc. Unglamorous, but necessary. (Don't tell them I said that.)

When I see relevant examples, then I can better comment on debugging. If I use examples that I conjured up by myself, others say "you are doing it wrong", but don't give me viable alternatives. Their reworked examples assume domain patterns that don't exist in practice, leading me to suspect that FP requires too much "regularity" in designs. Some domains have more regularity than others. For example, the laws of physics or an existing standard is not going to change much such that most new features are additions rather than changes of what already exists. In my domain, the "rules" usually come from the whims of managers, owners, lawmakers, and/or marketers.

1

u/ScientificBeastMode May 07 '19 edited May 07 '19

You bring up some good points. If you don't have the authority or freedom to make changes to your work processes or tool-set, then switching to a new programming paradigm is going to be difficult, and probably won't offer as many benefits.

A lot of the problems that FP addresses are essentially top-level concerns (e.g. test coverage, test quality, error frequency, cost of refactoring, etc.), so migrating to a functional language (or design paradigm) is more relevant to a senior engineer or manager. One rogue developer opting to turn all of their code into nested functions is probably not going to see many of the systemic benefits that they might see if FP design was implemented across large sections of the codebase.

So if the question is, "Why should I, some average developer at a random company, switch to FP?", I could come up with a few reasons, but it's a hard sell. If you aren't familiar with it, the learning curve is tough. It's harder than switching between, say, C# and Java, which is basically learning different implementations of the same core concepts. Switching from C# to Haskell involves completely rethinking the way data ought to flow through an application. For me it felt like I was learning calculus for the first time.

But I guarantee you will become a better programmer if you learn FP (or heck, any new, unfamiliar paradigm). Just my hot take...

Edit: I have come across some examples of companies using FP to solve real-world, mundane technical problems. And often the results are rather boring on the surface. Usually it means something like having literally zero runtime errors for several years. Or implementing concurrent computation across an entire application without having to think to much about it. Or how Facebook managed to permanently squash a persistent bug with their messenger app by migrating portions of their code to ReasonML, a semi-functional language. Plenty of examples out there, and many of them are just solutions to ordinary business problems.