this post was submitted on 05 Sep 2023
1336 points (97.4% liked)

Programmer Humor

19623 readers
19 users here now

Welcome to Programmer Humor!

This is a place where you can post jokes, memes, humor, etc. related to programming!

For sharing awful code theres also Programming Horror.

Rules

founded 1 year ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] [email protected] 15 points 1 year ago (6 children)
[–] [email protected] 16 points 1 year ago* (last edited 1 year ago) (1 children)

Doesn't PEP 8 say spaces somewheres?

[–] [email protected] 15 points 1 year ago

4 spaces, although I'll die on the hill that tabs should always be used instead of space for indentation. Not just in python.

[–] [email protected] 15 points 1 year ago
  1. Use tabs.
  2. Enable visible whitespace.

Tada, your indentation level is nicely visible.

[–] [email protected] 13 points 1 year ago (2 children)

Tabs. But really with modern IDE it's irrelevant. Whatever the tech lead says I guess.

[–] [email protected] 8 points 1 year ago (2 children)

With things like black, flake 8 and Isort I can code however I want, list/format however I want, and commit team compliant content. The dream is real

[–] [email protected] 1 points 1 year ago

I love such formatters and wish they were even more widespread. In many cases, I really want consistency above all and it's so dang hard to achieve that without an opinionated formatter. If the formatters isn't opinionated enough, it just leads to countless human enforced rules that waste time (and lead to an understandable chorus of "why can't the formatter just do that for meeeee").

[–] [email protected] 1 points 1 year ago (1 children)

Wait wait wait, what is this black magic and how have I not heard of it?

[–] [email protected] 2 points 1 year ago

So you can have a local, and a team config. So at time of commit the code rules your team has selected are enforced. So if I looked at my code, on GitHub, it would look as expected by the team.

If I load it locally, it formats as I like.

Check out the cicd stuff on PRs for github

[–] [email protected] 2 points 1 year ago (1 children)

Yeah but outside of that where the code is implemented or in a documentation, tabs are still easier to look through. And it does look pretty as long as there aren't too many nested functions.

[–] [email protected] 1 points 1 year ago

Even with nested functions tabs are neat.

Does you app have too many nested functions?

Use tab width = 2

Do your app have too less nested functions?

Use tab width = 8

Is your app having average number of nested fns?

Use tab width = 4(mostly default)

And all theese can happen without modifying a single byte in the source file, unlike spaces!

[–] [email protected] 6 points 1 year ago* (last edited 1 year ago)

Questions like that are likely to start a war

[–] [email protected] 5 points 1 year ago (1 children)
[–] [email protected] 4 points 1 year ago
[–] Jakylla 1 points 1 year ago (2 children)

4 Spaces, then one tab, then 3 spaces, then 2 tabs, then 2 spaces, then 3 tabs...

Python supports that (and I hate this)

[–] [email protected] 1 points 1 year ago* (last edited 1 year ago) (1 children)

Please elaborate (eg which standard is this defined in?)

[–] Jakylla 1 points 1 year ago* (last edited 1 year ago) (1 children)

Not any standard (and actually not at all something to do for real), but try it, it works

def magic(a, b, c):
    if a > 0:
    	if b > 0:
    	   		if c > 0:
    	   		  return 'All positive'
    
    return 'Not all positive'

print(magic(1,2,3))
print(magic(-1,1,2))
print(magic(1,-1,0))
print(magic(-1,-1,-2))

(you should be able to verify I used both tab and spaces f*cking bad way in this example, like I described)

Output:

All positive
Not all positive
Not all positive
Not all positive


** Process exited - Return Code: 0 **
Press Enter to exit terminal
[–] [email protected] 2 points 1 year ago

That's really interesting. So does that mean the interpreter just checks whether the current line is more indented, less indented, or equal vs. the preceding, without caring by how much?

[–] [email protected] 0 points 1 year ago

"indentation is indentation!" (mr_incredible_cereal.jpg)

it may look messy, but would you actually rather Python didn't support some inconsistency when the intent is clear?

being exact just for the sake of being pedantic isn't useful.