Tuesday, July 22, 2008

What Has Scala Got To Do With Being A Boiled Frog?

I'll take the analogy back to its analogue.

With limits approached on processor core speeds, multi-core processors have arisen to provide the additional performance that cannot be squeezed out of individual cores. That means that on my computer one application can be running in one core, and another in another core. If my computer has two cores, it seems that it is running those two applications twice as fast as it would have done if it had only one core.

That's true. And with each doubling of the number of cores in my computer's processor, it will be able to run more applications and all will seem well and good with Moore's Law -- from a computer user's perspective.

Computer users are not the potentially boiled frogs. It's computer programmers who will begin to feel those tiny bubbles swirling around their nether regions as they float around happily in a pot of soothing warm water with convective currents tickling their toes.

And guess what? All computer programmers are computer users. From a user perspective we see our computers getting faster. In that respect we are surprisingly good at seeing things from a user point of view. The irony is that in this case we should not be guiled by user experience. We have to think of ourselves for a change.

Our individual programs are not running much faster. Unless you are writing Fortran or Fortress (eventually) on a supercomputer and your code is pipelined by the compiler to be parceled out to multiple CPUs, then your programs are running in a single core. And those cores are likely to experience only marginal speed improvement in future now that some physical limits have been reached.

With Scala (and Erlang) it is possible to write functional style programs that are thread safe and more capable of utilising the power of multiple cores so your programs will run faster. Faster than those who don't adopt the functional style of programming. There's a lot coming to mind in this one sentence. Sure, you can write multi-threaded programs in Java. But it's a bit mind bending. And yes, it's a steep learning curve going from object oriented and procedural programming to functional programming, but the payoff may be immense. And you have to get yourself out of that pot before it's too late.

Where Scala is different is that it's a hybrid language that blends both object oriented and functional language facilities. That means you can begin learning Scala from a Java perspective and dip your toes into functional programming at your own pace. And you won't get your toes boiled. And because it runs on the JVM (like Groovy and JRuby) you can use all your familiar Java classes, and import from the amazing array of class libraries available for the Java platform.

And you could write one or two helper classes in Scala and use them into your Java programs, just to get your feet wet.

Are you dreaming wistfully of the next major advance in physics or nanotechnology that will lift your gently out of your predicament with a quantum leap in core performance? The steam may be already dulling your senses.

Let's assume that Moore's Law resumes its pace at the core level. Multi-core processors are not going to go away. As in economics or biology, once a business or plant variety has spread, it tends to take root and retain its selective advantage. A multi-core processor will always be better than a single-core processor. That won't get you out of the pot. Multi-core is here to stay. Programmers who realise this and take advantage of multi-core programming languages and techniques will do better than those who don't.

Don't be a boiled frog. Learn Scala now!

Here's a link I have found useful as I begin to transition from Java to (Java + Scala).

Scala for Java Refugees by Daniel Spiewak is a series of posts about Scala from a Java point of view. The comments too are of high quality, and he makes corrections based on those comments.

No comments: