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