Live data from Hacker News

No Semicolons Needed

terts.dev

51–60 of 92 posts

Re: No Semicolons Needed

#51
post #41

I never actually type semicolons in my JavaScript / TypeScript. In work projects, my IDE adds them for me thanks to the linter. In personal projects, I just leave them out (I don't use a linter, so my IDE does not add them), and I've never had a problem. Not even once. Semicolon FUD is for the birds.

I occasionally run into problems with JS weird parsing rules. My favorite is: return x Which does not return. It returns undefined. Typescript helps a lot with that. A linter will probably flag it as well. Still, JS went way out of its way to accept just about anything, whether it makes sense or not.

That is what I lament too. So I've started to use the comma-operator to make sure my return statements don't care about line-breaks. I often write:

return 0,

x;

I find this a mildly amusing discovery for myself because it took me a long time to figure out a useful use for the comma-operator.

Re: No Semicolons Needed

#52

> 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…

we don't even use indents that way in natural language. We use things like bullet points, we need specific markers.

space is for spacing, tabs are for tabulation, they are not in any human language I know of used as terminators of statements. You know what is the equivalent of an indent or a semicolon in english? a period. We have paragraph breaks just like this to delimit blocks of english statements.

A semi-colon is used to indicate part of a sentence is done, yet there is still related continuation of the statement that is yet to be finished. Periods are confusing because they're used in decimal points and other language syntax, so a semi-colon seems like a good fit.

If I had my pick, I would use a colon to indicate the end of a statement, and a double colon '::' to indicate the end of a block.

func main(): int i - 0: do: i=i+1: print(i): while(ianother downside of indentation is it's award to do one-liners with such languages, as with python.

There is a lot of subjectivity with syntax, but python code for example with indents is not easy for humans to read, or for syntax validators to validate. it is very easy for example to intend a statement inside a for loop or an if/else block in python (nor not-intend it), and when pasting around code you accidentally indent one level off without meaning to. if you know to look for it, you'll catch it, but it's very easy to miss, since the mis-indented statement is valid and sensible on its own, nothing will flag it as unusual.

In my opinion, while the spirit behind indentation is excellent, the right execution is in the style of 'go fmt' with Go, where indenting your code for you after it has been properly parsed by the compiler/interpreter is the norm.

I would even say the first thing a compiler as well as interpreter do should be to auto-indent, and line-wrap your code. that should be part of the language standard. If the compiler can't indent your code without messing up logic or without making it unreadable, then either your code or the language design has flaw.

Re: No Semicolons Needed

#53
post #18

> 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…

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.

I must disagree but only a tiny bit. modern IDEs try to indent and attempt to add indentation as you code which can cause problems sometimes.

tabs vs spaces is very painful still when copying code that is in a different format. it's not just tabs and spaces, but the width of the tabs and the spaces. Even with VSCode extensions and sublime text extensions I've struggled a lot recently with this.

I commented on a sibling thread just now, but it is still very easy in python to mess up one level of indentation. When I caught bugs of that sort, it was introduced either when copy pasting, when trying to make a linter happy and doing cosmetic cleanup, or when moving code around levels of indentation, like introducing a try/except. I had one recently where if I recall correctly I moved a continue statement under or out of a try/except when messing around with the try/except logic. it was perfectly valid, and didn't stand out much visually, pydnatic and other checkers didn't catch it either. It could have happened with a '}' but it's easier to mess up a level of indentation than it is to put the '}' at the wrong level. a cosmetic fix results in a logic bug because of indentations in python. with curly's, a misplacement of that sort can't happen because of indentation or cosmetic/readability fixes.

what the curly approach asserts is a separation of readability and logic syntax.

The interpreter/compiler should understand your code first and foremost, indenting code should be done, and should be enforced, but automatically by the compiler/interpreter. Python could have used curly braces and semi-colons, and force-indented your code every time it ran it to make it more readable for humans.

Re: No Semicolons Needed

#54
post #43

This article makes a strong case for every language to use ‘;’ as a statement separator.

Exactly. I genuinely do not understand how any significant user of python can handle white space delimitation. You cannot copy or paste anything without busywork, your IDE or formatter dare not help you till you resolve the ambiguity. One day https://github.com/mathialo/bython one day!

looks cool..

Alternatively, I've several times used 'pass' as block terminator for my personal code.

Re: No Semicolons Needed

#55
post #2

Can anyone give a good reason why supporting syntax like: y = 2 * x - 3 is worth it?

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.

IMO, that is the only acceptable situation where semicolons can be removed from the language... if you need to add indentation rules, you've failed.

Re: No Semicolons Needed

#56
It's very subjective, and I don't want to say that semicolons are good or bad, indentation is good or bad, etc.

But I think a language should decide whether white space is significant or not. If it's not, don't add exceptions!

Operators changing meaning when surrounded by spaces in otherwise context-free languages are an abomination!

Re: No Semicolons Needed

#57

Perhaps having unary minus (and especially unary plus ) is just a bad idea in general; just mandate "0 - expr". To make negative constants work properly, you still have to either special case literals "256", "65536", etc. and ideally check whether they got negated or not, or introduce a special syntax just for them, like "~1" of ML for negative one, or "-1" (which you are not allowed to break with whitespace) of some…

+1 on the convenience of a "mask" operator that perform the and-not. It's an operation that's used more often than others which do have the privilege of having their own symbol, like xor.

Re: No Semicolons Needed

#58

> 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…

we don't even use indents that way in natural language. We use things like bullet points, we need specific markers. space is for spacing, tabs are for tabulation, they are not in any human language I know of used as terminators of statements. You know what is the equivalent of an indent or a semicolon in english? a period. We have paragraph breaks just like this to delimit blocks of english statements. A semi-colon i…

> we don't even use indents that way in natural language.

Have you never seen a nested table of contents?

  1. Introduction
  2. Fruit
    2.1 Apples
      2.1.1 Red apples
      2.1.2 Green apples
    2.2 Oranges
  3. Vegetables
    3.1 Carrots

Re: No Semicolons Needed

#59

Perhaps having unary minus (and especially unary plus ) is just a bad idea in general; just mandate "0 - expr". To make negative constants work properly, you still have to either special case literals "256", "65536", etc. and ideally check whether they got negated or not, or introduce a special syntax just for them, like "~1" of ML for negative one, or "-1" (which you are not allowed to break with whitespace) of some…

> Also, a small prize (a "thank you!" from a stranger on the Internet i.e. me) to someone who can propose a good syntax for compound assignment with reversed subtraction:

I would do away with operator-assign operators and instead introduce a general syntax for updating a variable that can be used with any expression.

  x = _ + 1  # increment x
  x = 0 - _  # negate x
  output = sanitizeHtml(_)
  index = (_ + 1) % len(arr)

Re: No Semicolons Needed

#60
post #43

This article makes a strong case for every language to use ‘;’ as a statement separator.

Exactly. I genuinely do not understand how any significant user of python can handle white space delimitation. You cannot copy or paste anything without busywork, your IDE or formatter dare not help you till you resolve the ambiguity. One day https://github.com/mathialo/bython one day!

> You cannot copy or paste anything without busywork

Sounds like a tool issue. My editor (Neovim with a few plugins) can handle copying/pasting with indentation just fine.

Post reply on HN