Can someone explain this pic to me? What the fuck is going on there in the bottom example...

Can someone explain this pic to me? What the fuck is going on there in the bottom example, and why is this a separate 'type' of programmer? The top is obvious to me but I can't read the the bottom one at all

Other urls found in this thread:

en.wikipedia.org/wiki/Fold_(higher-order_function)
twitter.com/NSFWRedditGif

developers who try to be "clever" to reduce the amount of code

Bottom is a """clever""", functional approach, top is a traditional imperial approach.

Although I've seen worse. The bottom code is not exactly hard, but there are special snowflake programmers who try to condense as much code as possible into one line, for whatever reason, instead of just writing more readable code in 2-3 lines.

am I dumb if I don't do the bottom? I mean, I assume I could learn what's going on there (although I don't know what language this is), but it's so fucking ugly I feel like whoever has to make changes after the fact is going to spend much longer just reading trivial bullshit like this than if I'd just written it as per the top

The bottom is en example of the "clever" python one-liner.
Just chain library calls together and don't do anything yourself.
Don't even avail yourself to the possibility that you might want to expand functionality in the future.
Programming isn't something you do to simplify your life, you masturbate to dumb code snippets like these and upvote others who do the same on reddit and stackoverflow.

It's PHP garbage

this is python? what's the $ for?

python lends itself to this kind of shitty code

It doesn't hurt to look at functional programming, though it doesn't really matter which language.

I had a mandatory Haskell class in school, it had some funny stuff in it. Not super useful, but once you know the functional approach in one language, you basically know it in any.
I can decipher what's going on in the bottom part, but I don't know the language either, and as you said, I wouldn't write it like that myself

Nice meme

No. There's no benefit from using the bottom version speed-wise (probably it's slower) and it makes code less readable.

>it makes code less readable
Nice meme pajeet

lol that's not python

any programmer who uses php should consider dousing themselves in motor oil and jumping into a live volcano

not him but if you have an actual rebuttal, I'd like to hear it

>rebuttal to an unfound opinion
Nice meme

...ok
so you're just here to shitpost and do nothing else?
posting "nice meme" over and over isn't funny or entertaining my dude

> thinks he isnt doing the same
Nice meme

>I make thread
>guy posts statement
>you say "that's dumb nice mem xD"
>I wonder why because I'm genuinely curious and I want to learn
>you continue posting "le epic nice mem xDD"
>stop shitposting and just answer the question please
>"no u lol xdddd"

ok bud..

>imperial approach
I prefer metric system m8

i think its missing a half of the image,
under the php screen theres another screen with a sane language

Bottom example is using laravel's obfuscated way of using php's array_reduce()

>he wonders why with an unfound opinion
Nice meme

>it's just self-flagellation
oh

Found the true pajeet

>reduce
That wouldn't even work. That should be `map`.

Bottom one is definitely better though. It just looks a bit weird there because PHP has a fairly verbose syntax for lambda and doesn't have a native clean way of chaining list operations like that.

That Laravel `collect()` thing would be nice for something a bit more complicated than just one `map`, but for that example,
$contents = array_map('file_get_contents', $files);

would be fine.

>any programmer who uses php should consider dousing themselves in motor oil and jumping into a live volcano

found the node hipster.

PERL guy reporting for duty.

>map and reduce are hard to read

Spotted the idiot

When will functional hipsterism die?

Also why the fuck are they "reducing" right there? Don't they want to map by that function?

Since it's just concatenation, fold would make even more sense.

They failed at making a functional wank. Kek

>"I can read baby's first functional programming example"
>"I watched a YouTube video on lambda calculus!"
Pathetic

the one on the bottom is what happens when you need to impress people on the net so bad you read documentation extra to pick up on useless features

Reduce is fold breh

en.wikipedia.org/wiki/Fold_(higher-order_function)

So the first implementation is easy to read and understand and the bottom is not? is that the point?

`fold` is the same thing as `reduce`.

There's nothing wrong with "functional hipsterism". It's the cleanest and most concise way of doing what they're doing. It is very simple and easy to understand and write, but can look confusing if it's a style of working with lists you're used to. What they're doing there (assuming they meant to use `map`) is fine.

The problem in PHP is that you can't chain things like that natively so it looks weird.

In modern JavaScript, this style of programming is actually pretty readable, assuming you've ever used basic list functions and are familiar with the syntax:
[1, 2, 3, 4, 5]
.map(x => x + 3) /* Add 3 to each item */
.filter(x => x < 7) /* Filter to only have items < 7 */
.forEach(alert); /* Run alert() on each item */

Why do modern devs fail at understanding basic higher-order function functionality?

This shit has been prominent since the days of C, LISP and early JS, and OO language makers are starting to realize what they've been missing out on.

the point is the difference between imperative programming and lisp faggots, using a shitty php framework to show it

The first one is messier
>creating an empty variable first
>looping to fill it
Completely unnecessary. It's literally asking to be streamed through functions. Why do you hate functions?

I like functions, but compared to you I'm not married to them

Both are ugly af

Does PHP seriously not have built-in list comprehensions?

But you are married to using shitty constructs

You can use array_map as in PHP isn't perfect for things like this, since a string containing a function name is what you use to refer to a function instead of using an anonymous function, but it just so happens to be perfectly clean for the example in the OP.

What shit language is that?

ITT:
>functional programming is bad because PHP is bad
OOP fags are truly getting desperate

It's funny because PHP wasn't even OO at first.

>Can someone explain this pic to me?
The bottom developer tries to be clever and fucks up. In the bottom example the contents variable will just contain the file content of the last file in the array.

PHP has always been a kitchen-sink language with no planning

It's the nethack of programming languages

>using functions is 'trying to be clever'
What meme are you guys trying to push?

>Oh man map and reduce are so hard to comphrend
>fuck you hipster lambda calc faggot

Man you really showed me, idiot. A child could understand these functions better than you can.

Didn't think people in this board would consider map or reduce clever. They are 2 of the common, standard techniques for transforming data in any language

your extreme hostility, condescending attitude, and overall delusions of superiority probably means that you suffer from some sort of autism, and I also imagine you've never worked on a professional project in your life. I mean, people don't like when you make things less easy to read for little to no reason.

>It's not easy to read
the fuck am I reading

What can I say? In the OP it looks less readable. What language is it again? PHP? Okay.
But some languages make this more seamless.
For one thing that language follows C-style syntax which makes it awkward (see javascript). And these lambdas use the 'function' keyword, which is long.
Ruby would do something like
[1, 2, 3].map {|x| x*2}

and lisp
(mapcar (lambda (x) (* 2 x)) '(1 2 3))

and haskell irrc also has smaller lambdas
\p -> 2*p

perl's lambdas are also awkward
&map sub { shift * 2 } (1, 2, 3);

but less so than with javascript where you usually end up with
function foo(function(function( ....

Yes, I've seen 3 functions nested in a row, that's what drove me away from javascript the very same day I tried it,long before I knew lambdas existed because fuck the programming education these days.

This is why Python is great:

files = ["one", "two", "three"]
contents = [file_get_contents(file) for file in files]

or alternatively

contents = [file_get_contents(file) for file in ("one", "two", "three"]

That is supported by any language that takes FP at least semi-seriously

Yep, python's idea of using the same format as mathematical set notations, which is naturally readable is one of many things that it got right that other languages should have adopted. I use it so much and can't imagine not having it

Glad someone got that

>reduce
>clever
Never change Sup Forums

Stop chatting shit m8

>Memeing in a meme thread
You're going 3 memes per hour over the limit sir

Nice meme

not him but are you really this dumb?
>relative comparison
>vs
>independent evaluation
do you even speak English?

Why not

$files = ['one', 'two', 'three'];
$get_file = function($key, $file) { return file_get_contents($file); };
$contents = collect($files) -> reduce($get_file);

snowflake programmers = 90% of the high paid programmers -- you can blame agencies for this

ITS PHP

oh fuck off
1. its PHP
2. shut the fuck up you don't know anything at all about it

makes you realise that nobody on Sup Forums really knows what the fuck they are talking about

i talked to a php programmer once
he was a smartarse with extremely bad hygiene

I am this type of developer:

$contents = file_get_contents('one') . file_get_contents('two') . file_get_contents('three');

holy shit, i knew Sup Forums was stupid, but this is a whole new level. this isn't some "magic python library" shit, its a basic fucking higher order function

for a subreddit that always spouts memes about SICP and stallman you retards sure don't know even the basics of functional programming

>for a subreddit

this thread .. file it .. this is the day Sup Forums exposed

nobody in here knows what the fuck they're talking about

What is this doing? Isnt $file one, two, three just created? How could it have any contents in it if it was just declared above.

What method is collect() in the SPL? I can't find it anywhere. This notation also denotes that collect() will return an object. Instantiating an object is much more heavy on memory and makes the procedural (and readable) way more efficient.

No, 'one', 'two' and 'three' can be files in the relative directory that the script resides in.

oh i see thanks.

Functional programming is one thing, having the rich type system Haskell offers is yet something else. And that gives you ways to use functionality and abstractions that are not practical in other languages (I'm looking at you Lisp).

If you look at the URL in the box at the top of your browser window you might notice that after the http:// and "boards" parts it says Sup Forums

This part of the website address indicates the site you are currently viewing

You are on Sup Forums.

For more information on Sup Forums, type "Sup Forums" into your Bing toolbar.

ebin

eh, I like array_map better.

nice1

>mapreduce
>for loading files

WHAT THE FUCK IS HE "COLLECTING"? WHY IS THIS "CLEVER PROGRAMMER WASTING TIME TO WRITE A REDUCE FUNCTION IN THE FIRST PLACE? WHAT THE FUCK IS GOING ON.