this post was submitted on 27 Mar 2025
33 points (100.0% liked)
Out of the loop
12520 readers
108 users here now
A community that helps people stay up to date with things going on.
founded 2 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Since my other post got a bit wordy and maybe not quite ELI5, let me simplify as much as I can, with the risk of leaving out details:
Say you have a red car but want a car that's identical in every except that it's black.
In a procedural programming language, you may just paint the car black. Or you may build an exact copy of the old car but in black. Or you may take half the parts from the red car and put them into a new black outer shell. Or anything in between. Any change to your old car, your driveway or anything else in the world is called a "side effect". The programming language doesn't prevent you from writing something that has side effects that you didn't actually want. It's the programmers responsibility to make sure.
In a functional programming language, you're not allowed to change the red car at all. You have to create a new black car. In fact, you can't have any side effects. That way, you can't accidentally damage your old car but makes some wishes harder to express.