For further actions, you may consider blocking this person and/or reporting abuse
Read next
Advent of Code 2024 - Day 20: Race Condition
Grant Riordan -
Is sourcehut git access denied for anyone?
Zaba Va -
WIP Notes working though Render hosting Flask + Vite + React + Wouter
Kanishka -
Django, Flask, FastAPI, and More: Choosing the Right Python Framework for Your Project
Hexadecimal -
Latest comments (8)
I agree with what the others said about pure functions and immutability and will extend it a bit.
If you want to bring functional programming to the real world,
there is a great pattern you should be aware of :
Functional Core, Imperative Shell
where you put your business logic in easily testable pure functions and have a thin imperative layer that is responsible for doing the side effects.
Do watch the screencast => destroyallsoftware.com/screencasts...
NOOP
🤣 🤣 🤣
I think this is the exact opposite of a "like I'm 5" answer.
LOL
Functional programming is a lot like playing with legos. You grab one lego, connect it with another lego and the result is yet another lego that can potentially be connected with other legos. It's legos all the way down.
To me functional programming is programming with pure functions. Use pure functions as much as you can. A lot of fancy patterns exists only to enable you to do "impure" things while still being technically pure (which is the best kind of pure).
To finish I'll just leave this right here.
Anjana Vakil — Functional Programming in JS: What? Why? How?
Scott Wlaschin - The Power of Composition
Okay, one last thing. I've documented everything I know about functional programming here on DEV, if anyone is interested you can find a guide here.
In it’s purest sense, functional programming comes down to one simple principle:
‘Everything is a function.’
Functions are, of course, functions. Variables are functions that return their value. Modules are functions that return their contents. This has a couple of interesting implications that lead logically to many of the other things often associated with functional programming, namely:
map()
andreduce()
in Python both use calling conventions that would be seen in many functional languages, explicitly taking the iterable/enumerable that they will be operating on as their first argument. This, in turn, lends itself easily to dependency-injection design patterns, which makes testing and interoperability much easier.In addition, there are a number of other things often associated with functional languages that follow logically from functions being such a core part of the language but aren’t a strict requirement for the language to be functional, with the two biggest ones being
Enum.each/2
function from Elixir, it takes an enumerable and a function, and then evaluates that function for each item in the enumerable).this was a fantastic answer. maybe a bit beyond 5 but well worth it. with a few code snippet examples this would be great as it’s own post.
this is as 5 as i can get thinking about the practical aspects of FP (not all the theory)! let’s call each function an action.
each action has one distinct purpose.
each action can only work on the things you give it - it is blind to anything outside of it. meaning it can’t see or change anything outside the action.
if you put the same thing into an action you get the same thing out every time.
if you want more complex action you put in multiple actions into a composing action that performs them for you.
if you want an action that is pre-configured you call a pre-configuring action and give it some configuration information. it then gives you the pre-configured action back (with the configuration info saved in it) for you to use.
if you want to perform many sequential actions you can coordinate the output of one action as the input of the next action to get from the start to the finish one action at a time.