Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Questions about Scala from a Rubyist

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

like image 970
jinx Avatar asked Feb 28 '10 15:02

jinx


People also ask

Why Scala is so popular?

Scala makes it easy to write code using immutable data. This includes constructs such as: first-class vals, case classes, higher order functions etc. But that's also because how the standard library is designed and written; all of the “default” data structures are immutable.

Is Scala a functional language?

Scala is also a functional language in the sense that every function is a value. Scala provides a lightweight syntax for defining anonymous functions, it supports higher-order functions, it allows functions to be nested, and it supports currying.

What is Scala in programming?

Scala (/ˈskɑːlə/ SKAH-lah) is a strong statically typed general-purpose programming language which supports both object-oriented programming and functional programming. Designed to be concise, many of Scala's design decisions are aimed to address criticisms of Java.

What is Scala vs Java?

Scala is a statically typed programming language, whereas Java is a multi-platform, network-centric programming language. Scala uses an actor model for supporting modern concurrency, whereas Java uses the conventional thread-based model for concurrency.


2 Answers

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.
like image 199
retronym Avatar answered Sep 21 '22 13:09

retronym


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.

like image 27
Daniel C. Sobral Avatar answered Sep 25 '22 13:09

Daniel C. Sobral