• Skull giver@popplesburger.hilciferous.nl
    link
    fedilink
    arrow-up
    0
    ·
    5 months ago

    One of the nice things Kotlin did for the JVM is add a semicolonless option. Semicolons are entirely optional in 99% of code, we just use them because older languages decided to use them.

    The AST knows where a statement ends with or without a semicolon, that’s why you get those “you forgot a semicolon” errors instead of “unexpected character” errors.

    Some languages actually use semicolons. Rust does, for instance; an expression without a semicolon can be used as a return value, therefore adding value to the presence of the semicolon character. That said, with how few expressions are return values, I do wonder why semicolons are the default rather than adding a special character to indicate return values.

    I know computer programmers are deadly afraid of change, so I guess they’ll stick around at the end of every single line for years to come. In Java, semicolons are nothing but a hassle these days, though.

    • force@lemmy.world
      link
      fedilink
      arrow-up
      0
      ·
      edit-2
      5 months ago

      That said, with how few expressions are return values, I do wonder why semicolons are the default rather than adding a special character to indicate return values.

      you mean like return/break/etc.?

      because Rust was designed to remind you of functional programming despite not being very functional, and because semicolons allow way better syntax rules in Rust and are generally pretty vital for good, readable lowish-level code. it also allows Rust programmers to use newlines/indents and stuff to pretty up their code a lot without littering it with random \ and |> and begin end and such everywhere, which, given how dense Rust code can be and how much it uses iterators and weird trait magic, is a big plus for readability

      • Skull giver@popplesburger.hilciferous.nl
        link
        fedilink
        arrow-up
        0
        ·
        5 months ago

        As in yield/return, yes.

        I don’t see why you would need semicolons in any of those cases. The only languages I know that have you put a backslash at the end of the line to continue am expression are already using semicolons, while Python allows splitting expressions across lines without them.

        • force@lemmy.world
          link
          fedilink
          arrow-up
          0
          ·
          edit-2
          5 months ago

          I don’t work on any widely-used languages (I’ve made my own but not anything important) but I do think the designers of Zig and Rust have very good reasons for using semicolons – I read some reasons from the Rust devs themselves somewhere but I can’t remember them other than it vaguely being about how Rust is expression-based and intended to be lightweight and how whitespace significance can create confusion around how to read and write certain things and bla bla bla…

          but my personal opinion, what I generally I would imagine it’s for other than readability, is because the code can look a lot cleaner when an expression returned from a block is just the expression, and not expression plus some token like return. It’s especially nice in long closures or extremely short and simple blocks. I would rather consistently have to write expressions broadly like let a = { b + c }; rather than let a = { return b + c }. The semicolon has significance as a “result discarder” so expressions can be the default, so it’s on the surface a lot more functional-friendly.

          Also this is more specific but I hate the way WS languages generally handle quotes