Scala:
1. For comprehensions can be much slower than while, if the content of the loop is fast:
Code:
for (i <- 1 to 1000000) doSomethingFastAndSimple
is much slower than:
Code:
var i = 0
while (i < 1000000) i++; doSomethingFastAndSimple
2. The distiction between a lambda expression taking n parameters and lambda taking one parameter of tuple type with n values is somewhat funny:
Code:
val hashMap = Map("abc" -> "def", "xyz" -> "lkj")
hashMap.foreach {case (key, value) =>
println("Key is: " + key + " value is: " + value) }
Code:
val list = List(9,34,345,5,7,21,49)
list.sort((a, b) => a < b)
3. Implicit conversions can be tricky. But unfortunately no other language has anything as powerful as Scala's implicit conversions, so the complexity here is justified.
Code:
object SafeEquals {
trait Related[T, U]
implicit def related[T, U <: T]: Related[T, U] = null
class Equals[A](o: A) {
def ===[B](other: B)(implicit related: Related[A, B]) = o == other
def !==[B](other: B)(implicit related: Related[A, B]) = o != other
}
implicit def anyToEquals[A](o: A) = new Equals[A](o)
}
BTW: The criticism of Java BigIntegers is not valid. Immutable objects are your friend. They are not necessarily slower than the mutable ones. You save only on making a copy of the object, wich is cheap compared to the actual calculation. The problem with BigIntegers is that the syntax sucks. Operator overloading as in Scala would be nice.
Bookmarks
Algorithms and Data Structures
Java tutorials
Algorithms Forum