Scala has a relatively small number of built-in features that it uses to create
ID: 3579483 • Letter: S
Question
Scala has a relatively small number of built-in features that it uses to create structures
that in other languages have to be built in as well. This means that Scala is "simple" in
some sense of the word. For example, Scala does not really have for loops. Instead they are
just syntactic sugar. The loop
for (i <- 1 to 10) println(i)
is transformed by the compiler to
(1 to 10).foreach( i => println(i) )
Do you think Scala's approach is good? (In general... not just with respect to for loops.)
There is no right answer. Justify what you say in a reasonable way and you will get full
credit. Martin Odersky talks about this matter some here:
http://lamp.epfl.ch/~odersky/blogs/isscalacomplex.html
You can likely find other discussions about this online as well. Be sure to indicate any
references (URLs) you use to back up your position.
Explanation / Answer
We will comare scala for loop with java.
Java for loop:-
for(i=1;i<10;i++)
{
//
}
As you can see the java for loop is much more verbose. You need to write more to doing any simple thing. Hence, scala was creted with a view in mind to make it less verbose (do more, write less). Hence it can be justified that scala is doing it's job well, though for a beginner of Scala find it difficult to understand those syntax on the other hand it really simple to undertand java syntax but the disadvantage with java is it is much much vorbose when compared with scala. I will show a exaple below which will clear your queries further.
Let’s take a look at creating a simple list of Strings:
Java:
Scala:
Now I give a class creation example:
Java:
Scala:
So, this sums up our discussion.
Tahank you.