r/functionalprogramming • u/Character-Lychee-227 • Apr 06 '24
Question Why do people react consistently negatively to functional programming?
My sample of other developers from across multiple companies gives a homogeneous picture: People are virtually allergic to FP concepts. If you simply use `map` in e.g. Python, people get irritated. If you use `partial` they almost start calling you names. If you use `lift` to make mappings composable... that PR is never gonna make it.
This allergic reaction pattern is incredibly consistent. I wonder why. I can't figure out why. What is so incredibly more comfortable about writing loops etc. and re-inventing the wheel every time with spelled out, low level code, rather than cleanly composing code on higher level with some functional helper functions. What is so infuriating about the most innocent dialectical FP influences, like the ones mentioned. It is not like I am using Monads are other "scary, nerdy" concepts.
For context: I am always very particular about nicely readable, expressive, "prose-like, speaking" code. So by using dialectical FP elements, code in question generally becomes more readable, IF you take the few minutes to look into the definition of the occasional new high-level helper function that you come across in my code, which are in total maybe 10 of these helper functions (map, filter, take, reduce, drop, first, second, ... the usual).
Have you had that experience as well? I have been thinking of switching to a functional development studio with the next job change, just because I don't feel like putting up with this close mindedness of programming dialect anymore.
28
u/imihnevich Apr 07 '24 edited Apr 07 '24
Because while computer science is a hard skill, software development is much more of a soft skill, since you communicate your ideas. And when you communicate it is important to use a language that is common and familiar to your audience
9
u/tb5841 Apr 07 '24
List comprehensions - which are a functional programming tool - are used everywhere in Python. The main reason map/filter are unpopular is because list comprehensions do the same thing.
16
u/Longjumping_Quail_40 Apr 07 '24
To tackle the specific,
mapis just not how one should use as the default to write python. Always write the idiomatic code, not the kind of exceptionally good (in whatever sense you want to talk about) code. That’s why in Haskell you should not loop. I argue that, these twoshouldare exactly identical, i.e., there isn’t a difference, at all, no better or worse.And
partialis objectively worse than explicitly define a named function that does exactly the same thing for specific instances you want to use with explicit type annotation. Python is not much capable of (the last time i tried) typing the variadic parameters. You NEED to help it.7
u/func_master Apr 07 '24
They want ‘easy’, they don’t want ‘simple’.
5
u/ElGuarmo Apr 07 '24
Really depends on the company and language you’re using. I’m a front end dev, and could probably count the for loops I’ve seen in the last couple years on one hand. Everyone reaches for map, filter and reduce first and foremost
4
u/chehsunliu Apr 07 '24
I like FP, but I never use
mapin Python...7
u/Shadowys Apr 07 '24
Functional programming code in python is quite unreadable, even if it be more modular and composable. One cannot simply blindly follow the use of FP everywhere without adapting it towards the context
3
u/real_taylodl Apr 07 '24
Consider how many people, including developers!, are proud to proclaim they're not "very good" at math? You think you're going to get those people on board with functional programming? I'm amazed SQL took off like it did. Think about it.
2
u/[deleted] Apr 07 '24
Honestly OP, I don’t understand it very well. I think the whole “take one and apply a function” on it logic that then recursively scales to the rest of the data in the function feels too foreign to me.
I understand for value in listOfValues
but listOfValues.map().thenDomagicalstuff.thenGetbackanotherList and then compiler throws an error like
Oh you meant to return “Object?” I thought you wanted a BiFunction<Data,Function<Megalodon, TriceratopsQuadraFunction>> . Like no bro just take my email ID and name and give me a list of IDs to work with.
3
u/joelangeway Apr 07 '24
My humble opinion:
Somehow complaining that code is “unreadable” has replaced the idea that with effort and practice one can learn to read any style of code. When I started my career I had 3 mentors who all coded in a different styles and it worked out fine. Everybody would leave code in the style they found it when they had to change it. Everyone appreciated others’ tastes and learned from them. My own style evolved over time.
When I’ve been in charge of such decisions I’ve been emphatic that everybody learn to appreciate each others’ styles and when someone’s style needs to improve they’ve always been pleased to learn a better way.
The fact is having exactly one way to write anything means you get zero creative space to write it better. It is madness to think that static lint rules can do better than a thoughtful human, but that is the norm in web development at least. Python at least gets structure out of its whitespace rules. I honestly like that, but still, the clearest parts of Python code to me are list comprehensions that escape the tyranny of significant whitespace.
Now I always have to just conform to the team’s arbitrary selection of linter rules. Nobody is interested in building anything truly new. We all pretend like we solved the hard problems of making software when “Agile” came along. I don’t make a stink about it at work ‘cause I need to get that bread like everyone else.
I think we all come up with a vision how best to make software and we’re all probably mostly right. Maybe I’m wrong for thinking we ought to let people write code however they like. I look forward to being in a position to test that hypothesis someday, but for now I can’t pretend to certain.
4
u/ganjaptics Apr 07 '24
Most programmers are terrible and work on terrible projects that were developed by terrible programmers that have since left to spread more terrible code throughout the world.
34
u/kinow mod Apr 07 '24
I think in your example about Python it could be that while your version of the code looks more readable to you, it could be harder for someone that learned Python from the python.org docs, in university, or in another Python job.
You can replace many for-loops by a map in Python, but I tend to 1) try to use list/dict comprehension if possible (faster than most for-loops or maps in many cases), 2) simplify the for-loop as much as possible and, 3) use map if it's really just a for-loop + function call, as it really simplifies it.
The only case where I push for a map in Python is when I want the loop to happen in C instead of Python if it makes a big difference in performance (using godbolt one should be able to confirm that the for has more work in Python-land, whereas map skips it and iterates in C).
Maybe you should try to focus on other aspects of FP (and OO too) that can help improving a Python code base, like favoring immutability where possible, using composition over inheritance where it makes sense, applying partial where it makes sense. You can definitely apply FP in a way that most Python devs would approve it too, and where junior/graduate devs are able to quickly join and contribute to the code base.
4
u/Razalhague Apr 07 '24
Remember that programming is a team effort. For someone who's only ever done imperative programming, functional code can be tough to wrap their head around. If most of the people in your team are like this, then it just doesn't make sense to incorporate functional code into the codebase as you'd be introducing code that is hard to maintain and modify for most of the team.
If your natural approach is a functional style, then it makes sense to look for jobs where that is appreciated.
7
u/fhunters Apr 07 '24 edited Apr 07 '24
It's declarative v imperative. Imperative is easier to understand "at first" and aligns more closely to the C abstract machine.
Declarative requires understanding the secret sauce of the declarative syntax. Declarative syntax is extremely dense.
And here is the real kicker.
Imperative programming more closely aligns with the C abstract machine (and the C abstract machine is the great influencer of all modern non functional programming languages).
The declarative nature of FP is a different universe from the imperative C abstract machine. It hides the imperative C abstract machine from you.
All imperative tools do this. Look at HTML and CSS (and how programmers respond to both :-) ).
I find the declarative syntax very powerful and expressive. Much less code. Extremely dense. But that is my personal preference.
Peace
6
u/escaperoommaster Apr 07 '24
In my experience FP tools are most appreciated when they're easy to opt-in (like JS) or opt-out (like Rust). The culture that people are exposed to is going vary massively based on industry and location, but I know a lot of Jr and mid-level engineers who don't in their minds differentiate between IP and at least those ten most common helper functions. I think part of that is because they weren't sold them as "this this amazing, superior and distinct paradigm - never use a loop or reassignment again!", they were sold "hey, here's a neat built-in helper function"
5
u/Blothorn Apr 07 '24
Python is a poor example because the language and community are deliberately opinionated (“There should be one-- and preferably only one --obvious way to do it.”), and functional constructs aren’t it. Kotlin is an example of an imperative/OO language that encourages higher-order functions, especially for collection manipulation.
Point-free style I think is generally unpopular, but for good reason. Partial application and function composition are very elegant in Haskell, but
partial(f, x)is little more succinct and far less readable to the average programmer thanlambda y: f(x, y). (Also, languages in which partial application isn’t encouraged don’t tend to have favorable argument orders for it, and switching between lambdas and partial application is definitely worse than consistent lambdas.)In general, I’d argue strongly against quitting helper functions in any language that compete with idiomatic ways of doing something unless there are severe usability issues with the idiom. Python’s list indexing is terse and powerful; there’s really no excuse for writing a “better” way of selecting a sublist based on indices. The same goes for list comprehensions; I love Haskell and hate Python, but I think map and filter should generally be avoided in Python.
Remember that your reviewers aren’t (or at least shouldn’t be) just worrying about whether they understand your code; they’re reviewing on behalf of everyone else who will have to understand and maintain your code. Understanding a few helpers isn’t much relative effort for someone who is already reviewing a significant change, but it can easily double the effort of someone reading an isolated function while debugging something. Powerful abstractions are good, but weak abstractions actively harmful—and the power of an abstraction should be measured not in absolute terms but relative to whatever is immediately comprehensible to an ordinary user of the language.
4
u/TankorSmash Apr 07 '24
I used to feel the same way. I like to think fo it as a person likes to read code that flows from one thing to the next. When you see a new pattern (whether FP or not), you don't have a mental model of what the next line will look like, so it breaks you out of that flow.
If you've spent 15 years seeing only for-loops and now you're seeing folds and reductions, you're going to get (slightly) frustrated because you're not used to it. Not everyone wants to get slightly frustrated and just wants to write some code.
tldr the longer you've been doing something, the bigger the discomfort in changing it, for better or worse
4
u/delventhalz Apr 07 '24
Python as a language and a community is not very inclined towards FP. These conversations would go differently in a JavaScript shop.
4
u/v-alan-d Apr 07 '24
Difference in paradigm is a jarring difference in the cognition. You understand two different paradigms, which makes it hard for you to realize that.
The reason for the rejection is not because it is not readable or prosaic enough, but because people who work with you aren't used to reading declarations, expressions in programs.
Imperative-only people don't intuit expression because they are concerned with the procedures and isn't used to having the process heavily abstracted into short expressions. Meanwhile, declarative-only people don't intuit procedures because they think in results and result composition, and having to write both the implementation detail (i.e. fn body) and the expected result (i.e. return type and return statement) feels wrong because they are used them being on a different level of abstraction.
I understand that it is equally important to communicate with the same language and to add better grammar and vocabulary to the collective mind. Therefore the way around this constraint is through occasional knowledge sharing.
1
u/thiagomiranda3 Apr 07 '24
The problem with FP and language that heavily emphasize the FP pattern, is that it is very easy to create a total mess almost unreadable for the next guy that are going to maintain your code.
I work in a Scala code base, and almost of chain of concatenated method to transform a data, makes me spend minutes or hours if I need to change that piece of code.
A single method I had to maintain yesterday, received two other function as arguments, and was used in a sequence of flatMaps, zip, scan, compose. It was almost like the factory builder where I need to look into other classes, to understand what the fuck that other two functions did.
I like pragmatism. I first program in a procedural style as much as possible. I compose functions and use functional style only when it makes code easier to READ, not smaller to write. And this is why as much as people complain about java being a verbose language, I almost never have problems with it
3
u/tweinf Apr 07 '24
You're addressing a sensitive issue here.
As a freelance developer, I've primarily utilized RFP tools in "turnkey" projects, where I didn't collaborate directly with my clients' teams. However, occasionally, clients have expressed a desire to review the code themselves. Unfortunately, in nearly 99% of these instances, I've struggled to effectively communicate the benefits of functional programming, leading to my frustration. In fact, out of approximately a dozen cases, I only had one success.
I posit that developers are typically instructed to conceptualize programming as a sequence of "commands" to be executed. This could explain the initial difficulty many faced with callbacks in JavaScript, whereas promises appear more approachable. Imperative programming tends to overlook the notion of time, making it challenging to grasp basic FP principals. Put simply, developers may find it tough to comprehend code that doesn't execute immediately, or more accurately, code that creates functions instead of producing "tangible" values or side-effects.
3
u/memayonnaise Apr 07 '24
It's just a bunch of nitpicking that likely doesn't mean much. People just think the way they do it is better. If you work in a code base it's best to mimic the style.
Also python is hard to do functional like in Typescript, it's best to not fight the language.
3
u/yeastyboi Apr 08 '24
Because FP isn't the norm in Python. I met a new programmer who does React and he didn't know how to use a for loop. Just map and filter. If you want to do more FP Switch to something like C# (sounds weird but it's true), Typescript or Rust.
3
u/ab5717 Apr 08 '24
I haven't used Python in a very long time myself. I have seen mostly negative reactions to FP concepts/jargon usually from older developers who are more set in their ways or project an air of being "gurus" but they have zero experience with functional programming.
IMO it's usually something along the lines of
this new thing confuses and angers me because I'm not familiar with itcombined with (and this is a verbatim quote from one guy I worked with)I've been programming for 25 years and I've never needed this(20 of those years were using C).Which, IMO, being closed minded to learning new things is silly. But even more so when we're all learning a vastly complex
Rustcodebase.I can understand balking at jamming a functional peg into an imperative hole, but when we're using languages that have actual support for Algebraic Structures, it just seemed closed minded to me in that particular instance. (Oh yes, I'm one of those. Balls deep in Abstract Algebra, Category Theory, Homotopy Type Theory, etc.)
Also, I'm a fan of formal specification with model checking and to me, mathematics is the most expressive, flexible, powerful, and precise way to describe anything I know of. Some people don't like math or things that remind them of math.
So my primary point is, I tend to try to learn what is the idiomatic way to express various things in the right tool for the job (or the tool that we're being forced to use).
I've seen people go the other way too and write Typescript or Go like it's C. Using almost zero abstraction and are confused and angered by interfaces
As much as I love math and FP, if it doesn't fit the necessary tool for the job, then I think people will likely reject it.
I have also seen an entire team (a small one of like 6 people) get entirely won over by the declarative, immutable, testable, expressive goodness of FP, when the toolset we were using supported it. There was resistance at first, but in the end, everyone leveled up, and the team was better for it.
3
u/MonadTran Apr 08 '24
People don't react consistently negatively to FP. It all really depends on the company culture, the programming language, the domain, etc.
I have worked for a company where you could push literally any kind of code through - including pure FP or some horrible imperative spaghetti. If people see something unfamiliar, they may become curious and learn it, buy they'll never criticize your approach.
I've worked for a company where people were initially resistant to FP (when it first appeared in C#), but I kept pushing for it and they eventually adapted and understood and utilized it to reasonable extent.
I guess there are people out there who strongly prefer imperative for their language and domain. Maybe it has something to do with Python - Python is rarely used in big projects, so benefits of FP may be unclear. And also FP strongly benefits from a powerful type system and thorough compile-time validations, which Python doesn't have.
12
u/tbm206 Apr 07 '24
I second this. Most devs are allergic to FP.
My conclusion is that most people are intrinsically lazy and are afraid of challenging their deeply seated beliefs about imperative/OOP programming.
The usual excuses are:
This is unreadable; as if your factory of factories within that 10 years old mixin is readable?
This is hard; because you're lazy and don't want to learn FP.
5
u/messier696 Apr 07 '24
I believe it's worth sticking to a subset of a language just to simplify the codebase and make it more consistent. I met people who are allergic to loops and they always insist on using FP concepts. to be honest it doesn't matter that much, I think it's a trade-off what you prioritize in a given codebase. sometimes it's better to adopt the style of the codebase you are working with instead of putting your personal favorite concepts everywhere.
2
u/Former-Recipe-9439 Apr 07 '24
First, many people are not familiar enough with it (or understand the math behind it) to read it with the ease of the traditional for loop. So, they are too lazy to become fluent in it. I have been using fp in Java and TypeScript for many years, and use it almost exclusively now, but it still throws people familiar with my code base.
There are ways that it is difficult to use. I find the browser tools to debug them are not sufficient. It is hard to set breakpoints in them effectively. The arbitrary execution order in Java on multi-processor machines can be the source of subtle bugs for beginners. The Java syntax for fp is awkward to me. The words used for fp functionality differ between languages, once you start using more than map and filter. None of these things keeps me from using fp, but taken together they do serve as a barrier to newcomers.
2
u/SlimeyPlayz Apr 07 '24
im in uni studying computer science and whenever people see my functionally influenced code they think im insane (usually after hearing about dabbling in haskell and apl/bqn as well)
2
u/MaxwellzDaemon Apr 07 '24
Having done functional programming from early on, I don't understand the pushback other than that people tend to get stuck in the first way of thinking they've learned.
People new to the array-language community often find it challenging to think in terms of array operations when they are used to loops which I think is a similar problem to what you describe.
2
u/peni4142 Apr 08 '24
I have a problem with my colleagues writing FP style with C#. Now I need something like a monad in Haskell for C# syntax. The actual way leads to errors that are hard to detect.
But I have no idea how to achieve that.
2
u/pthierry Apr 07 '24
FP is a paradigm shift. It involves getting way out of your comfort zone when everything you knew was imperative.
I love FP because it gives me more reliability guarantees than imperative programming but it comes at the cost of constraints. When thinking about an algorithm, maybe I could imagine mutating something and it would make implementation easier in the short run, but I either can't or shouldn't.
While I've embraced those constraints as helpful, at first they'll be a nuisance for many people.
The nice part of all this is that while it's the reaction of many people, it's not universal.
A friend of mine is a physicist turned sysadmin for the French national research agency, the CNRS. He has a few software projects in Python as a hobby; we started discussing good practices like hexagonal architecture and I've started showing him Haskell.
While he's comfortable with Python and has started using the hexagonal architecture in his Python code, he's also enthusiastic about Haskell and pure functions and immutable data structures.
He's not yet able to write his hobby project in Haskell but he's learning it anyway and he told me he sees clearly how FP would be a huge asset when you want reliable code.
Some people will get it.
0
u/XDracam Apr 07 '24
FP is great. Make things immutable. Limit state to as few places as possible. Reduce unnecessary boilerplate through lambdas.
Unnecessary abstraction is bad. Many FP abstractions introduce a decent amount of performance overhead. And once you start with nested flat maps, and lifting and all that, people get confused. You obfuscate what the code is doing only to save a few characters. You should only use these abstractions when they either make the code safer to maintain, or they reduce confusion for most maintainers by stripping away unnecessary boilerplate.
In your example, using
firstinstead ofx => x[0]makes things a little worse, because now the reader needs to know what this mystery First function does, whereas the lambda is fully obvious, even though it looks uglier.I've tried out a lot over the last 5 years, using FP in C# in a larger team. And my conclusion is: keep things as simple as possible without compromising maintainability and performance. That sometimes means using FP patterns, and sometimes OOP, and sometimes even sticking to simple structural imperative programming.
1
u/schittbricks Apr 23 '24
Because I saw no need in applying extra effort for a non critical system that I could just bash out in any other language in less than half the time.
1
u/maxcruer Feb 26 '25
This FP allergy is also consistent within my working group. Those who use the one-and-only procedural/imperative paradigm, are not allergic; they are scared to come out of their comfort zone, to learn something new, to embrace new ideas. Complex systems should actively use the functional approach, in my opinion. FP helps make complex systems more understandable and maintainable. As it expresses “intent” and not “control flow”. The procedural/imperative approach is suitable for small projects or prototyping.
1
u/Ace-Whole Apr 08 '24
I used python for a while in my university and I did not liked the functional aspects of it. It was inconvenient to use and nobody in the python community appreciated it.
Whereas, in javascript, rust land, this is the standard. Codebase are full of map filter reduce.
Ironically enough, in js, map, etc is slower than loops where it is opposite in python.
0
u/argylekey Apr 07 '24
I think most folks have experience with singleton pattern, and dependency injection in OOP(Java, C#, etc) and their mental models as well as testing patterns are geared toward that.
In schools, OOP is taught a lot because there are tons of jobs in the above languages. I think that OOP is also a great design pattern.
Functional stuff is viewed as a “scripting” paradigm, for better or worse. I think it can be extremely powerful, especially in languages like Kotlin, Javascript/Typescript and Python.
You’re just going to get tons of push back, because unfortunately most devs(myself included) tend to do things in ways they’ve practiced. If the senior or Principle dev on a project hasn’t put out a project with FP, they will push back and claim stuff like, “it isn’t battle tested” or something.
That’s their right, it sucks, but they control the project, I’ll do things their way on their projects and do it my way on mine.
-1
u/PotatoBoy666 Apr 07 '24
How come some read mine own eloquent writings and reject the teachings professed within that very same text? Do they not understand the elegance and precision of the language that I spake? They reject my bloated style and use of unnecessary words, they choose not to comprehend what is a greater and more beautiful way of thinking, while still communicating in a more simple and common manner. How quaint!
0
u/[deleted] May 01 '24
[deleted] — view deleted comment
7
u/[deleted] Apr 07 '24
[removed] — view removed comment
0
u/[deleted] Dec 25 '24
[removed] — view removed comment