views:

538

answers:

5

I have recently been looking around to learn a new language during my spare time and Scala seems to be very attractive.

I have a few questions regarding it:

  1. Will not knowing Java impose a challange in learning it? Will it be a big disadvantage later on? ( i.e How often do people rely on Java-specific libraries? )

  2. How big of a difference it is compared to Ruby? (Apart from being statically typed) Does it introduce a lot of new terms, or will I be familiar with most of the language's mechanisms?

  3. What resources would you recommend? I have my eye on Programming Scala and Beginning Scala books

  4. Although subjective, is Scala fun to programme in? : P

Thanks

+5  A: 

I do not have a Ruby background but nevertheless, I might be able to help you out.

  1. I don't thing not knowing Java is a disadvantage, but it might help. In my opinion, Java libraries are used relatively often, but even a trained Java coder don't know them all, so no disadvantage here. You will learn some parts of the Java library by learning Scala because even the Scala libraries use them.

  2. --

  3. I started out by reading Programming Scala and turned over to read the source of the Scala library. The latter helped a lot to understand the language. And as always: Code, Code, Code. Reading without coding wont get you anywhere, but I'm sure you know that already. :-) Another helpful resources are blogs, see http://stackoverflow.com/questions/1445003/what-scala-blogs-do-you-regularly-follow for a compilation of good Scala blogs.

  4. It is! As you stated, this is very subjective. But for me, coming from a Java background, It is a lot of fun.

Malax
+1  A: 

Re. point 1. Not being familiar with Java the language is not necessarily a problem. 3rd party libraries integrate largely seamlessly into Scala. However some awareness of the differences in collections may be good (e.g. a Scala list is not a traditional Java list, and APIs may expect the latter).

The Java-related skills that carry over are related to Java the platform. i.e. you're still working with a JVM that performs class-loading, garbage collection, JIT compilation etc. So experience in this is useful. But not at all necessary.

Note that Scala 2.8 is imminent, and there are some incompatible changes wrt. 2.7. So any book etc. you buy should be aware of such differences.

Brian Agnew
+20  A: 

There are many concepts that are shared between Ruby and Scala. It's been a while since I've coded Ruby, so this isn't exhaustive.

Ruby <==> Scala (Approximately!)

  • Mixins <==> Traits
  • Monkey Patching <==> Pimp My Library (Implicit Conversions to a wrapper with extra methods)
  • Proc/Closure <==> Function/Function Literal
  • Duck Typing <==> Structural Types
  • Last Argument as a Proc <==> Curried Parameter List (see Traversable#flatMap)
  • Enumerable <==> Traversable
  • collect <==> map
  • inject <==> foldLeft/foldRight
  • Symbol.toProc <==> Placeholder syntactic sugar: people.map(_.name)
  • Dynamic Typing conciseness <==> Type Inference
  • Nil <==> null, although Option is preferable. (Not Nil, which is an empty list!)
  • Everything is an expression <==> ditto
  • symbols/hashes as arguments <==> Named and Default Parameters
  • Singleton <==> object Foo {}
  • Everthing is an object <==> Everthing is a type or an object (including functions)
  • No Primitives <==> Unified type system, Any is supertype for primitives and objects.
  • Everything is a message <==> Operators are just method calls

Ruby's Features you might miss

  • method_missing
  • define_method etc

Scala Features you should learn

  • Pattern Matching
  • Immutable Classes, in particular Case Classes
  • Implicit Views and Implicit Parameters
  • Types, Types, and more Types: Generics, Variance, Abstract Type Members
  • Unification of Objects and Functions, special meaning of apply and update methods.
retronym
Regular expression: /Cats(.*)/ <==> "Cats(.*)".r
Thomas Jung
+11  A: 

Here is my take on it:

  • Never mind not knowing Java.

  • Scala relies a lot on Java libraries. That doesn't matter at all. You might have trouble reading some examples, sure, but not enough to be a hindrance. With little time, you won't even notice the difference between reading a Java API doc and a Scala API doc (well, except for the completely different style of the newest scaladoc).

    Familiarity with the JVM environment, however, is often assumed. If I can make one advise here, it is to avoid Maven at first, and use SBT as a build tool. It will be unnecessary for small programs, but it will make much of the kinks in the Java-lang world easier to deal with. As soon as you want an external library, get to know SBT. With it, you won't have to deal with any XML: you write your build rules in Scala itself.

  • You may find it hard to get the type concepts and terms. Scala not only is statically typed, but it has one of the most powerful type systems on non-academic languages out there. I'm betting this will be the source of most difficulty for you. Other concepts have different terminology, but you'll quickly draw parallels with Ruby.

    This is not that big of a hurdle, though -- you can overcome it if you want to. The major downside is that you'll probably feel any other statically typed language you learn afterwards to be clumsy and limited.

  • You didn't mention which Programming Scala you had your eyes on. There are two, plus one Programming in Scala. That latter one was written, among others, by the language creator, and is widely considered to be an excellent book, though, perhaps, a bit slow. One of the Programming Scala was written by a Twitter guy -- Alex Payne -- and by ex-Object Mentor's Dean Wampler. It's a very good book too. Beginning Scala was written by Lift's creator, David Pollack, and people have said good things about it to. I haven't heard anyone complain about any of the Scala books, in fact.

    One of these books would certainly be helpful. Also, support on Stack Overflow for Scala questions is pretty good -- I do my best to ensure so! :-) There's the scala-users mailing list, where one can get answers too (as long as people aren't very busy), and there's the #scala IRC channel on Freenode, where you'll get good support as well. Sometimes people are just not around, but, if they are, they'll help you.

    Finally, there are blogs. The best one for beginners is probably Daily Scala. You can find many, many others are Planet Scala. Among them, my own Algorithmically Challenged, which isn't getting much love of late, but I'll get back to it. :-)

  • Scala has restored fun in programming for me. Of course, I was doing Java, which is booooring, imho. One reason I spend so much time answering Stack Overflow questions, is that I enjoy working out solutions for the questions asked.

Daniel
+6  A: 

I'm going to introduce a note of caution about how much Java knowledge is required because I disagree that it isn't an issue at all. There are things about Java that are directly relevant to scala and which you should understand.

  1. The Java Memory Model and what mechanisms the platform provides for concurrency. I'm talking about synchronization, threads etc

  2. The difference between primitive types (double, float etc) and reference types (i.e. subclasses of Object). Scala provides some nice mechanisms to hide this from the developer but it is very important, if writing code which must be performant, to know how these work

This goes both ways: the Java runtime provides features that (I suspect, although I may be wrong) are not available in Ruby and will be of enormous benefit to you:

  • Management Extensions (MBeans)
  • JConsole (for runtime monitoring of memory, CPU, debugging concurrency problems)
  • JVisualVM (for runtime instrumentation of code to debug memory and performance problems)

These points #1 and #2 are not insurmountable obstacles and I think that the other similarities mentioned here will work strongly in your favour. Oh, and Scala is most certainly a lot of fun!

oxbow_lakes