Keep in mind, though, guys, the more complex the syntax becomes, the harder it’s going to be for newbies to get into the language. That’s one of the problems of learning scala.
Here are a couple of different ways of printing out each String in an array:
val strings = "this is a string with different things in it".split(" ")
// Way 1:
for (str <- strings) Console.print(str)
// Way 2:
strings.foreach { str => Console.print(str) }
// Way 3:
strings.foreach((str) => {
Console.print(str);
})
// Way 4:
strings.foreach((str) => Console.print(str))
// Way 5:
strings.foreach(Console.print(_))
// Way 6:
strings.foreach(Console.print)
Scala’s syntax is rich, that’s a plus on the one hand and a minus on the other.
It makes it harder to learn and sometimes you wonder even as experienced programmer why some syntax doesn’t work.
Personally, I’m all for a concise simple syntax, which is extensible. Lisp and it’s dialects are incredibly good at that. Concise, simple and very extensible. It shows the perfect combination of minimalism and extensibility
There is a talk “Growing a Language” by a genious “Guy Steele”, who worked a lot with Lisp-languages and helped with designing a lot of languages, one of them being java. I really strongly recommend watching it completely