No Semicolons Needed

(terts.dev)

24 points | by karakoram 3 hours ago

10 comments

  • Animats 57 minutes ago
    Classic mistakes in language design that have to be fixed later.

    - "We don't need any attributes", like "const" or "mut". This eventually gets retrofitted, as it was to C, but by then there is too much code without attributes in use. Defaulting to the less restrictive option gives trouble for decades.

    - "We don't need a Boolean type". Just use integers. This tends to give trouble if the language has either implicit conversion or type inference. Also, people write "|" instead of "||", and it almost works. C and Python both retrofitted "bool". When the retrofit comes, you find that programs have "True", "true", and "TRUE", all user-defined.

    Then there's the whole area around Null, Nil, nil, and Option. Does NULL == NULL? It doesn't in SQL.

  • librasteve 46 minutes ago
    This article makes a strong case for every language to use ‘;’ as a statement separator.
  • bmandale 43 minutes ago
    > I would love to see a language try to implement a rule where only an indented line is considered part of the previous expression.

    After python, it seems like every language decided that making parsing depend on indents was a bad idea. A shame, because humans pretty much only go by indents. An example I've frequently run into is where I forget a closing curly brace. The error is reported at the end of the file, and gives me no advice on where to go looking for the typo. The location should be obvious, as it's at exactly the point where the indentation stops matching the braces. But the parser doesn't look at indents at all, so it can't tell me that.

    • kayson 34 minutes ago
      I was much more opposed to this early on than I am now. With modern IDEs and extensions handling tabs vs spaces, tab width, and formatting, python ends up being very easy to read and write. I use it daily, and while I hate it for other reasons, I can't remember the last time I had any issues with indentation.
    • vips7L 38 minutes ago
      Scala 3 decided to go with indents.
    • stinkbeetle 29 minutes ago
      > An example I've frequently run into is where I forget a closing curly brace. The error is reported at the end of the file, and gives me no advice on where to go looking for the typo. The location should be obvious, as it's at exactly the point where the indentation stops matching the braces. But the parser doesn't look at indents at all, so it can't tell me that.

      That's somewhat a quality of service issue though. Compilers should look at where the braces go out of kilter vs indentation and suggest the possible unmatched opening brace.

  • sheept 55 minutes ago
    > I would love to see a language try to implement a rule where only an indented line is considered part of the previous expression.

    Elm does this (so maybe Haskell too). For example

        x = "hello "
         ++ "world"
    
        y = "hello "
        ++ "world" -- problem
  • kayson 33 minutes ago
    Are we really saving that much by not having semicolons? IDEs could probably autocomplete this with high success, and it removes ambiguity from weird edge cases. On the other hand, I've not once had to think about where go is putting semicolons...
  • sheept 49 minutes ago
    Because formatters are increasingly popular, I think it'd be interesting to see a language that refuses to compile if the code is improperly formatted, and ships with a more tolerant formatter whose behavior can change from version to version. This way, the language can worry less about backwards compatibility or syntax edge cases, at the cost of taking away flexibility from its users.
  • marcosdumay 1 hour ago
    Looks at 11 languages, ignores Haskell or anything really different...
  • gethly 5 minutes ago
    garbage
  • gcanyon 1 hour ago
    Can anyone give a good reason why supporting syntax like:

        y = 2 * x
          - 3
    
    is worth it?
    • whateveracct 1 hour ago
      in Haskell, supporting that is how you get neat composition

      such as applicative style formatted like this:

              f
          <$> x
          <*> y
          <*> z
    • marcosdumay 57 minutes ago
      By "is worth it" you mean it's worth the work?

      Because it's very little extra work.

      If you want to know if it's a good syntax, AFAIK it's the only way to do a semicolon-less language that doesn't break all the time.

    • zephen 39 minutes ago
      Obviously, that's a really short expression.

      So, the question is, if you have a long expression, should you have to worry too much about either adding parentheses, or making sure that your line break occurs inside a pair of parentheses.

      It boils down to preference, but a language feature that supports whatever preference you have might be nice.

        priority = "URGENT"  if hours < 2  else
                   "HIGH"    if hours < 24 else
                   "MEDIUM"  if hours < 72 else
                   "LOW"
    • justsomehnguy 51 minutes ago
      Mostly eye-candy, especially for some long one-liners.

      In PowerShell you can do that by explicitly instructing what the next line is actually a continuation of the previous one:

          $y = 2 * $x `
             - 3
    • szmarczak 1 hour ago
      It's not. Your eyes can deceive you by guessing the correct indentation. Indentation should never be used for grammar separation. Explicit characters such as } ] ) are clearer and unambiguous.
      • bmandale 41 minutes ago
        Clearer for the computer, but not for the human. Many errors, some severe, have been caused by a human only looking at the indentation and not realizing the braces don't match.
        • szmarczak 29 minutes ago
          > human only looking at the indentation and not realizing the braces don't match.

          If it ever gets to that point, a refactor is obligatory.

          Don't give the human tools to make easy mistakes. Any grammar can be abused, so blame the human for not writing clean code.

  • IshKebab 40 minutes ago
    > how does Gleam determine that the expression continues on the second line?

    The fact that it isn't obvious means the syntax is bad. Stuff this basic shouldn't be ambiguous.

    > Go's lexer inserts a semicolon after the following tokens if they appear just before a newline ... [non-trivial list] ... Simple enough!

    Again I beg to differ. Fundamentally it's just really difficult to make a rule that is actually simple, and lets you write code that you'd expect to work.

    I think the author's indentation idea is fairly reasonable, though I think indentation sensitivity is pretty error-prone.