/usr/portage

New languages to broaden my horizon 6

I’ve read a bit and played around with Scala and Arc recently. I always recommend to learn other languages. Nobody is forced to get productive tomorrow in a language one learns but it always makes you a better programmer. This sounds trivial but I often met programmers who did only Java or only PHP or … you name it. There is nothing wrong with focusing on a language and getting really good at it, but ignorance is wrong. A good programmer always wants to learn, he basically defines himself through his fast ability to adopt new stuff. Everytime I look at different languages outside of my daily scope (which is mostly PHP and C, Ruby and Python for fun), especially on those who look exotic from the first view, I get something better. When I’ve tried to learn Erlang – even I totally failed at really getting it – I looked completely different afterwards at PHP constructs like array_filter(), array_walk() and the general concept of callbacks. When you halfway know both worlds, the functional as well as the object oriented, you just get more effective in applying the adequate methodology to solve an issue.

Back to Scala. Scala comes with a really feature rich object model. It provides classes, a concept well known to those who do Java or C++. Classes and methods may even be abstract. So far nothing new. But Scala provides a language feature so called traits. It addresses the issue that single inheritance is often too limited when it comes to stable (and convenient) compositions while mixins as in Ruby or classical multiple inheritance as in Python induce fragile, hardly maintanable hierarchies. The answer are traits. Traits allow stable compositions. A trait is basically a container for functionality. A class may extend from multiple traits, rename or overrride methods. Think on a debugging functionality – in this case implemented as a debugging trait – which should be used in a number of classes while each class has its own hierarchy. The debugger is than easily composited with the debugging consumer class while the class hierarchy is kept and the composition is stable itself. In PHP we do big wrenches to do composition. We introduce broker components to handle composited objects and what not. Traits are an elegant solution to the problem, a really impressive language construct.
Scala also provides generics. Generics are datatypes that can take other types while keeping type safety. Think you have an array and can enforce it to only accept instances of the class “Foo”. C#, Java and C++ implement that concept for a long time but nevertheless it is really handy.
I’m not really sure, how handy that would be in practice, but Scala enforces to explicitly overrride methods. I have the feeling that after a while one would do “override def method()” with the same implicitness as we do it today. Maybe this feature will be good for teaching object oriented programming.
The general syntax is a best of both worlds, the Java and the Ruby world. It is also possible to reuse existing Java libraries in Ruby, which makes it pretty attractive and lowers the entry barrier as a full stack of libraries are already present.

Arc is the newest baby by Paul Graham, the inventor of the bayesian spamfilter which mildens the pain for everyone of us dealing with email. Graham loves Lisp and it relatives. This is why Arc is very lisp’ish including polish notation for mathematical expressions. Actually the code examples are so incredible short to do a lot of stuff I guess I will try some sort of prototyping with it in the future. The plan is to design Arc to be useful in 100 years. This means time for adoption.

Filed under , , , , , , , & six comments & no trackbacks

Trackbacks

Trackback specific URI for this entry

No Trackbacks

Comments

  1. bertrand replys:
    published on February 8th 2008, 08:57:26 am *

    i have found that lua would be the easiest to grasp for a php dev. things like "traits" are conceptually possible. ever tried ?

    Reply

  2. Lars Strojny answers:
    published on February 8th 2008, 10:36:45 am *

    I find it becomes interesting when it stops being easy. Lua is a fine language, but it is really easy to grasp and you do not learn so much from it. Doing brain calisthenics for programmers just helps to become a better programmer. I have tried traits in Scala and I just love it. It makes compositions so powerful and easy to read.

    Reply

  3. Bertrand responses:
    published on February 8th 2008, 01:31:16 pm *

    Looks like you don’t know Lua. I don’t think easy means uninteresting and in Lua’s case easy means power.

    Reply

  4. Lars Strojny states:
    published on February 8th 2008, 02:04:12 pm *

    Oh no, I didn’t supposed to say something bad about LUA. I just wanted to point out the conceptual similarity to other languages providing imperative and object oriented constructs. All I wanted to say is that the distraction level is higher and therefore the impact on the developer’s knowledge is bigger when learning a language that has no or near to no conceptual similarities (I know, this is seldomnly true).
    In fact I have the opposite view about LUA, I think it is a pretty interesting language, with a neat C API to extend it. Especially as a plugin language it has a lot of pros.

    Reply

  5. Garvin replys:
    published on February 8th 2008, 12:59:36 pm *

    My main problem with learning other languages often is that I don’t find any examples of what to code. Guess I’m not creative enough to think of things that I could built with a different language.

    How do you do these things? Do you always have applications in mind when trying out a new language? Or are you modifying examples or re-coding applications you already created with different languages?

    Reply

  6. Lars Strojny means:
    published on February 8th 2008, 01:12:20 pm *

    It depends. When I looked at Ruby two years ago, I’ve had an itch to stretch, which was a jabber and mail notification bot for subversion. Ruby was the perfect tool to do so, as there is xmpp4r.
    In case of Scala I was mostly interested in the traits construct. So I’ve tried to do what I always do: thinking out a design for a web problem. So basically I thought how to realize a flexible controller with traits. I didn’t implemented it for real as it just was a theoretical problem I wanted to solve. In case of arc I just read examples and played around with snippets, so nothing mature. And I would not pretend to know Arc pretty well, I just saw it once.

    Reply

Add a Comment & let me know what you think