TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

What If the Team Hates My Functional Code?

43 pointsby tiltover 2 years ago

11 comments

z9znzover 2 years ago
First we have to agree on what FP style even means.<p>For some it means chaining collection operations so &quot;one line of code&quot; solves an entire problem. This is not unlike the regexp wizard who can perform miracles with a regular expression which is incomprehensible to most other developers.<p>The above is what turns many people off from FP. As another commenter said, &quot;what&#x27;s wrong with a loop&quot;? Indeed, accessibility matters; and if your team and new arrivals are not in that mindset, it&#x27;s like a new language; and they already know a &quot;language&quot; and believe they are getting work done. Why complicate things?<p>I don&#x27;t believe real FP is about doing these super concise expressions which can take considerable time to comprehend. I think FP is really more about pushing effects and mutations to edges, purifying (and simplifying) intermediate steps&#x2F;functions, and using simple data structures.<p>The huge selling point of this kind of FP is in testability. When 90% of your code is pure and operates on simple data structures, testing each function is a breeze. No more do you need layers of setup and mocking. You don&#x27;t even need full objects. If you&#x27;re testing for a valid phone number in a person &quot;record&quot;, you need only pass in a person: { phone: &#x27;12343241&#x27; }. All the rest of the crap which you would normally have to deal with, just to test this one thing, evaporates.<p>It does mean you end up with a LOT more functions. Then code organization and naming becomes a more significant challenge. But the end result, I believe, is still very much worth it.<p>And from my two recent experiences bringing this approach to OOP teams, I have found that after a brief period of fear and uncertainty, they end up adopting it enthusiastically.
评论 #33290895 未加载
评论 #33291004 未加载
bern4444over 2 years ago
I wrote something on this idea as well referring to it as Debug Driven Development[0].<p>Similar to TDD or Domain Driven Design (DDD) we should aim to write code that is easy to debug. Store intermediate values in a pipeline in variables, store predicates in a variable with a human readable name, and avoid in lining complex function calls.<p>There are other techniques that serve this purpose and additional reasons than what this article explores of how or why this is helpful.<p>[0] <a href="https:&#x2F;&#x2F;sambernheim.com&#x2F;blog&#x2F;debug-driven-development" rel="nofollow">https:&#x2F;&#x2F;sambernheim.com&#x2F;blog&#x2F;debug-driven-development</a>
评论 #33291674 未加载
评论 #33285747 未加载
stevenaloweover 2 years ago
Have you tried explaining it to them using arcane jargon and an arrogant tone?
评论 #33289704 未加载
phibzover 2 years ago
When you program on a team choices like using procedural vs OOP vs FP aren&#x27;t up to you since they impact others. You should be coding for your maintenance programmer, the person who will come behind you, need to quickly understand the code and make changes or bug fixes. The maintenance coder may be you, it might be a team mate or it might be someone yet to join the company.<p>Use your own time or projects foe exploring programming styles.
评论 #33285279 未加载
评论 #33284845 未加载
acadapterover 2 years ago
&gt;“This is too clever. It’s unreadable.”<p>This is valid criticism in many cases. Code has two interfaces - the compiler and humans.
skeletover 2 years ago
I&#x27;ll never understand the fear some developers have of the for loop.
评论 #33291873 未加载
评论 #33296948 未加载
评论 #33288272 未加载
tabtabover 2 years ago
A critique of &quot;mainstream&quot; FP:<p><a href="https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;DilbertProgramming&#x2F;comments&#x2F;qg99f0&#x2F;functional_programming_is_dysfunctional_givvitup&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.reddit.com&#x2F;r&#x2F;DilbertProgramming&#x2F;comments&#x2F;qg99f0&#x2F;...</a>
fulafelover 2 years ago
One of the nontechnical advantages of FP focused languages is that writing FP style code won&#x27;t frighten or confuse anyone by itself. (But of course team maintained FP code should still be held to standards about clarity, maintainability, excess cleverness etc)
legerdemainover 2 years ago
If you had to resubmit your code patch four times before you reached version number five, you&#x27;d quickly become a persona non grata on your team. Doubly so if every iteration of code review takes a day and it takes you a week to make a trivial 5-line change.
animitronixover 2 years ago
This is precisely the type of programmer I avoid hiring.
Firfiover 2 years ago
Why not rewrite it to for loops, we need to also accommodate for the programmers who don&#x27;t know what&#x27;s .map.