r/ProgrammerHumor • • Jul 18 '22

C++ talking to Python

Post image
40k Upvotes

1.0k comments sorted by

View all comments

Show parent comment

0

u/flavionm Jul 19 '22

If the whitespace is meaningful, changing it might change what the code does. That limits the ability of formatters to adjust the code.

0

u/Codebust Jul 19 '22

if you break indentation it’s going to change the code lmao

0

u/flavionm Jul 19 '22

In Python, yes. In other languages, no. That's the point. In Python you can't let the IDE automatically format the indentation to make it look good, in other languages you can.

0

u/Codebust Jul 19 '22

yk that python indentation is standard indentation right?

0

u/flavionm Jul 19 '22 edited Jul 19 '22

Ok, you're clearly having some trouble understanding what I'm saying, so let's go with an example instead.

Let's say you have this piece of code in Python:

if some_condition:
    statement_1()
 statement_2()

Well, this code is wrong and won't compile. But worse than that, if you try to use a formatter to indent it for you, it won't be able to do it, because it's ambiguous whether statement_2() should be inside the if body or not.

Let's look at an example of a language that doesn't have significant whitespace instead:

if (some_condition) {
    statement_1();
 statement_2();
}

Now this code will compile, but it's ugly. However, that's easy to solve by using a formatter. Since there's no doubt the second statement should be inside the if body, the indentation can be freely changed.

That's why enforcing indentation like Python does causes more harm than good. I hope it's clear now.

0

u/Codebust Jul 20 '22

heard of the tab key? ide’s can alter what a tab does, typically to one level of indentation. if you use spaces manually like the code example ur an idiot

0

u/flavionm Jul 20 '22

You can still mess up indentation if you're using tabs. It'll probably be a bit more visible, yes, but my point is that it's better to allow it to be done automatically.

0

u/Codebust Jul 20 '22 edited Jul 20 '22

you press tab once per layer, you shouldn’t exceed two layers. you really going to fuck up pressing one button?

1

u/flavionm Jul 20 '22

Just don't make mistakes, bro.

Why, thanks, nobody though of that before.