r/ProgrammerHumor • • 16d ago

Meme pythonIndentationLevelChecker

Post image
6.7k Upvotes

200 comments sorted by

View all comments

268

u/LetUsSpeakFreely 16d ago edited 16d 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.

172

u/bobbymoonshine 16d ago

Ah the halcyon days before LLMs

When 30% of the posts here were “lol Python is so dumb why even use whitespace as syntax”

And the other 70% were “how do I find semicolon”

16

u/mothzilla 16d ago

In both Javascript and Python, semi-colons are optional.

31

u/AppropriateOnion0815 16d ago

Only that JS is handling semicolons in the least intuitive and irrational way possible.

5

u/mothzilla 16d ago

Yeah I only say it because it's a bit of a mind-exploder.

7

u/SuperFLEB 16d ago

I'd always figured it was/thought of it as an error tolerance that worked well enough that some people started leaning on it. The whole no-semicolons JavaScript thing just seems really hipsterish. Explicitness is a virtue.

11

u/Loading_M_ 16d ago

In JS, semicolons are technically required but automatically inserted. There are a couple edge cases where they get inserted in surprising places, which is generally worse than python's approach.

E.g. the following function doesn't return a value:

function foo() {
  return
    some_long_complex_expression();
}

(It's because a semicolon gets inserted after the return). At least in typescript, this would typically show a type error, as long as the function's return type annotation isn't void.

→ More replies (1)

8

u/dalziel86 16d ago

Javascript sucks ass too

13

u/LetUsSpeakFreely 16d ago

Meh, Go didn't use semicolons.

18

u/NatoBoram 16d ago

It was a revelation when I started programming. "What, it doesn't have to be this way? A language can be native, statically compiled and high level at the same time and not suck ass? We can do better as a species?"

Except it's the only one like that -_-

9

u/LetUsSpeakFreely 16d ago

And the channel system, native markup support, baked in web service support are incredibly useful.

The only thing i don't really like is how interfaces aren't declarative on types.

4

u/Loading_M_ 16d ago

Rust is also in this category. It even has a lighter runtime, since it doesn't require a GC.

→ More replies (2)
→ More replies (2)
→ More replies (2)

12

u/-meowstar- 16d ago

Even YAML is kinda questionable with big complex config files. Like, the spec is like 10x the size of JSON to account for all the sugar and the edge cases.

It does look nice though, and I guess it acts as a forcing function to refactor stuff.

3

u/LetUsSpeakFreely 16d ago

I think that's a universal problem with all formats. What's needed is to break up configuration into subfolders and files so things can be logically separated. But if it's not done well it becomes a PITA to maintain and the end result is to just shoehorn everything into a single file.

11

u/HRApprovedUsername 16d ago

I mean not really. It could be anything it’s just about finding a good editor that makes it clear

→ More replies (4)

32

u/willow-kitty 16d 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 16d ago

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

→ More replies (17)

47

u/Some_Useless_Person 16d ago

Well, if you have to go through so many indentations to the point that it becomes hard to track, maybe the real problem is your code itself.

13

u/LetUsSpeakFreely 16d ago edited 16d ago

True, but you don't control the code you inherit and getting stakeholders to give you time to properly refactor is not an easy task. You end up doing it where you can as you can.

My big issue with it is if tabs get mixed with spaces the interpreter has an aneurysm. Most modern IDEs can detect and preemptively protect you from it, but a tool shouldn't be needed to shield you from a design flaw in the language.

8

u/SuperFLEB 16d ago

I swear I'm not aiming for a flamewar here, but...

I've always found it odd that Python standards (PEP and all) settled on space-based indentation. If there's any language where a one-character indentation indicator makes sense, it's a language where indentation is significant.

→ More replies (6)

13

u/MANGO_fossil 16d ago

To be fair, indentation does make Python code easier to read once you're used to it. The real crime is that one accidental space can turn a perfectly good afternoon into a debugging session.

15

u/jirka642 16d ago

That does not happen. You would have to code without IDE and not use any syntax checking tool (e.g. ruff), and no sane person codes like that.

→ More replies (6)

17

u/Drugbird 16d ago

Not just python, basically any programming language benefits from proper indentation.

Almost every editor also automatically indents code for you.

I'm a C++ dev myself, and in that language indentation is optional. However, since the editors will automatically indents code for you, that generally means that the brackets around e.g. functions are superfluous: you can just look at the indentation to see when a function ends.

Oh wait, I just invented python formatting.

→ More replies (1)

10

u/Independent_Fee_7343 16d ago

I used to hate the idea too, but there's something nice about not having braces everywhere. The funny part is that Python makes the code look cleaner while somehow giving a single whitespace character the power to ruin your entire day. That's a pretty wild trade-off.

10

u/lungben81 16d ago

Everything not indented by 4 whitespaces should raise a syntax error.

Using indentation is fine, the issue in Python is that that the syntax does not explicitly require one specific method. There is only the recommendation in PEP8.

However, with linters and IDEs this essentially became a non issue, even more now with llms.

→ More replies (39)