I have been reading through the tutorials and finally downloaded Scala last night. It looks pretty cool to me. Most of the functional stuff of a language like Haskell or OCaml, tail call elimination, higher order functions, semantics for easily encoding algebraic data types. The syntax isn't as clean as Haskell, but there's less boilerplate than Java. Plus it compiles to JVM bytecode so it can interact seamlessly with Java classes, it has the same "compile once, run everywhere" flavor of Java, and it's comparable to Java in terms of speed. But I haven't done anything serious with it yet so I might just like the spec. So does anyone have any experiences with it whether good, bad, or indifferent?
Some problems are so complex that you have to be highly intelligent and well informed just to be undecided about them. - Laurence J. Peter
Joined: Jan 17, 2006
OK from the deafening silence I'll assume the answer is no. So I'll respond a little about what I've found. The reason I was drawn to Scala was for its support of a functional style of programming. I've read other places that most people who use Scala use it in an Object Oriented style, but I feel like you could just use Java for that. So I figured I'd play around a little bit by solving the first few problems in Project Euler.
Here's the Scala version of the answer to Problem 2
It could probably have been done in a one-liner but whats the fun in that?
Anyway after I got done with that I figured I would write a small Mastermind that had a small GUI component. Since I was dong something that would require more than 10 lines of code I figured I needed to write some tests. So I thought this was as good a time as any for me to get used to writing tests in SUnit, JUnit style unittestng tool that ships with the Scala development kit. I was severely disappointed. It was poorly documented and nearly unusable. By default, if an assertion fails it prints a message to the console and the entire stack trace of the method call up to that point, usually about 50 lines of library calls that can safely be ignored, but must be sifted through to find the message provided by the next failing test. When I say its badly documented, this is what I mean. Here is the entire documentation of the SUnit object, the object that contains all the testing classes: That seems like a pretty fragile way of running tests. Seriously. I guess I could use JUnit to test the Scala code, but since I'm stubborn, I think I'll try to patch together something to make SUnit usable. I'm still going to finish the Mastermind project. I'll post back if I find out anything else useful.
I'm gonna go buy a copy of Mastermind. For real, right now. I brought up the Scala root page, then moved on. I recognize this type of work ( as your experience reveals ) by how the page runs on page-load. I like to look at the code they produce because it is often a masterwork by accomplished masters of the craft. I want to implement the board game with an AI engine behind it. Java can run ai sufficiently well and provides a prototyping tools that can be fast-path (ed) where need be with it's call native construct.
"The differential equations that describe dynamic interactions of power generators are similar to that of the gravitational interplay among celestial bodies, which is chaotic in nature."
I've been playing with Scala too and really liked it. As an exercise, I've implemented Dijkstra�s shortest path (Dsp) algorithm and blogged about it. For better testing maybe you can consider ScalaTest and ScalaCheck Although philosophically, OO and FP are incompatible, I think the pragmatic approach of Scala hits a sweet spot between both paradigms and can lead to very interesting results... [ April 29, 2008: Message edited by: Gabriel Claramunt ]
Thanks for the link Gabriel. Looks like you've explored the language a little deeper than I have thus far. I really like Scala, not as much as Haskell but close. I hadn't even read about explicit self-typing until I looked at your blog. Mark that down as something else I have to learn. I knew about ScalaCheck, but this is the first I've heard about ScalaTest. ScalaTest looks like it might be exactly what I'm looking for. What I've liked the most about Scala in the little bit I've looked at it is how it emphasizes short concise interfaces that are easily and painlessly reused. Since the documentation is so bad for many portions of the API, I find myself reading through a lot of the source code to figure out how to use certain features. It seems to me that a lot of the API that could be written in a more functional style (no mutable state, using recursion instead of looping as a control structure) is instead written in a much more imperative style with a lot of mutable variables and explicit while loops. I'm not sure if this was done for performance reasons or if the authors were just more comfortable with that style. Anyway, thanks for the link to your blog. I'll keep the interested updated on how the Mastermind game is going.
Joined: Jan 17, 2006
So I've been working on the Mastermind game. I still don't have a GUI, but I have the console version working pretty well. For any interested, here's the code to the main game logic.
As you can see, I've just been experimenting with Scala's abstract class and trait facilities. Scala doesn't have the restriction that every Scala class must go in its own file, so this is all in one file. It seems to be a common Scala idiom (at least in the library classes) to have a class and a "companion object" with the same names. The companion object is a singleton object that mostly carries utility method that are usually analogous to static methods in Java (a little like the relationship between the Collection classes and Collections class). Scala doesn't have static methods.
In all I'd say the code is probably just a little smaller than the comparable Java code. The style is pretty different. I intentionally tried to use as little mutable state as I could. I'm not sure if its clearer or not. [ May 10, 2008: Message edited by: Garrett Rowe ]
Gee, I posted nearly this exact question over in meanless drivel.
I haven't used it, yet, but I'm learning a bunch.
Java is getting too ugly for my tastes....
Joined: Sep 17, 2006
PF: Java is .....
Typing probably, one general purpose do-all linguistic a good area for prototyping. I suggest re-examining the decision after designing an overview in Java. I will probably start an attempt to write a Collection manager as soon as I close the window. The JList / JScroll pane has some 'extensions' ( ... ) that I would like to have that are in the direction of simplification. I noticed the typing issue as soon as I looked at the Scala page, you are not alone. Google for Ravi Mohan.
- do you drink?... perhaps this evening would be a good time. ( humor ) [ May 14, 2008: Message edited by: Nicholas Jordan ]
In December 2007 I attended a talk by Martin Odersky (the inventor of Scala) at JavaPolis. The guys of the JavaPosse (one of the most popular podcasts about Java) seem to be quite interested in Scala too.
The new eclipse's Scala plugin looks very nice (lot better than the old one). Syntax highlighting, code completion, and all the nice goodies expected from a full blown IDE. No refactoring though, but one can argue that Scala makes refactoring less necessary (just joking).