Scala, a Statically Typed, Functional, O-O Language 299
inkslinger77 notes a Computerworld interview with Martin Odersky on the Scala language, which is getting a lot of attention from its use on high-profile sites such as Twitter and LinkedIn. The strongly typed language is intended to be a usable melding of functional and object-oriented programming techniques. "My co-workers and I spend a lot of time writing code so we wanted to have something that was a joy to program in. That was a very definite goal. We wanted to remove as many of the incantations of traditional high-protocol languages as possible and give Scala great expressiveness so that developers can model things in the ways they want to. ... You can express Scala programs in several ways. You can make them look very much like Java programs which is nice for programmers who start out coming from Java. ... But you can also express Scala programs in a purely functional way and those programs can end up looking quite different from typical Java programs. Often they are much more concise. ... Twitter has been able to sustain phenomenal growth, and it seems with more stability than what they had before the switch, so I think that's a good testament to Scala. ... [W]e are looking at new ways to program multicore processors and other parallel systems. We already have a head start here because Scala has a popular actor system which gives you a high-level way to express concurrency. ... The interesting thing is that actors in Scala are not a language feature, they have been done purely as a Scala library. So they are a good witness to Scala's flexibility..."
Type erasure (Score:5, Informative)
Scala is great, but one really annoying thing about it is that it inherits type erasure [safalra.com] implementation of generics from Java. This means that you cannot overload methods on argument with the same generic class with different type parameters, cannot implement the same generic interface with different type parameters on the same class, cannot check whether a class implements a particular generic interface for a given type parameter, etc. They did fix some issues [lamp.epfl.ch] - for example, you can instantiate arrays - but it's still far from perfect.
I understand the need to match Java's broken model for the sake of interoperability, but surely a better way can be devised for pure Scala code? It's pretty much the only area where Scala noticeably lags behind advanced .NET-hosted languages (such as Nemerle or F#).
Re:Reinventing the wheel is sometimes good (Score:4, Informative)
Like mod_perl ?
Re:Reinventing the wheel is sometimes good (Score:3, Informative)
You mean like Mason [masonhq.com]? Possibly you're looking for something more like Catalyst [catalystframework.org]?
These things have been available for Perl for a long time.
Re:Strongly typed language? (Score:2, Informative)
http://en.wikipedia.org/wiki/Strongly_typed
Re:Strongly typed language? (Score:5, Informative)
Strongly typed languages usually make type conversions explicit and enforce type restrictions; whereas weakly typed languages usually allow implicit type conversions and relax type restrictions.
Explicit type conversions disallow a value of type T to be treated as a value of type S without invoking a function that takes a value of type T and returns a corresponding value of type S. For example, a conversion from an integer type to a floating point type requires the invocation of a function that performs the conversion. Contrast this with implicit type conversions where a value can be treated as almost any type depending on how it is to be used.
Type restrictions only allow certain operations to be done to certain types. For example, numerical addition mïay only be performed on numerical types. A lack of type restrictions allow for numerical addition to apply for, say, booleans, for example.
Re:Strongly typed language? (Score:2, Informative)
What does that even mean?
It basically means that variable types are rigidly enforced and conversions are explicit.
It's annoying, but also eliminates some possible mistakes.
For example, say you've got a float variable: FloatNum1
And a couple integer variables: IntNum1, IntNum2
Some languages don't care much about variable types and do conversions on the fly. So you could write code to do
IntNum2 = (FloatNum1 + IntNum1)
and nobody would complain. No errors. Nothing. It would compile and run just fine. At least, assuming you didn't lose something important in a rounding error somewhere.
A strongly typed language will not allow that. It will kick out errors, refuse to compile, and generally pitch a fit. You are not allowed to add a float to an integer, and you certainly aren't allowed to assign it to another integer variable. Instead, you do something like this:
IntNum2 = (Float_to_Int(FloatNum1) + IntNum1)
Re:Strongly typed language? (Score:2, Informative)
Scala is a joy... (Score:5, Informative)
Re:Reinventing the wheel is sometimes good (Score:3, Informative)
My point is that Scala is most certainly not re-inventing Perl.
True, it also doesn't appear to be a reimplementation of anything. It's somewhat related to Java (Scala programs execute with the JVM).
The code snippets on the website http://www.scala-lang.org/ [scala-lang.org] are intriguing. It's certainly a terse language. That's both good and bad.
Re:Strongly typed language? (Score:3, Informative)
Scala is statically typed. Most languages are strongly typed so that's not a particularly useful metric.
Static typing means that every object type is known at compile time and thus type safeness can be enforced before the code is executed.
Re:Wanted: Scala Expert (Score:5, Informative)
Since Scala's been out since early 2004 [wikipedia.org], it's entirely possible to have had five years of experience with it.
Re:Type erasure (Score:4, Informative)
The third of your listed limitations is semi-bogus: you can't check generic type information with instanceof, but java.lang.Class.getGenericInterfaces gives you the information you need if you're prepared to write a method to process it.
I can't help feeling that the first two can be worked around too if you're prepared to be more creative with your Miranda methods than javac.
Re:Doomed (Score:2, Informative)
For the curious: http://www.alenz.org/mirror/khason/why-microsoft-can-blow-off-with-c.html [alenz.org]
And the followup: http://khason.net/blog/computer-languages-and-facial-hair-%E2%80%93-take-two/ [khason.net]
static typing != strong typing (Score:3, Informative)
According to common usage, Python and Scheme are both "strongly typed" as well, since they guarantee that all type errors in programs are detected. This is in contrast to "weakly typed" languages like Perl or K&R C, in which many type errors are silently ignored. That is, all four combinations of strong/weak and static/dynamic typing are possible.
Some people are using the term "strong typing" as a synonym for "static typing"; I wouldn't really care, except that there is no good other term to describe what "strong typing" means.
From a practical point of view, it seems pretty clear that "strong typing" (in the first sense) is important, but I have seen little evidence that static typing is all that useful in a general purpose programming language.
Re:Choosing a language (Score:1, Informative)
Parent suggested:
y = [x*x for x in list]
vs
(let ((y (map (lamba (x) x*x) list)))
Personally I prefer a syntax like
where the BNF for a lambda should be something like
so you could even write
if you don't feel like trusting the compiler's ability to do type inference.