r/ProgrammerHumor • • Aug 26 '20

Python goes brrrr

Post image
59.2k Upvotes

789 comments sorted by

View all comments

413

u/[deleted] Aug 26 '20

Started learning python and thats my favourite thing after no ; thingy

115

u/ProbablyInnacurate Aug 26 '20

I love comprehensions.

50

u/axlee Aug 26 '20

I prefer lambdas + map/reduce/filter/etc, usually easier to understand with a quick look

27

u/marmoshet Aug 26 '20

Functional programming gang rise up

5

u/-Potatoes- Aug 26 '20

In my first year at university we did functional programming (not in python, unfortunately) and I think its left me forever scarred

→ More replies (3)

15

u/ProbablyInnacurate Aug 26 '20

Oh yeah, defs. I get stuck making them complex, unreadable and un-pythonic because it's fun.

7

u/Ghos3t Aug 26 '20

I've heard list comprehension is more optimized that map, reduce etc due to the way it is implemented in Python. Something to do work map, reduce being function calls

6

u/[deleted] Aug 26 '20

My favorite is that there are options so you can pick the syntax you prefer

→ More replies (1)
→ More replies (3)

26

u/Mr_Redstoner Aug 26 '20

As a (mainly) Java programmer, a lot of my Streams would be comprehensions in Python.

16

u/mpa92643 Aug 26 '20

As a long time Java developer, I so very much appreciate Streams. It's so much more readable to say "I have a stream of Xs; convert them to Ys, take out the lowercase ones, add them to a Set, and return it" than "create a new Set. Now iterate through all the Xs. Declare a variable of type Y. Now set it to the conversion result of X. If Y is lowercase, add it to the set. Now return the set."

And that's a simple example. Once you start dealing with Lists of Lists, things go off the rails so quickly and the nesting becomes so ugly.

7

u/Dizzfizz Aug 26 '20

That’s interesting to read, as a beginner I find them very confusing and think it’s much simpler to do one thing after another, especially once it comes to looking for bugs.

9

u/AnotherUpsetFrench Aug 26 '20

You will get used to it, I promise, especially when you will start to gain more time and less headaches.

8

u/mpa92643 Aug 26 '20

Yeah, I can understand that. Streams add another layer of abstraction that requires understanding the core behaviors first. Streams are basically shortcuts for longer blocks of code, and they're easier to compose but can be harder to debug if you're not certain about what's happening under the hood. They provide incredible flexibility and conciseness, which is why they're so useful.

Just wait until you start getting into RX. Even once you get the hang of Java Streams, RX is going to make you so confused and frustrated that you're going to want to give up, but sticking with it is so worth it in the end. I'd recommend waiting a few years before even looking into RX though.

→ More replies (1)
→ More replies (9)
→ More replies (2)

7

u/Rasmaellin Aug 26 '20 edited Jan 01 '21

Learn Haskell! We have general monad comprehensions. Lists, IO, parser combinators—as long as it's a monad, we have comprehensions for it. And sometimes even comprehensions for non-monads with ApplicativeDo.

Heck, I wrote a brainfuck interpreter comprehension not too long ago.

→ More replies (3)
→ More replies (3)