• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scalatra in Action, The Well-Grounded Java Developer

 
paul nisset
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Hi ,
How transferable are Java skills to Scala ?
For example, does Scala use the same libraries and classes?

Thanks,
Paul
 
Brian Hanafee
Greenhorn
Posts: 7
Mac Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Second question first: Yes! You can use any of the Java libraries. Interoperability is definitely a strength. Once you try using the Scala collections library, you probably won't want to use the Java collections, but it's all there. Many of my Scala projects have long lists of Java library dependencies (Joda time, for example). Importing a Java class or interface is really no different than importing a Scala class or trait, except of course Scala-specific features aren't available. It's also quite easy to create Scala objects that extend or implement Java classes and interfaces.

The answer to your first question is also yes, Java skills are transferable to Scala. That's a double-edged sword. You can make your Scala feel and behave like it's just a syntacticly different version of Java, and apply the same OO design principles as you would in a Java environment. It'll work fine, and your productivity in Scala will quickly become on-par with your productivity in Java. The other answer to your first question is no, Java skills are not helpful (and in some ways detrimental) to using Scala as a functional language. It's a very different mindset, but it's also where some of the bigger gains in productivity are to be found. The temptation to do something the Java way can be hard to overcome and think through a functional solution. I highly recommend taking Martin Odersky's class and really pushing yourself to develop functional skills to complement your OO skills.


Edit: typo and implement java interfaces rather than objects
 
paul nisset
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
Thank you for the tips.
The flexibility sounds great but your right ,it doesn't make sense to use a new language to mimic an existing one.
Thanks,
Paul
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Brian Hanafee wrote:

The answer to your first question is also yes, Java skills are transferable to Scala. That's a double-edged sword. You can make your Scala feel and behave like it's just a syntacticly different version of Java, and apply the same OO design principles as you would in a Java environment. It'll work fine, and your productivity in Scala will quickly become on-par with your productivity in Java. The other answer to your first question is no, Java skills are not helpful (and in some ways detrimental) to using Scala as a functional language. It's a very different mindset, but it's also where some of the bigger gains in productivity are to be found. The temptation to do something the Java way can be hard to overcome and think through a functional solution. I highly recommend taking Martin Odersky's class and really pushing yourself to develop functional skills to complement your OO skills.


Edit: typo and implement java interfaces rather than objects


If I think about it, my java skills which are imperative by the way is definitely not advisable to be transferable to Scala style of functional programming. All I can take from Java are just the libraries.
 
paul nisset
Ranch Hand
Posts: 236
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's good to know. It will probably save many hours fitting a square peg in a round hole.
 
Brian Hanafee
Greenhorn
Posts: 7
Mac Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Joe Harry wrote:If I think about it, my java skills which are imperative by the way is definitely not advisable to be transferable to Scala style of functional programming. All I can take from Java are just the libraries.


That might be a little extreme. There are times when an OO approach does make sense. Scala blends them, so you can have it both ways. Try to find a functional solution first, but keep OO approaches in your toolbox. Many of the OO solutions in Scala are an improvement over their Java counterparts, resulting in less code to implement the same or more functionality. Traits, for example, are an OO solution that combines benefits of Java interfaces and Java abstract classes. Getter/setter pairs are completely unnecessary. Scala also has real closures rather than the broken inner class concept. The result is that many of the GoF patterns become invisible parts of the language that just work rather than tedious boilerplate. Also the type system (abstract types, variance/contra-variance notations, etc.) moves much more of the type checking from the runtime to the compiler where it belongs, so that more powerful libraries can be created without sacrificing correctness.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic