mort,
@mort@fosstodon.org avatar

I can't deal with languages with optional semicolons! I like languages without semicolons, but when they're optional, especially if they feel "C-like", I always end up adding semicolons to some lines even when I try to write in a semicolon-less style. I'm writing some now and I decided to just use semicolons consistently because the alternative is seemingly to use them inconsistently.

Strangely, this isn't an issue I have in . I do have it in however.

ekuber,
@ekuber@hachyderm.io avatar

@mort Rust doesn't have optional semicolons. Leaving a semicolon out is only valid as the last element in a block to denote it as the resulting expression for that block, but that's not the same thing as optional semicolons.

mort,
@mort@fosstodon.org avatar

@ekuber That's correct, and I would've added a caveat if I wasn't limited to 512 characters, but here we are

For a whole lot of blocks in rust (such as if statements and loops not used as expressions), it doesn't make a difference whether the block technically evaluates to something, so the last semicolon there is in practice optional, so I sometimes forget it

ekuber,
@ekuber@hachyderm.io avatar

@mort but it is mandatory in many of those cases: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=32225df0708630a138de26cfba3f4ffb

Thank you for making me double check, because made me realize there's a bug in our logic: https://github.com/rust-lang/rust/issues/124819

Crell,
@Crell@phpc.social avatar

@mort I have the same issue going from #PHP to #Kotlin. Though not having it in Rust is weird. It's a semicolon language aside from returns, no? Or is it the returns that bug you?

mort,
@mort@fosstodon.org avatar

@Crell I should've clarified but I ran out of characters :p Semicolons after the last line in a block in Rust aren't optional, they do have semantic meaning, but they are optional in practice a lot of the time. For example, it usually makes no difference whether an if statement technically evaluates to a value or not, so in effect, the last semicolon in the body of an if statement is usually optional.

Crell,
@Crell@phpc.social avatar

@mort Ah, now I follow. Yeah, that's been awkward for me the few times I've touched Rust, too.

  • All
  • Subscribed
  • Moderated
  • Favorites
  • Kotlin
  • GTA5RPClips
  • DreamBathrooms
  • InstantRegret
  • magazineikmin
  • thenastyranch
  • ngwrru68w68
  • Youngstown
  • everett
  • slotface
  • rosin
  • ethstaker
  • Durango
  • kavyap
  • cubers
  • provamag3
  • modclub
  • mdbf
  • khanakhh
  • vwfavf
  • osvaldo12
  • cisconetworking
  • tester
  • Leos
  • tacticalgear
  • anitta
  • normalnudes
  • megavids
  • JUstTest
  • All magazines