this post was submitted on 27 Mar 2025
34 points (100.0% liked)

Out of the loop

12978 readers
185 users here now

A community that helps people stay up to date with things going on.

founded 2 years ago
MODERATORS
 

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
[โ€“] dfyx@lemmy.helios42.de 6 points 3 months ago* (last edited 3 months ago) (1 children)

And another example that shows off pattern matching:

Procedural:

int minimumElement(int[] array)
{
    if(array.size() == 0)
    {
        return 0;
    }

    int minimum = array[1];
    for(int i = 1; i < array.size(); i++)
    {
        if(array[i] < minimum)
        {
            minimum = array[i];
        }
    }
    return minimum;
}

Functional (still, no specific language, just an example of what it might look like):

int min(int a, int b) => a < b ? a : b;
int minimumElement(int[] array) =>
    array match {
        [firstElement, ...rest] => min(firstElement, getMinimumElement(rest));
        [singleElement] =>singleElement;
        [] => 0;
    }
[โ€“] ieatpwns@lemmy.world 7 points 3 months ago

To a layman like me it looks like procedural looks more like logical coding and the functional version looks more like a math problem