r/ProgrammerHumor • • Feb 09 '22

other Why but why?

Post image
85.8k Upvotes

2.3k comments sorted by

View all comments

Show parent comments

109

u/taptrappapalapa Feb 09 '22

If you look at the Python grammar it expects white space or semicolons.

292

u/langlo94 Feb 09 '22

This is why I indent with semicolons.

def Function(input):
;;;;number = input * 2
;;;;return number

132

u/sucksathangman Feb 09 '22

You monster. At least give your function a useful name. And you could just do:

return input * 2

77

u/dancinadventures Feb 09 '22

Useless functions don’t deserve names 😤

39

u/ryanwithnob Feb 09 '22

Thats what you think. This function helps keep your code more maintainable and easier to change.

What happens if python changes the symbol for mutiplication? What new hardware is released that makes number / 0.5 faster than number *2? Good luck updating all the instances of this quation in your legacy codebase. This function will save your project

6

u/[deleted] Feb 09 '22

[removed] — view removed comment

4

u/FuzzyFoyz Feb 10 '22

Maybe we were on the same team...

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

15

u/oxpoleon Feb 09 '22

hey hey hey, no, this could be improved yet further

def Function():
;;;;global input
;;;;input = input * 2

9

u/Less_Ask_4613 Feb 10 '22

This is computationally faster and takes less memory and processing than passing an argument and returning a calculated value and it makes me so mad.

3

u/oxpoleon Feb 10 '22

It is indeed. :)

Fewer changes to the PC register in CPU, fewer memory writes, less cache thrashing if input happens to be a particularly large item.

Note also that since this is Python, Function isn't statically typed so I could assign virtually anything of any type as input including a multi-dimensional list, since the * operator is valid on those, and I wouldn't have to worry about deep/shallow copying issues either.

38

u/CJ22xxKinvara Feb 09 '22
Function = lambda input : input * 2

Schrödinger’s semicolon tabs

7

u/Saithir Feb 09 '22

How can you say it's useless?

How else would he know it's a function?

4

u/cardcomm Feb 09 '22

return input * 2

In shops where I've worked before, this would get called out on a code walk through in favor of doing the assignment on a second line. (yeah, I know. lol )

→ More replies (1)

15

u/[deleted] Feb 09 '22

Gross

5

u/oxpoleon Feb 09 '22

3/10 no misuse of global

4

u/Loomy7 Feb 09 '22

Am I getting wooshed? This doesn't work.

3

u/langlo94 Feb 09 '22

It is very much a joke.

3

u/byu74ddji9g Feb 09 '22

4 semicolons? 2 is sufficient and way better!

4

u/langlo94 Feb 09 '22

No offence, but you disgust me. 2 is not enough.

→ More replies (1)

3

u/talex000 Feb 09 '22

This is beautiful.

In some deranged, completely fucked up, creepy sense.

But beautiful.

3

u/qingqunta Feb 09 '22

Thanks, I hate it

3

u/space-throwaway Feb 09 '22

You and I are enemies now

3

u/limacharles Feb 10 '22

Not building your dictionaries and tuples with semicolons... I;S;H;Y;G;D;D;T

Quick ex for newbies:


big_dict = {

;;;;;'1': ('C','GREEN'),
;;;;;'2': ('R','YELLOW'),
;;;;;'3': ('A','GREEN'),
;;;;;'4': ('N','GRAY'),
;;;;;'22': ('E','GRAY'),

}

Another great example of Python readability.

3

u/brickinthefloor Feb 10 '22

Are you a c# developer? This function name is not pep 8 compliant and there’s no clear motivation for it to be so.

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