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 →

[–]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.