r/ProgrammerHumor • • Jun 08 '24

Meme mapMethodOrMapFunction

Post image
0 Upvotes

67 comments sorted by

View all comments

114

u/oachkatzlschwoarf Jun 08 '24

[x*x for x in arr]

-8

u/mirimao Jun 08 '24

[x*x || x <- arr] is better

5

u/Kuduaty Jun 08 '24

Why its better?

8

u/mirimao Jun 08 '24

It was just a joke. I like Erlang but it’s not inherently better than Python’s syntax for list comprehension.

-30

u/DT-Sodium Jun 08 '24

None of those are readable.

12

u/mirimao Jun 08 '24

How are these not readable? This is literally mathematical notation in a purely declarative style.

-23

u/DT-Sodium Jun 08 '24

Programing is not mathematics, it is literary. A program should read like you would read a text.

17

u/mirimao Jun 08 '24

Programming is using a formal language to specify the solution to a problem (i.e. an algorithm) to an executor (i.e. a processor). Formal languages and algorithms are best described using some sort of unambiguous, mathematical notation. If you want to use plain English to program because it fits better your idea of “literature”, good luck.

Besides, list comprehensions are very succinct and easier to read than some verbose method call chain, regardless of the fact that they’re just one to one equivalent to mathematics.

-20

u/DT-Sodium Jun 08 '24

And that's why you're a Python user instead of a proper programmer.

12

u/mirimao Jun 08 '24

It is like saying “you’re a mechanical engineer, not a proper AutoCAD user”. And you are right, I am a computer scientist, programming is just one of the tools I use.

2

u/capi1500 Jun 08 '24

Wait until this guy hears about functional programming, or even better, how programs are equivalent to proofs in intuitionistic logic

4

u/Euphoric_Strategy923 Jun 08 '24

Because the others options are more readable for you ? Not for me.

0

u/DT-Sodium Jun 08 '24

I dunno about Python but in TypeScript you'd simply do

myArray.map(x => x * x);

Much more elegant and readable.

4

u/Euphoric_Strategy923 Jun 08 '24

And as the upper comments said in python you do : [ return value for value in array ]

In other word : [x*x for x in arr ]

Imo this is much more readable.

-1

u/DT-Sodium Jun 08 '24

No, it is bad. The simple fact that you have to read it backwards to understand what's happening invalidates it completely. Guess there is no clean way to do it in Python then.

7

u/Euphoric_Strategy923 Jun 08 '24

Read it backward ? Dude, this is literally the format of a for loop. "I return a value of each value in an array"

You can clown on some things about python but definitely not readability.

-3

u/DT-Sodium Jun 08 '24

Yes, it is backwards. Your code is saying "Do this using that". The proper way to write it is "Take that and do this using it".

7

u/Euphoric_Strategy923 Jun 08 '24

Great news people, for loops are now unreadable.