Recently someone asked me if I’d thought of making tutorials about Scala. I’d never heard of it. So I looked it up and became intrigued. It turns out that Scala is a fairly new programming language that compiles to Java .class files, which of course run like any other .class files on Java virtual machines.
So Scala can run on Android or your PC or whereever, and in theory runs with the same speed as a Java program. You can also use any Java class within your Scala program.
So why use it? Scala was designed by one of the creators of Java – some German genius programming guy by the name of Martin Odersky – to be a “scalable” language; that is, you can basically build in your own language constructs, create your own funky kinds of loop or whatever if you want to. I’m not totally certain whether that’s a good thing or a bad thing, but the idea is that Scala can’t become obsolete in the same way that other languages certainly will. Even Java is changing every few years, and people are growing tired of some of its annoying quirks.
Scala is also designed to remove all unnecessary coding, meaning that Scala programs are half the size of Java ones. You can, in effect, create your getters and setters just by choosing a single keyword for instance. At the same time it is allegedly more readable than Java.
On top of that, Scala allows you to do functional programming. Frankly I thought functional programming was the old style of programming where you build your program from functions. Who wants to go back to that? These days we prefer objects. But no, functional programming is where functions are values that can be passed around or defined within other functions just like integers or strings. In the lingo, functions are first class objects. In fact, everything in Scala is an object, including all literals such as “1″, “Hello”, etc, and all functions.
I’m a little confused by this, but it’s starting to become clearer. In Scala, the plus sign “+” is a method call; but method calls are functions, which are objects. I think. Crazy.
The main problem with Scala is lack of documentation. The only really good documentation I’ve found is the non-free version of “Programming in Scala”, which explains things at a gentle pace as long as you already know how to program.
Create Your Own Social Network?
My own main motivation in learning Scala, other than an obsessive attempt to quell the feeling that I’m not intelligent enough to understand Scala and I’m damned if I’ll be beaten by something that’s designed to be understandable, is that you can use it to build applications in the Lift framework. Lift promises to allow you to create complex websites extremely quickly, like Ruby on Rails but without the stupid name.
Twitter apparently now uses Lift, as does the social network Foursquare, and the UK’s Guardian newspaper is switching to it.
In general, I hate all frameworks. But since I decided recently to get into building fancy modern websites with user registration, chat applications and what-not, I accept that I need to find a good framework. Also I’ve no idea how to stop hackers or how to create a website that could scale up to tens of thousands or even millions of users, and Lift promises to basically more or less handle that stuff for you, as much as any framework could.
You can indeed create a website VERY quickly with Lift. Just download it, type a few commands (it even installs Scala for you) and it’ll be up and running, complete with user registration (which however, won’t quite work since you don’t have a mail server). Then you’re only left with the headache of learning Scala and trying to figure out how to modify the framework to suit your own purposes.
This is a steep learning curve, but I’m sticking with it for the moment, since the alternative would seem to be going back to Java servlets (which I nurture a lasting dislike of that may or may not be rational, after having working with them for several years) or using something like Ruby on Rails (I can’t fully explain what I dislike about Ruby on Rails either — maybe it just sounds like it’s going to be obsolete soon) or going back to my original plan and using WordPress, which probably won’t scale up too well and isn’t quite as easy to customise as I’d like, although I’ll admit WordPress is very good and would do the job.
Finally I want to mention a private company here, which I wouldn’t normally do except that they’re giving away free webspace and so far most reviews of them are highly positive.
Free Java-Enabled Web Space!
If you want to develop a Scala or Java servlet application, you need webspace that supports servlets. You’ll also probably need a database and you’ll probably need a mail server. All that sounds like it’s going to cost you a pretty penny. Then you’ve got the following problem: what if your website actually becomes very popular? You’ll have to migrate it to some other, more powerful set of machines, pay more money and so on, and you’ll have to get your head around a lot of very tedious issues or else hire someone who understands web farms.
Cloud services, such as Amazon’s EC2, promise to alleviate many of your problems. Your software runs on “the cloud”, an ill-defined, expandable bunch of machines, and you just use as much of the cloud as you need.
While Amazon’s starter prices seem a bit steep, CloudBees gives you a lot of stuff for free, including, at the time of writing, a 5 Mb database, a servlet container to run your Java servlets or Lift framework programs and even a mail server that can send 200 emails a day. Once you start registering thousands of users on your fancy new social networking site, you can simply upgrade your plan and start forking out cash to get more memory and computing power. Which is rather nice.
The future of cloud computing seems bright. Who cares what machine your website is running on? You just care about whether it can handle your users or not. As for Scala, whether it will be the successor to Java or not, only time will tell. Personally I doubt it. I think programmers actually quite like typing unnecessary code and only having a few limited ways of getting things done. Scala makes people feel stupid. That’s why it won’t take off in a big way. That and the fact that it sounds as though it’s sort of piggybacking on Java, even if it arguably isn’t. But I could be wrong, in which case I’d be very happy.