Saturday, October 30, 2010

Scala Bowling - A better Java or a Research Project?

A short post in the hope that I'll get some input about Scala. I first looked at Scala when it first came about, around 3 years ago now I think. My first impressions were clever, conceptually robust, but schizophrenic. It is as though the language designers decided to shoe horn in every language feature they could think of. It was clear that it was way more powerful then Java, but for me it was too clever, too complex.

Well three years later I'm looking at Scala again. I've recently come back to Java, after spending awhile in C# land, and I'm sorely missing lambdas. A quick perusal of the usual Java forums convinced me of what I had already suspected. Java 7 and closures aren't going to see the light of day anytime soon. What Java needs is a re-write, and you could argue that Scala is it! So I downloaded a Scala plug-in for Eclipse, got "hello world" up and running and started pondering what to do next?

As chance would have it, trusty Ron Jefferies has come to the rescue again with his bowling game. His first attempt at Bowling with Scala is definitely imperative. A sort of Scala for Java programers style. As he anticipated the functional community were quick to come back at him with more functional suggestions, using pattern matching and recursion. Well Scala has all the functional paraphernalia so why not use it? There is a sort of unsaid assumption by the functional crowd that a pure functional solution is somehow intrinsically superior to an imperative one. As I mentioned in my post on Haskell the jury is still out for me. Sure state is evil, and where a functional style is a natural fit to the problem domain, then a pure functional style is a no brainer, but how often is that? My gut feel is that most of the stuff I tend to do (shuffling data between a database and a browser) is imperative in nature, well at least I tend to think of it that way. To me, pure functions are things you use in maths and best suited to mathematical analysis. I get the feeling that Ron also shares my misgivings, and yet again, the expert pure functional solution was found wanting when someone discovered a failing test.

So how should we use Scala? As a pure OO language where we exploit the benefits of immutability as much as we can? Or as a pure functional language were we exclude state entirely Haskell style? It was interesting to see that the expert pure functional solution came about as a direct port from Haskell. looking at the Haskell version and the Scala version, they are almost identical. Based on this evidence you could describe Scala as a pure functional language, that also so happens to support imperative OO programming.

The guys over at Object mentor may beg to differ. Their bowling examples, whilst functional in nature also exhibit an OO quality, yet they still make use of pattern matching. So their Scala style could be considered an OO/Functional hybrid. What is the budding Scala programmer from an imperative background to do? It seems to me that Scala is still a bit of an experiment, with people still working out the best idioms.

The option of using Scala as a better Java is always there of course, and if I get the chance to do so I will, but there will always be this nagging doubt of whether I'm doing it right? And whether a real Scala programmer would approve? I think languages should promote a style. C was very good at this, with everyone adopting the style of Kernnighan and Ritchie. Smalltalk also makes a very strong style statement, exemplified by the code in the Smalltalk-80 image. Scala doesn't seem to have this. It is though it is at least two languages, or perhaps three, all coexisting. A haphazard mix of paradigms, idioms and styles.

I guess I need to read the book by the inventor Odresky to see if he as a Scala style I can comfortably adopt. More important then the discomfort of "am I doing it right?", is the obfuscation of the problem domain that comes IMHO when applying a pure functional style to problems that are more naturally expressed imperatively. Should I always be living in fear of that next failing test that blows a whole in my cleverly contrived pure functional solution? Or should I be able to reason about the correctness of my program with a modicum of confidence by simply reading it?

I'm interested in finding out the thoughts of people who are further down the Scala path. All comments and pointers welcomed.

Monday, May 03, 2010

Pull is the new Push

Just finished watching the video of Kent Becks keynote speech at the recent Lean Startup Conference. First thing to say is that I've got a lot of respect for Kent Beck. The thing that grabbed me about this talk though was that he was advocating that we could use pull and flow to accelerate learning in the context of an internet startup. The learning is identifying where the value is. What is it that customers are willing to pay for, and in turn will mean that your startup will become financially successful.

I'm a forty something, and I remember when none of this technology existed. I remember when it all was a promise. The microchip was going to change our lives for the better, by giving us all lots of leisure time to spend as we like. Well it didn't quite work out that way did it? Instead technology has made our lives faster and less secure. So given this back drop who is going to willingly turn to technology as a fun thing to do?

Sure people will use technology to interact with other people. I guess that's exactly what I'm doing now, but few will be interested in technology for its own sake. There appears to be a dilemma here. People enjoy interacting with other people, yet increasingly they find that they need to put up with irksome technology in order to do so. The village pub were everyone knows your name is now a thing of the past. Instead we're all sat at home by ourselves trying to make friends through blogs and chat rooms.

Is this a trade that anyone really wants? I doubt it. I'd much prefer being in a real social setting right now, getting this all off my chest :) So the trick it seems is to find ways that are less irksome then others that allow us to interact with each other through these horrible technology mediums we've invented.

The village pub closed down years ago by the way, and even if it hadn't your pals haven't the energy to come out for a drink, because the computer at work means that they now have to do three peoples jobs, so in the evenings they barely have the energy to sit through a TV dinner before rolling into bed :(

Kent is pretty open and honest about his failures in startup land. I think he is being slightly unfair to himself though. No one wants this stuff. People will put up with it only if they really have to, or if they see a way of making money out of it. Technology in the work place is seldom a win win proposition. Often a minority gain whilst the majority loose. Is it any wonder that technology as a leisure pursuit is a hard sell?

The whole drive for being "Lean" and efficient leaves me a bit could. We seem to think that by speeding everything up we can some how make the world a better place. I like the idea that many things of value can't be measured and many of the things we can measure have little value. Try putting a number on the value of your humanity?

I can't help but think that all this technology is being pushed on us all. Kent is right, we can learn which aspects of the technology are less irksome to users, to the point that people will actually put up with it, in order to make contact with their fellow man. But is this really market pull? Or just a desperate means of pushing stuff onto people that deep down none of us really want?

An After thought:

Despite this rant I must admit that I'm still a bit of a techno-geek at heart :) I noticed myself salivating over a colleagues iPad the other day, so I'm still attached to the dark side :) What I'm talking abut here is really a sense of balance and purpose. People aren't machines, and their desires and needs have been built up over thousands of years of evolution long before technology existed. We all need balance in our lives in order to gain a sense of well-being, and our current technology driven society isn't providing that I don't think, which brings me to purpose. Technology is just a tool, its what we do with it that counts. Since the microchip revolution I don't believe we have given sufficient thought to the purpose we should apply all these cheap CPU cycles. Quicker and faster, more with less, isn't a forfilling answer, especially when it ends up turning our lives into one big frantic blur. I guess that's why the iPad is so attractive. It offers a glimpse of a technological future were the medium fades into the background and the content comes to the fore. Alan Kay's Dynabook is with us. Now what was Alan's purpose for the Dynabook again? Oh yes, learning and enlightenment. Lofty ideals, but perhaps we'll get there some day :)