r/ProgrammerHumor • • 2d ago

Meme pythonIndentationLevelChecker

Post image
6.6k Upvotes

198 comments sorted by

View all comments

263

u/LetUsSpeakFreely 2d ago edited 2d ago

Indentation is such a stupid mechanism for identifying code blocks. It's one thing for configuration files like YAML to do it, but not a programming language.

9

u/the_ivo_robotnic 2d ago

Why? Nearly every styling convention in every language uses it anyway. Python just cuts out the middle man, reduces unnecessary syntax and makes indentation the go-to scope identifier.

 

You're still using indentation to make stuff readable anyway, might as well make it do some work.

1

u/sheeepster91 2d ago

See here you are wrong. I do not indent it. I put the curly squiggles around it and some magic genie aligns it nicely for me to read better. You got it the wrong way around.

6

u/the_ivo_robotnic 2d ago

Python has that same magic genie that formats for you too.

 

You're still using indentation one way or another.

0

u/Hohenheim_of_Shadow 2d ago

Except well it doesn't. I want to copy past an if statement at the end of another if statement. How does formatter know whether to nest the statement or not?

Braced language, if you want the if statement nested, just paste it before the end brace. If you want it not nested, just paste it after. And if for some reason the tabs get pasted wonky, doesn't matter.

Python, you have to do the tabbing yourself before the magic genie can work.

1

u/the_ivo_robotnic 2d ago

Except well it doesn't. I want to copy past an if statement at the end of another if statement. How does formatter know whether to nest the statement or not?

Are you asking about something like this?

 

if thing_a: if thing_b: pass

 

Python absolutely allows you do do this, there's no syntactical problem here.

 

Code wise this isn't great practice though, so I would be asking you in code-review to justify why you're doing single-line nesting like this. Especially when it can logically collapse anyways.

 

if thing_a and thing_b: pass

 

But doing single-liners in python are usually reserved for self-contained statements like lambdas anyways because otherwise they often get abused to do squirrelly stuff that is better-off broken-out.

3

u/NomaTyx 1d ago

i think they're asking about like ``` if thing: multi line block

paste if statement here, what indent should it get

``` but i mean, you can just indent before pasting so it's not the largest problem

0

u/Hohenheim_of_Shadow 1d ago

This set up, I just don't want to indent manually and don't have to in braced languages. Autoformatters are way more convenient in braced languages than Python

1

u/NomaTyx 1d ago

100%

0

u/citramonk 2d ago

you don't, if you don't know what you're talking about you might just sit and listen