I'm new in the scala programming, so i'm seeing some basic programs.
I noticed that the instructions end with ;
character in some case, while in other case they end without any character.
What is the difference?
I'm new in the scala programming, so i'm seeing some basic programs.
I noticed that the instructions end with ;
character in some case, while in other case they end without any character.
What is the difference?
None, really. Scala allows you to explicitly insert semicolons but it's not mandatory and they are inserted for you.
From my experience, the overwhelming majority of Scala developers tend to prefer not using semicolons explicitly.
The only case in which I've seen semicolons used is when you have multiple expressions in a for
-comprehension and you don't want to necessarily break those apart over multiple lines, in which case you would turn something like this:
for {
a <- 1 to 10
b <- 1 to 10
} yield a * b
into
for (a <- 1 to 10; b <- 1 to 10) yield a * b
But then again, some prefer to always break those kind of expressions over multiple lines anyway for consistency, which is why scalafmt
(a Scala code formatter) has a rule precisely for that.