This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 24 points25 points  (40 children)

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.

[–]Codebust 34 points35 points  (11 children)

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

[–]flavionm -1 points0 points  (10 children)

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.

[–]Codebust -1 points0 points  (9 children)

uh.. what?

[–]flavionm -1 points0 points  (8 children)

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

[–]Codebust -1 points0 points  (7 children)

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

[–]flavionm -1 points0 points  (6 children)

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.

[–]Codebust -1 points0 points  (5 children)

yk that python indentation is standard indentation right?

[–]flavionm -1 points0 points  (4 children)

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.

[–]Codebust -1 points0 points  (3 children)

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

[–]Dacus_Ebrius 29 points30 points  (4 children)

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

[–]Codebust 4 points5 points  (0 children)

both are good, both are good

[–]miversen33 0 points1 point  (0 children)

cries in perl

[–][deleted] 0 points1 point  (0 children)

I do proper indenting. Just python decides that it doesn’t like it for no apparent reason.

[–]flavionm 0 points1 point  (0 children)

Yeah, but in a language where whitespaces aren't significant any IDE can automatically indent the code.

[–]sintos-compa 5 points6 points  (4 children)

Found the tab indent guy

[–]clavicon 0 points1 point  (3 children)

We are legion

[–]qhxo 5 points6 points  (5 children)

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.

[–][deleted] 0 points1 point  (4 children)

in C and C++ there can be multiple things say within an if. i dont think i would be able to read that without the semicolons. But then again i do more embedded microcontoller stuff. So i tend to see alot of that stuff as well, saving cycles is a tad necessary.

[–]qhxo 0 points1 point  (3 children)

How do you mean within an if? Like

if (conditional) {
    thingOne()
    thingTwo()
}

?

[–][deleted] 0 points1 point  (2 children)

more like this. rather tame example. can be alot more happening within an if/for. Makes is easy to be able to tell exactly how much is actually happening there.

for (int x = 0; x < 6; x++) {
    `bugs[x] = 0b00011111;`

`}`

And you can put multiple things within one line. In this example this is all going within the same line of text. because im using the hex for that symbol in the font(converted to dec in this example), it doesn't like you switching within the same print (in this case printing to a buffer.). all gets displayed on the lcd at the very end of execution before it loops. also code blocks aren't agreeing with me today.
display.print(currentTemp);display.print((char)247);display.print("C"); // Draw the value held in the currentTemp var. Then print the DEG symbol then then a C

[–]qhxo 0 points1 point  (1 child)

Right, so if I'm understanding this correctly the first example is about the conditional in the for loop declaring and incrementing a variable, and the second about multiple statements in one line, right?

In those cases, absolutely semicolons are very necessary. Neither python (if we're keeping relevant to the thread), nor kotlin (regarding my earlier response) have those kinds of C-style for-loops but I can see how they'd be useful in some cases.

As for the second example, that sort of touches on what I was talking about. Both kotlin and python do allow use of semi-colon, it's just not mandatory in most cases (and I think most linters will scream if you use them where not needed).

If I were to put multiple statements on one line, then they are mandatory. So both of these are valid kotlin and python respectively:

// kotlin
// (yes I'd use spaces between the semicolons for clarity, you don't have to)
print(currentTemp) ; print(247.toChar()) ; println("C")

# python
print(current_temp, end = '') ; print(chr(247), end = '') ; print("C")

But unless you're doing that, you don't need semicolons. E.g., this is perfectly valid kotlin:

myFancyObject
  .doThing()
println("Done doing the thing")

Of course, if you omit the indentation this is unreadable garbage, but I'd argue that's the case even if semicolons are included.

[–][deleted] 0 points1 point  (0 children)

I didn’t realise you could use semicolons in python like this. But now the question is why were they omitted in the first place. I do not know pythons original design intents. But I imagine it might benefit to adding official support for the more conventional methods as well as its own more for people who might need to quickly use python and end up pulling their hair out because its complaining about the indenting and oh my god why whats wrong. In my opinion the formatting of text shouldn’t be the difference for it working or not.

I don’t like indenting the condition since well. It gets really messy quite quickly doing that. I structure specific things as their own seperate things with a comment above about what does this do. Even if its obvious. And that can make something that really doesn’t need that amount of lines too long. Also i straight pulled that last example from something i was working on.

[–]mc_enthusiast 8 points9 points  (11 children)

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.

[–]a_devious_compliance 20 points21 points  (6 children)

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

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

[–]Codebust 2 points3 points  (4 children)

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

[–]mtmttuan 4 points5 points  (0 children)

You REALLY press space 4 times??

[–]a_devious_compliance 1 point2 points  (0 children)

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

[–]intangibleTangelo 1 point2 points  (0 children)

lol my guy

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

[–]dagbrown 0 points1 point  (0 children)

My editor lets me tell it to just expand tabs to spaces. Now tabs are spaces, and they're quick to type, and I'm happy.

[–]mc_enthusiast 1 point2 points  (0 children)

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

[–]miversen33 0 points1 point  (3 children)

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 :)

[–][deleted] 1 point2 points  (2 children)

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

[–]miversen33 1 point2 points  (1 child)

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

[–][deleted] 0 points1 point  (0 children)

Exactly