4 ms·
Some people absolutely LOVE their semicolons. As a fan of Python, I don't really get it. But I think you would have to pry the semicolon from some people's cold
by zach_garwood 4y ago
Some people absolutely LOVE their semicolons. As a fan of Python, I don't really get it. But I think you would have to pry the semicolon from some people's cold, dead hands.
- gjsman-1000 4y agoRight - I'm only throwing the idea out there of a "modern PHP" layer that breaks some old conventions for more modern ones, but it would be opt-in and not too different, so that old code doesn't run into massive compatibility issues, and so that the "modern PHP" can be gracefully added (or not added) into any application where the developer has a different programming background, so as to allow a smoother transition.
- masklinn 4y agoTBF there are languages where the semicolon have important semantics meaning. Not needing to `\` every other line is also nice. And then there's javascript, of course, eating glue in the corner as usual.
- nobleach 4y agoHonestly this is something I love about Kotlin/Rust/Go. You either have them, or you do not. There are no time-wasting silly arguments over their veracity... just because a language makes them optional.
- nequo 4y agoIn Rust, they are not optional though. The semicolon turns an expression into an expression statement.[1] [1] https://doc.rust-lang.org/reference/statements.html https://doc.rust-lang.org/reference/statements.html
- masklinn 4y ago> The semicolon turns an expression into an expression statement.[1] And more relevant, this has the effect of suppressing the expression's value when used in tail position of a block, by moving from the second to the first branch of the block expression grammar: https://doc.rust-lang.org/reference/expressions/block-expr.html https://doc.rust-lang.org/reference/expressions/block-expr.h... Which also explains why it sometimes doesn't work e.g. in non-block match arms, because they're not blocks, and thus don't accept statements.
- nobleach 4y agoRight, that's exactly what I'm saying. They're NOT optional in any of those languages. Some of them (Kotlin and Go) don't have them, but there is no argument.
- nequo 4y agoOh, I misunderstood. I don't know Go very well but they do seem optional there: $ cat with_semicolons.go $ cat without_semicolons.go package main package main import "fmt" import "fmt" func main() { func main() { var x = 3; var x = 3 x += 1; x += 1 fmt.Printf("%d\n", x); fmt.Printf("%d\n", x) } } $ go run with_semicolons.go $ go run without_semicolons.go 4 4 $ $
- Beltalowda 4y agoGo requires every line to end in semi-colons if you look at the EBNF in the specification, but the compiler will insert them for you. It's kind of a subtle detail, but it shows up in some places, for example the following being a compile error: if true { } else { } Because the semicolon is inserted when the last character on a line is "one of the operators and punctuation ++, --, ), ], or }" (among other cases, see https://go.dev/ref/spec#Semicolons https://go.dev/ref/spec#Semicolons). So you need to use the } else { style. In practice, you can just leave of the semicolons at the end of lines (gofmt will remove them) and it's as if semicolons are not required, but if you want to get all technical about it then they are required.
- conductr 4y agoI'm a fan of both but when I started with Python, after years of PHP, it took me a minute to get the indentation and line breaks in the right places so it would execute a simple script. This may have improved but it was really hard to find where I did something wrong with format and with PHP I could easily spot a missing $ or ;. Going back to PHP, the $ and ; made things look messy at first. With either, if you stick around long enough it just becomes muscle memory and you don't even consider it overhead of writing code and your eyes adjust to the syntax. I find it a non-issue these days.
- gremlinsinc 4y agoi like using them in php and not javascript, it's almost like a switch, that tells me we're in a new context, don't write php here. Python is nice, but the whitespace can often have issues, and formatters can be wonky in vscode... It's pretty though, like rails. Still, I'm most comfortable w/ Laravel/php so will stick w/ that for time-being.