jducoeur: (Default)
jducoeur ([personal profile] jducoeur) wrote2009-01-03 02:25 pm
Entry tags:

Scala By Example

For serious programmers: I've been gradually reading into the language Scala for the past few weeks. Having just finished the online book Scala by Example (PDF, about 150 pages), I commend it as a fine read, for language geeks or simply programmers who want to expand their repertoire in useful ways. It's one of the better languages books I've come across.

It's written by programmers for programmers -- anyone who doesn't have pretty good depth in the subject will just be left at sea. But if you're an experienced software engineer, it's a neat read. Rather than trying to be orderly and complete, it instead presents a series of chapters, each introducing a major concept in Scala with relatively rich examples. It doesn't waste time on the basics: most chapters are focused on things that are really different from conventional languages like Java or C#.

It's gone a long ways towards convincing me that I want to migrate much of my development over to Scala. My original motivation had simply been the desperate crying need for a functional language -- I use functional techniques a *lot*, and emulating functional programming in Java is an awkward and bulky pain in the ass. But in practice, I find myself very attracted to a lot of Scala's other capabilities. For example, it rather casually (in Chapter 3) describes Scala's capabilities for working with Actors and Messages -- essentially, by adding a single library, it gains the core functionality of Erlang, while not being as irritating and limited a language as Erlang. Given that I'm increasingly suspecting that the Erlang-oid message-passing approach is probably the way CommYou *should* work internally, this is very tempting, and I may start experimenting with it.

Better yet, the book drives home the language's meta-programming facilities. A lot of the examples are of the form, "Here's a useful language feature -- and here's the code that implements it". Indeed, the book ends by returning to its start, building up from a few synchronization primitives to demonstrate how to implement a simplified version of the Actor functionality.

I'm quite taken by the whole thing: Scala looks to be a very good language. It has Ruby's intense object-orientation, without Ruby's syntactic quirks and weak threading. It has Erlang's message-passing, without Erlang's lack of OO. It has more or less complete interoperability with Java (within reasonable limits: if you define classes that go beyond Java's semantics, you may not be able to access them), and access to Java's full libraries, but adds all the things that Java is lacking such as functional programming.

So I'm going to investigate it more seriously: I'll try installing it and migrating some CommYou systems over to it. More reports on that as it goes...

[identity profile] metahacker.livejournal.com 2009-01-03 08:52 pm (UTC)(link)
Good stuff to know; I'm taking a look myself.

Any idea about the performance hit (if any)? Always my worry with 'fancier' languages.


Edit: Neat. They have an IDEA plug-in. I'll just do some testing, then...
Edited 2009-01-03 21:07 (UTC)

[identity profile] antoniseb.livejournal.com 2009-01-03 09:11 pm (UTC)(link)
If it is named after Flaminio Scala, then perhaps I should look at it too.

[identity profile] learnedax.livejournal.com 2009-01-03 10:53 pm (UTC)(link)
Hmm. Fairly conventional ideas, it looks like so far, but selected and composed in a more judicious way than in many extreme languages. I've gotten jaded about new languages, but I might play around with this one. I like that they ground the functional paradigm, which I quite like in the abstract, with a sense of the necessities of state persistence in real world applications.

(Of late, the more I delved into lambda structures, the more I realized that a truly functional language cannot produce functioning applications, because interaction is always a side-effect.)

[identity profile] learnedax.livejournal.com 2009-01-04 01:12 am (UTC)(link)
Hmm, I like the handling of generics, too, but I just read the bit on parallel processing constructs. I hadn't realized how similar their approach was to Fortress's, though I guess that explains why the latter is currently built using the former...
ext_44932: (tech)

[identity profile] baavgai.livejournal.com 2009-01-03 11:32 pm (UTC)(link)
Not another bloody language! ;)

I've toyed with Erlang; I'm still not convinced a pure functional language is the solution. At the same time, lambda methods are amusing me more and more when I have to deal with lists ( or Lisp? )

I found myself playing with Python again this weekend, only using more functional stuff because it's on my mind. Actually, more of the list comprehensions that seem lifted from Haskell.

I enjoy a lot of Python, except that "data type as you go" crap that so many newer languages seem to think is useful...

Wait! Scala looks like Python Java fusion. All those little defs in defs with typesafe declarations? I think I may have to play with this. Damn.

And thanks. :p

[identity profile] crschmidt.livejournal.com 2009-01-04 12:37 am (UTC)(link)
I think Python is dynamic and strongly typed.
>>> 5 == "5"
False
>>> a = 5 
>>> a = "5"
ext_44932: (Default)

[identity profile] baavgai.livejournal.com 2009-01-04 05:55 pm (UTC)(link)
Agreed. The real issue is the dynamic part. I like my type mis steps to be caught at compile time, rather than run time. It's really one of my only gripes with the language.


>>> def test(foo): print foo, "\t", str(type(foo)).split("'")[1]
...
>>> test(5.0)
5.0 float
>>> test("5")
5 str
>>> test(5)
5 int
>>>

[identity profile] crschmidt.livejournal.com 2009-01-04 06:19 pm (UTC)(link)
Understood. I am a fan of dynamic typing, but hell, I work in Javascript half the time, so... :)

[identity profile] crschmidt.livejournal.com 2009-01-05 12:35 am (UTC)(link)
Wikipedia says (http://en.wikipedia.org/wiki/Type_system#Strong_and_weak_typing):

"Weak typing means that a language implicitly converts (or casts) types when used.
>>> 5 + "37"
Traceback (most recent call last):
  File "", line 1, in 
TypeError: unsupported operand type(s) for +: 'int' and 'str'


is used an example of strong typing. However, it also says:

"these terms have been given such a wide variety of meanings over the short history of computing that it is often difficult to know, out of context, what an individual writer means when using them." -- Strongly Typed Programming Language (http://en.wikipedia.org/wiki/Strongly-typed_programming_language)

So... we're probably both right :) To me, the 'dynamic' means that the latter succeeds, and the 'strong' means that 5+'37' or 5 == '5' don't work.