3 ms·
I used to be a huge Python fan until I found Scala. It can be as expressive as Python (slightly more so even), but as safe as Java (again, slightly more so).
by lmm 10y ago
I used to be a huge Python fan until I found Scala. It can be as expressive as Python (slightly more so even), but as safe as Java (again, slightly more so).
- willtim 10y agoUnfortunately Java is far from safe, NullPointerException and ClassCastException abound. Which isn't surprising given that Java was originally inspired by ObjectiveC, a mostly dynamic language. Scala has a sort of ML subset which mostly avoids these errors, but unless you need the JVM, why not try OCaml or Haskell?
- jdmichal 10y agoDefault-nullable types and thereby having to check for null in every non-primitive argument is definitely a thing in Java, but I don't think I've seen a ClassCastException in the wild for a very long time... Generics pretty much solved the problems that led to bad casts, such as a integer sneaking into your list of strings.
- willtim 10y agoYes true, Generics helped a lot (thanks to Odersky and Wadler). But the language does seem to encourage more dynamic frameworks like Spring, that IIRC do perform a lot of casting.
- lmm 10y agoThere are some Java libraries based on reflection, sure, including Spring. They're not widely used from Scala.
- nradov 10y agoNullPointerException can usually be prevented by using FindBugs annotations. This is a work around for a fundamental design flaw in the Java language, but I find it's pretty effective. http://findbugs.sourceforge.net/manual/annotations.html http://findbugs.sourceforge.net/manual/annotations.html
- lmm 10y agoI agree that those are good languages - my reasons for using Scala rather than OCaml or Haskell are mostly boring practical ones (interop with Java, employment, tooling). That said I do think higher-kinded types are very valuable (which rules out OCaml until they finish the modular implicits feature), and that eager evaluation is very useful if there's a chance performance might become important at some point.