102 points · by mynegation · 13y ago · 63 comments
Scala requires much more work to learn than Go. I don't think I ever ventured out much from the offical Go documentation, the spec and effective Go and the library documentation to learn Go. With Scala I've already bought 3 books, and have bookmarked nearly 100 sites. I frequently have very many tabs opened with various scaladocs, examples and stackoverflow questions open.
My favorite thing in Scala is Akka. I quite like Akka and I like the functional programming that's possible with Scala. The build tools, like sbt require getting used to but I'm able to pretty much get along just fine without an IDE. I do have intellij open but I hardly look at it. I do all coding in vim and testing with sbt.
About 14 days in and I can connect to TCP and parse JSON ok. That's where I'm at. There have been some pretty frustrating moments, mostly dealing with 3rd party libraries (like scalaz, not documented much) and sbt, but once overcome it feels rewarding.
My other favorite things in scala: it has a REPL, s"String $interpolation" and pattern matching.
I've also written a blog post about learning resources. Maybe it helps you: https://www.bionicspirit.com/blog/2013/05/13/getting-started...
As a word of warning, don't use Scalaz while in the learning process. It's a pretty cool library, but I've been developing with Scala for the past 2 years already and personally I've never felt the need for Scalaz.
Akka is great, the standard library is great, Play is great. You can also use any Java library you want and wrapping Java libraries in Scala-ish interfaces is great for learning ;-)
> Scala requires much more work to learn than Go.
This is true. Go is more familiar because it has a less complicated (and unfinished) type system and because it doesn't contain too many unfamiliar concepts to developers that are used to mainstream languages.
For example in Scala you end up seeing a lot of flatMaps() being used on monads, you also see type-classes or persistent/immutable data-structures, or the CanBuildFrom pattern which looks intimidating at first, but it's actually rather nice. Scala's type system is also much more static and more expressive than that of Java, Go or C# and I'm specifically talking about generics. Scala makes it easier to write statically type-safe generic code, so of course, people end up wanting more and some of them go crazy with that.
Being a static functional programming language, the type system is intimidating at first, but as you learn about it, you'll see that it's elegant and much thought went into designing it. And most importantly, it helps you to write better code, instead of just staying in your way.
Scala also contains simplifications versus other mainstream languages. In comparison with C# or Java, in Scala there is no such thing as static methods or members. In fact, in Scala all member accesses are considered method calls. This has great implications for polymorphism. In comparison with other languages that mixed OOP and FP (e.g. F#, Ocaml), in Scala all types are modelled by means of classes or traits. While using other languages, you'll notice that OOP (sub-typing) is a pain in combination with generics because covariance/contravariance is a bitch to deal with. Java's generics are broken, because at the class level they simply don't deal with it (they preferred invariance) and then for the methods themselves you've got to use wildcards. Scala is much saner in that regard. It also has a unified access philosophy that really simplifies things and the marriage that it achieves between OOP and FP is really good. In my opinion, only Clojure's protocols are on the same level while being somewhat simpler, but that goes with the territory of a dynamic language.
Anyway, Scala's learning curve may seem intimidating, but (1) it's worth it because you learn a lot about FP with Scala (the ML style, not the LISP style, which is slightly different :)) and (2) you don't need to use advanced concepts to write working code.
Have fun,
I guess that you can achieve the same benefits with an always-open SBT console.
I usually do
~ test
So SBT will recompile and launch test after every :w in VIM(Advice for understanding scalaz: look at the type signatures. Try and implement a function with that type signature yourself. In fact, the first few times I find it's best to write the thing without using scalaz myself, then notice that part of it has a type signature that matches a method in scalaz, and then replace that with the scalaz method.)
Although I like Haskell and FP, this is one of the reasons that I have been very hesitant using Scala in my previous or current position, although both were Java/JVM-heavy. Using Scala has the implication that some of my colleagues have to learn it as well, and learning FP and Scala well can be a multi-month or multi-year project.
With a language such as Kotlin, one can scrap much of the Java boilerplate, while most of it is very easy to pick up for a Java programmer in a few days or weeks.
That said, Typesafe are doing great work! I use and love Akka and it works great in Java as well (if you don't need to compose futures to much :^)).
A very short summary of my impressions from Scala: * It is beautiful, I felt the half-forgotten beauty of functional programming once again
* Scala worksheets (quick scratch to evaluate whole code snippets with immediate feedback) are awesome. I love them even more than REPL (Then again, I love IPython notebook more than Python REPL too)
* Scala seems a bit heavy in terms of number of concepts
* Scala can be terse and very expressive, but pretty verbose if you need it to be
* Compilation of large programs is slow and eats gobs of memory
* tail-call optimize everything
* (Mostly) Python-ic syntax (indentation-based)
* Type inferance
* OOP (but only when you want it)
* Good expressivity
* Compiles via c (FAST, easy linking with C libs, no runtime required, prodoces standalone binaries)
* Lean core (Not a "kitchen sink" language, but has good support for FP and OOP)
The close compatibility with Java does allow an easy transition for Java developers, but it's a transition to writing what it repeatedly deemed unidiomatic Scala by the Scala community. And then I've seen the same community scoff at unenlightened Scala developers that are writing "Java++".
Half of Scala could make a really nice language, but the complexity of the full thing is not something I want to work with again.
Scala is not Haskell and Haskell is not Scala. If you use one and expect the other, you'll be disappointed.
That School (Aalto University) has used Java as a first year language for quite some time. Then they switched to Python (I think), and then to Scala. Before Java, it was Scheme. Before Scheme, I don't know.
I'm not sure why they're trying to scare the poor first years away.
I think the OP really nails the reasons Scala makes sense as an intro language. Students can start with simple concepts and gradually see how these lead to the complicated stuff.
scala> print("5" + 5)
55
And I stopped there (for now). At least my C++ compiler will warn about that (although it will still compile even if it doesn't print anything save for the newline): #include <iostream>
using namespace std;
int main(int argc, char *argv[]) {
cout << "5" + 5 << endl;
return 0;
}
Python gives me a TypeError. And so does Common Lisp. I was expecting the same from Scala; a language which purports to be a multi-paradigm language with static type inference and a strong functional programming bias. Not even a warning.What's the reasoning behind this in Scala?
scala> "5" + 5
res0: java.lang.String = 55
Don't use print in the REPL...> Python gives me a TypeError. And so does Common Lisp. I was expecting the same from Scala
scala> val i:Int = "5" + 5
<console>:7: error: type mismatch;
found : java.lang.String
required: Int
val i:Int = "5" + 5
^
You can easily get a compiler error, if you enforce the type. The inheritance of Javas "I'll call .toString on anything" is definitely not something I'll defend, but it's much less of a problem than it may appear. To do anything interesting with that "fake" integer, you'll have to call a method that only accepts integers - and the compiler will throw an error then. E.g.: scala> math.max("5" + 5, 5)
<console>:8: error: overloaded method value max with alternatives:
(x: Double,y: Double)Double <and>
(x: Float,y: Float)Float <and>
(x: Long,y: Long)Long <and>
(x: Int,y: Int)Int
cannot be applied to (java.lang.String, Int)
math.max("5" + 5, 5)
^The C++ behavior is notably worse, though: "5" + 5 in C++ is undefined behavior, and will give you a pointer to some mystery data.
I only meant to illustrate that even in C++ where types have a different meaning I will get a warning with a decent compiler.
In either case the expression in both languages garners a silly result. However Scala is happy with the result and reports nothing wrong with it (not even a warning). I was just surprised is all.
So you invoked print("5".+(5))
What else would you expect. The nice thing about Scala is that you can leave out some of the extra syntax that is not needed for the compiler to decode the meaning.
Now as for why the String class has a + method to do string concatenation? I don't know but this is far from the first language that I have come across that conflates string concatentation with numeric addition. Maybe it comes from the Java libraries? In any case, it is not really a problem to most people because we follow the maxim, if it hurts, DON'T DO THAT!
scala> 5 + "5"
res0: String = 55And I don't want a warning, I want a huge fatal end-of-the-world big red flag error message blinking on my screen until I fix it.
I mean, I'm so used to work in Java which has the same behaviour, so I may have been totally unable to see the problem due to the familiarity of that code, maybe, but I still don't understand the problem.
First, let state the basis: the meaning of the + operator is overloaded. For numeral types, it makes the sum of the operands. For string, it concatenates them. These are two different meanings in different context.
For the numeral types, it will not protest if you sum up a float with an int (and I think most programming languages won't either). The rules of the language are quite clear: the int would be coerced to a float, then the two float be added, and a float will contain the result.
For the string operation, you could force the operands to have all the same types, but you could also practice the same kind of coercion: convert everything (yes, it works for every object of any sort) to a string, then concatenate.
OK, it may be odd mathematically, but let's see it for what it is: a very handy syntactic sugar in the form of an overloading of the meaning of +, which obey simple rules, and thus have no potential to mean something else than what the programmer meant.
scala> println("5" + 5 + 5)
555 scala> val pi = "pie!"
pi: String = pie!
scala> println(f"Care for some $pi%f?")
<console>:9: error: type mismatch;
found : String
required: Double
println(f"Care for some $pi%f?")
^
scala> val pi = Math.PI
pi: Double = 3.141592653589793
scala> println(f"Care for some $pi%f?")
Care for some 3.141593?
ps:- http://docs.scala-lang.org/overviews/core/string-interpolati...
- read: https://github.com/adriaanm/talks/blob/master/scala-2.10/sli...
psedit: I can't resist one of my favorite f# article http://blogs.msdn.com/b/ashleyf/archive/2012/01/26/hp-35-mic...
also, arrayForth chip emulator : http://blogs.msdn.com/b/ashleyf/archive/2013/09/21/chuck-moo...
I use typesafe stack and it's really, really good.
Scala is fundamentally a pragmatic language - it is about compromise between functional purity and JVM/Java-style (OOP-based) mutation. As such, it's hard to really identify the distinctive features of either because Scala is so liberal in what it allows.
I wonder whether students would be better off learning something like Haskell along with (e.g.) Python or Java. And of course a Lisp of some kind(!).