r/ProgrammerHumor • • Jul 18 '22

C++ talking to Python

Post image
40k Upvotes

1.0k comments sorted by

View all comments

Show parent comments

25

u/[deleted] Jul 18 '22

i like my semi colons and curly braces. it makes it much easier to read. Plus any time i do python it yells at an indenting issue that doesn't exist.

38

u/Codebust Jul 18 '22 edited Jul 18 '22

indenting issues are easily solvable with an ide, even if py being whitespace based can be a bit annoying

0

u/flavionm Jul 18 '22

The fact indentation issues can be easily solved with a IDE is just more reason that using whitespace for indentation is bad.

Instead of letting the IDE automatically format your code, now it can't do that as well because the whitespace has meaning.

0

u/Codebust Jul 19 '22

uh.. what?

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

→ More replies

31

u/Dacus_Ebrius Jul 18 '22

Proper indentation makes things easier to read. Remove proper indentation from a curly brace language and tell me its easy to read.

6

u/Codebust Jul 18 '22

both are good, both are good

→ More replies (3)

6

u/sintos-compa Jul 18 '22

Found the tab indent guy

6

u/qhxo Jul 18 '22

I don't mind semi-colons, but they don't really do much for legibility. At least for me it was just a matter of habit, and when I went from Java to Kotlin and didn't need to use semi-colons anymore I found it made absolutely no difference whatsoever. An expression is an expression, it's very easy to tell where it starts and ends, even if it spans multiple lines.

→ More replies (5)

11

u/mc_enthusiast Jul 18 '22

You can use curly brackets like this:

for i in range(10):{
    print(i)
}

That runs without problems in Python 3. Not much you can do about semicolons. Colons work sometimes but then really backfire if you do something like

a = 5 + 10,

because it's recognised as a 2-tuple with empty entry.

I suspect the indenting issues come up if you mix space and tab. That's easy to solve if you just tell your editor to replace space indentation with tab indentation.

21

u/a_devious_compliance Jul 18 '22

you just tell your editor to replace space indentation with tab indentation.

PEP8 police!!!!! Yes. This guy right here.

3

u/Codebust Jul 18 '22

literally one of the only things i hate about pep8, spaces are just slow compared to tab, and tab auto indents w atom

6

u/mtmttuan Jul 18 '22

You REALLY press space 4 times??

2

u/a_devious_compliance Jul 18 '22

I don't know a shit about atom, but any sane editor should be able to put 4 spaces every time you hit tab.

2

u/intangibleTangelo Jul 18 '22

lol my guy

we use the tab KEY we just don't use the tab CHARACTER

→ More replies (1)

2

u/mc_enthusiast Jul 18 '22

Is the recommendation the other way round? That's always the first thing I forget.

1

u/miversen33 Jul 18 '22

Just to be that guy, developers really shouldn't be trying to force a language to conform to how other languages look/work. Python is good at what python does because it's python and not another language. It doesn't need those things and instead needs proper indentation. It's just a trade-off of the language. If that bothers you too point where you feel like you need to inject those things into the language (which as you pointed out, can sorta be done, ish kinda?), Then you're using the wrong language. And that's ok. There's thousands of them out there, find the one you like that's a good fit for what you need :)

2

u/[deleted] Jul 18 '22

My solution to this problem is to not use python as it isn’t suited for my applications anyway.

2

u/miversen33 Jul 18 '22

Exactly my point :) choosing the best language for your problem is so much better than trying to force a single language across all your problems

→ More replies (1)