Summary
In "The Feel of Scala," a talk I gave at Devoxx which is now available on Parleys.com, I show Scala solutions to real problems to help you get a feel for the language. Along the way I demonstrate how you can get many of the productivity benefits offered by dynamic languages using alternative static techniques in Scala.

Advertisement

In The Feel of Scala, a talk I gave at last year's Devoxx conference, I explain how I ended up choosing Scala instead of Ruby, Python, or Groovy for Artima's next JVM language. I show some ways in which you can reap
benefits offered by these dynamic languages using both alternative static techniques offered by Scala as well as using dynamic techniques directly in the Scala language itself.

One of the most commonly cited productivity benefits of dynamic
languages is that they enable much more concise programs compared to
Java. While this is true, the productivity benefit here is actually
conciseness, and that doesn't require dynamic typing. I show how
type inference in Scala lets you get much of the conciseness of say, a
Ruby or Python program, but in a statically typed language.

Another productivity benefit of dynamic languages is that, via a
feature called open classes in Ruby or Python, you can add a method to
a class and then call it. You can't do this in a static language.
Nevertheless, I point out that the productivity benefit isn't
actually in the dynamic adding of the method. The benefit, instead, is in being able
to call the method. And that you can do in static languages using various
other techniques. In C# 3.0, for example, you can make it
possible to call new methods on classes via C#'s "extension methods"
feature. In The Feel of Scala talk, I show how you can use Scala's
implicit conversion feature to obtain that same productivity benefit.

Another oft touted productivity benefit of dynamic languages is that
duck typing allows you to pass classes with common structures but no
common supertypes to a method, which treats them uniformly. I
point out once again that the productivity benefit isn't actually
the duck typing per se, but the ability to pass the different types. I
demonstrate three ways to achieve that in Scala. First, I show
"view bounds," which is a completely static approach that involves
implicit conversions. I also show structural typing in Scala, which
is dynamic in the sense that reflection is used to invoke methods at
runtime, but static in the sense that everything is checked at compile
time. Lastly, I demonstrate using plain-old duck typing, exactly the same
dynamic technique used in Ruby and Python, but this time in a static
language. I show that as with duck typing in a dynamic language,
spelling errors result in runtime errors, but
then demonstrate that with a compiler plug-in, you can move that
run-time duck typing error to a compile-time error, effectively
extending Scala's static type system.

Lastly, another commonly cited benefit of at least some dynamic languages is that their
syntax is more flexible, allowing you to make domain specific
languages. While this is also true, the benefit comes from the
flexible syntax, not the dynamic typing. During the talk I show
that dynamic typing is not required for syntactic flexibility. I
demonstrate the flexibility of the Scala language, showing how you
can define new control constructs and make internal DSLs.

The talk suggests that although dynamic languages such as Ruby,
Python, and Groovy are indeed in many ways more productive than Java, it
isn't so much the dynamic typing that makes the productivity possible.
Rather, it is the way these languages use dynamic typing to enable programmers
work at a higher level compared to Java. I conclude the talk by explaining I choose Scala because I felt Scala gives me many (though not all) of the productivity benefits of the dynamic JVM language alternatives, while still letting me enjoy the productivity benefits of static typing as well.

You can view the complete one-hour presentation of The Feel of Scala on Parleys via this URL:

RSS Feed

About the Blogger

Bill Venners is president of Artima, Inc., publisher of Artima Developer (www.artima.com). He is author of the book, Inside the Java Virtual Machine, a programmer-oriented survey of the Java platform's architecture and internals. His popular columns in JavaWorld magazine covered Java internals, object-oriented design, and Jini. Active in the Jini Community since its inception, Bill led the Jini Community's ServiceUI project, whose ServiceUI API became the de facto standard way to associate user interfaces to Jini services. Bill is also the lead developer and designer of ScalaTest, an open source testing tool for Scala and Java developers, and coauthor with Martin Odersky and Lex Spoon of the book, Programming in Scala.