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
33
submitted 1 month ago* (last edited 1 month ago) by [email protected] to c/[email protected]
 

I've seen a couple posts in the top in the last 6 hours feed, and it seems like people are really up in arms about this functional programming stuff. Not really sure what it even is.

It looks like it's people writing bad programming or something? Like a lot of extra stuff that is not necessary?

EDIT: sorry everyone, I'm not a programmer and I don't know to much other than a little java and python. I guess I should have posted this in Explain Like I'm Five.

you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 6 points 1 month ago* (last edited 1 month ago)

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.