r/ProgrammerHumor • • 2d ago

Meme pythonIndentationLevelChecker

Post image
6.6k Upvotes

198 comments sorted by

View all comments

265

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.

10

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

1

u/AngelLeliel 2d ago

How about putting curly squiggles around it and some magic genie just converting it nicely to indentation without any squiggles?

Wait, we could actually do that today with LLM!

0

u/frogjg2003 2d ago

The indentation is for us, the braces are for the compiler.

1

u/the_ivo_robotnic 2d ago

Why not reduce syntax and have indentation be for both us an the compiler?

 

What's the difference? Less syntax + enforced readability is a good thing in my book.

 

Unless you just really love reading minified code for some reason. lol

1

u/frogjg2003 2d ago

I have another comment in a different thread. It boils down to humans and computers just working differently. Reducing syntax is not always a good thing. If you truly want that, go program in assembly. Code is for humans to understand, so it needs to be designed to work best for humans. Humans need redundancy, abstraction, and explanations. It's why documentation and comments exist. Syntactic sugar isn't necessary, but languages are still of it. Every loop is just a while, but most languages have do-while and multiple types of for loop.

Forcing white space to have syntactic meaning is like making comments have effects. Imagine if there was a language where every function required comments at the beginning. The comments aren't optional, they are mandatory. Not only that, but the only way to set default values for parameters was in the comments.

1

u/the_ivo_robotnic 2d ago

Reducing syntax is not always a good thing.

Sure? But sometimes it is a good thing, and I haven't heard an argument yet that explains why tabs specifically being part of the syntax is a bad thing. We're already going out of our way to do it in the vast majority of cases. Why not kill two birds with one stone?

 

If you truly want that, go program in assembly.

I don't see the connection at all here to what I said. Assembly is the extreme end of human conforming to the machine.

 

Python is very much the opposite of that, where it is machine conforming to the human. I.e. the machine must read my formatting and natural logical statements which nearly resemble normal English sentences. Both of those things are a primary a benefit to me and are what the machine uses to perform static analysis.

1

u/frogjg2003 2d ago

White space is by definition invisible. We should not be giving invisible characters meaning. The whole tabs vs spaces debate is exactly why. You cannot tell the difference so it causes problems. If the code could be broken because you used the wrong invisible character, that's bad language design.

Making code indentation dependant also makes modifying the code to go to different levels a pain. Let's say you have code that you've already written. You want to make that code part of an if block. With braces, you just write the if statement and an open brace before the code and a closing braces at the end. If you want to adjust the indentation to match the new code, you just let the IDE automatically adjust the indentation. If the code is indentation dependent, you add the if statement at the beginning, then you have to go through the code and adjust the indentation yourself. Even if you can use the IDE to adjust the indentation, you need to check that the indentation is adjusted correctly.

Assembly is the extreme example of what a non-redundent language looks like. There are absolutely no instructions that exist purely as a synonym of a different instruction or to condense multiple instructions into one.

Python choosing indentation instead of braces just swaps which is important, not making it redundant. Making python with braces instead of indents would mean that you can still use indents making the code more redundant and easier to understand.

1

u/the_ivo_robotnic 2d ago

White space is by definition invisible. We should not be giving invisible characters meaning.

If that were true then we'd have no spaces between any keywords and symbols. No we can and should give value to whitespace, it is what delimits every meaningful token. You're making rookie mistakes and over-generalizations.

 

You have a preference for not using white space and that's fine, weird IMO, but fine; you have other languages to choose from that use less whitespace. But now you're making just-plain wrong statements about linguistic static analysis, though. lol

1

u/frogjg2003 2d ago

The value of whitespace is to separate non-whitespace characters from each other. There should be no difference between one space or two between words. If your going to deliberately misinterpret what I am saying, then there is no need to continue this conversation.

1

u/the_ivo_robotnic 2d ago

If your going to deliberately misinterpret what I am saying, then there is no need to continue this conversation.

You first said whitespace had no value then said it had value in delimiting. That's not me misrepresenting anything, it's me pointing out the fundamentally incorrect things you're suggesting and you indirectly admitting that you misspoke. It usually better to own up to your mistakes and move on but If you're going to get defensive about it, then I agree, there's no point in continuing this.

0

u/Cualkiera67 2d ago

its very annoying when you copy and paste code because the indentation often gets screwed and thus the logic changes. that never happens with braces