25 ms·
Both Powershell and Javascript are "curly-bracket" type languages. Yet semicolons are only mandatory in one. Why? (Powershell can have nightmarish encoding pro
by stephengillie 9y ago
Both Powershell and Javascript are "curly-bracket" type languages. Yet semicolons are only mandatory in one. Why?
(Powershell can have nightmarish encoding problems. "Why did my file change from UTF-8 to "UTF-16LE BOM"? Is that why Powershell can't read the file?")
- userbinator 9y agoPS is meant for interactive use, which is why using the newline to terminate statements makes sense (and then they had to introduce another separator for multiple statements on a line, along with a way to break up a statement across multiple lines.) JS is not. The amount of PS "semicolon vs newline" discussions and articles (as well as those about JS's ASI) shows the downside of this additional complexity and the confusion it causes --- contrast this with C or C-derived languages like Java, where the only statement terminator is the semicolon (and block statements end with }.) In general, you can see languages designed with interactive use as a primary goal (bash, cmd, PS, Python, ...) tend to also use a newline as a statement terminator.