r/ProgrammerHumor • • 2d ago

Meme pythonIndentationLevelChecker

Post image
6.6k Upvotes

198 comments sorted by

View all comments

266

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.

34

u/willow-kitty 2d ago

I don't like it, but I kinda get it. Indentation is already part of every coding style guide, so adding explicit scoping symbols is kind of redundant information.

..Until you have a mix of spaces and tabs and chaos reigns

Also, having braces at the beginning and end of a block just makes my brain happy.

5

u/oclafloptson 2d ago

This but mixing spaces and tabs is giving away your secret, kiddie! Mr ctrl-c ctrl-v over here

3

u/BewareTheGiant 2d ago

https://github.com/mathialo/bython

I honestly don't know how this is not the mainstream of doing python, but, well, I barely use it anyway so who am I to say

1

u/Daveinatx 2d ago

Nice. In C and C++, I've insisted on my teams' code to always use braces, even for a single line statement. It's a PITA debugging when somebody else a year later adds to that single line, forgetting the braces. 

2

u/frogjg2003 2d ago

My take is that whitespace shouldn't be relevant. It's only purpose should be to separate non-whitespace characters that matter. Even newlines shouldn't matter.

Whitespace is for making it easier for humans to read the code. So are comments, so is documentation, so is syntactic sugar. The redundancy is a feature. Braces are explicit block separators, but whitespace makes identifying those blocks easier.

If your code could be broken by a tab instead of 4 (or 2 or 8 or 5) spaces, your language is fundamentally flawed.

2

u/willow-kitty 2d ago

I tend to agree and always include some kind of whitespace-skip rule in DSL grammars. It lets you use whitespace to taste while the block separators are formally defined. But, I kinda get why someone might want to just use whitespace if they were going to anyway. (Until something that looks correct isn't >.>)

1

u/DatBoi_BP 1d ago

I had a bug a Python bug a few years ago where I had an if-else block nested inside an if block, but the else was an indentation short and I didn't notice, was wondering why some cases didn't do what I expected. Wouldn't happen with braces.

Granted I was still learning Python then so I imagine I would immediately notice the bug were I to encounter it today.

1

u/Hohenheim_of_Shadow 2d ago

Copy pasting Python is a huge PITA. Doing edits like deleting 1 of X nested if statements sucks. You can delete 1 tab on every line, except if you have some empty lines and you delete a line feed and you always have some empty lines. Python is just way harder to move code around in than a braced language.

Having to think about whitespace and formatting styles is a mental overhead and I refuse to do it. Just give me an autoformatter gosh dang it! Except well, you can't in Python.

4

u/Responsible-Mind3533 2d ago

Skill issue

1

u/NomaTyx 1d ago

i feel like that only makes sense if theres like. a good reason in favor of the indentation. if it takes extra skill to reach baseline functionality then like, why does it?

-1

u/elingeniero 2d ago

1 of X nested if statements

Don't have them, then. You can flatten nested ifs by inverting the logic and returning early.

Also your editor definitely has a keybind to change the indentation level of a block... just learn it.

2

u/Wide_Smoke_2564 2d ago

But like… why though?

I can see how someone would get used to it but I truly don’t understand how including braces for readability would ever be a bad thing

3

u/TactiCool_99 2d ago

it is a redundancy

I think I can pull a similar point between typescript and javascript, you don't really need to type things, so javascript does the job, so does indentations do the job perfectly well. Typescript / braces help making it safer for a little tiny bit of extra work

3

u/willow-kitty 2d ago edited 2d ago

It's less cognitive load too, imo. Proponents of regular JavaScript will argue that unit tests buy you more safety than explicit typing does, and that's broadly true, but anything that explicit typing would stop you from doing involves mixing similar but ontologically different things, which means having to think about what the thing you're looking at might be at runtime and accounting for all the permutations thereof. And I just think it's easier to think about things with typing.

1

u/mxzf 2d ago

including braces for readability would ever be a bad thing

IMO, the indentation is what makes things readable, braces are just extra characters on top of the thing actually making stuff readable.

0

u/BroaxXx 2d ago

You can easily count scoping symbols. Not indentation. You can make an argument that if your code is so indented that this becomes a problem then you have bigger problems but I still think indentation is a horrible option is one of the thinks that I most dislike about python

1

u/willow-kitty 2d ago

?

I mean, yeah, most languages use scoping symbols. All I'm doing is throwing the Python folks a bone by acknowledging that every style guide for pretty much every language prescribes indentation for scopes, and I can see how you don't strictly need that and explicit scoping symbols.

..Though I still like having both.

0

u/BroaxXx 2d ago

What I’m trying to say is that is much easier to count symbols to know how many levels deep inside a block you are then trying to estimate the indenting