The Mighty Awesome Power of Scala
Posted by feydr | Posted in Uncategorized | Posted on 21-03-2010
View Comments
1) class reloading
2) dynamic typing OR a sweet ass type inference engine
I could not stress these two points more. I do NOT want to have to recompile/reload my classes every time I make a simple edit to the code — having this with ruby/merb has just made tremendous strides in how fast we can flesh out features. I also HATE having to declare types for my methods, variables, etc. I think it’s a waste of time and good code should not have to do that (especially if you are using type inference like all good languages do).
So eventually I came across lift which I thought sucked right out since it likes maven/xml. Seriously, xml files were NOT meant to be configuration files — goto hell!
However, recently on another front my colleague and I have already been looking at languages that run on the JVM for another project for the same website. We’ve been looking into scalability concerns with big data and have both concluded that we want/need the power of the JVM but really do not like java particularly too much. This has led us to look at the two up and comers: Scala and Clojure. Recently I got ahold of the pragprog book and started flipping through it’s pages. One section in particular caught my eye. The author in a matter of 5-10 lines or so was able to open up a file, scrape some xml from the web, parse it and then save it. I was like — WHAT THE FUCK!? In java the exact same code would have had to have gone through the verbosity monster making machine and clock in at 20-30 lines easily.

So I kept reading the book! Another thing that immediately jumped out at me — where’s all your fucking semi-colons!? Oh those? We don’t need no fucking semi-colons in our language!
Motherfucking <3
This was enough for me to seriously start thinking about re-writing our main java project. This particular project has 10 (count them ten) antlr grammars and quite a few supporting classes along with CLI wrappers to said classes. We have quite a few test suites for each class thankfully otherwise this project would probably not be so possible without seriously killing it.
I first started converting one of our main classes over. Replace the for loops, drop the semicolons, take out the public identifiers, etc. Let’s try to compile. Oh noes! We don’t have access to these methods anymore. This is where javap comes in handy when you are converting from java –> scala. Javap will show you what the REAL class name or method name is for each language. Keep in mind my original intention was to just get a scala class to compile and use it FROM java. Now I’m on route to be using everything from scala but it really doesn’t matter — as long as you have class files and as long as those class files have access to the right methods/variables you are set.
Let’s say we have a seat class written in scala:
package com.bluffware; class Seat() { var id:Int = 0 var number:Int = 0 var seat_id:Int = 0 var sitout:String = "" var position:String = "" var button:String = "" var player:String = "" var amount:String = "" // might want to add utg, cutoff later on.. }
You might think that from java you can do a simple:
seat = Seat.new(); seat.number = 2; myContainer.seats += seat;
Well you can’t cause javap shows that there is NO access to number.
If you are accessing this class from java you’ll need to do the following:
seat = Seat.new(); seat.number_\$eq(2); myContainer.seats().\$plus\$eq(seat);
The escapes are for antlr — in normal java it’d just be _$eq(var)
Really though, the only time when you are going to have to do this is if you
have a java class that you need to be compiled through java — if you can convert
it to scala go ahead and do so.
Depending on the size and scope of your project it might make sense to convert
a bit to scala and do it piece-meal and then have other classes that access the scala
class to change the way they use it.
Really in our project now the only thing that uses this is our antlr grammars which
I’m going to be at sometime finally finishing the scala antlr target.
Anyways, if you have not tried out scala yet and you are a java dev — what are you
waiting for!? It’s easier than you think — make sure you have some tests for a small
class you’d like to convert then start doing it!














Except, this badhand was a lot like some others I had received — it had a special 2-byte character that looked like ‘


