Archive for February, 2009

How do you talk about Scala?

Saturday, February 28th, 2009

I gave a talk about Scala at Last.fm last night (It’s not online: not on Last.fm. At. I physically walked over to their offices and gave the talk to some of their devs).

Depending on how you look at it, it either went moderately well or was a complete disaster. People seemed interested, and went away knowing more about Scala than they came in with, so that part went well. The big issue is that I never actually talked about the subject I went in prepared to talk about. Oops.

I think part of the problem is that I aimed the talk at slightly too high a level. The talk I had designed was about testing with ScalaCheck, as that’s a pretty nice distinguisher of Scala from most of the other JVM languages – it’s something that really takes advantage of the type system in powerful ways, but isn’t too scary. I went in with a set of code I’d already written and was going to live code the tests for it. I still think this would have been a good talk, but I think it would have been a much better second talk on Scala than an introduction.

What happened instead was that we very quickly got diverted onto basic questions of syntax and semantics, and ended up touring Scala through the interpreter and performing a sort of general Q&A about it. This worked reasonably well (at least partly because Miles joined in and backed me up on some of the questions. Thanks, Miles), and would probably have worked even better if I’d come in with a couple small examples to demo this way. So maybe there’s something worth refining in there – certainly the “Here’s the interpreter. Let’s talk about code” model seemed like a pleasant one.

But I feel the talk still sortof missed the mark. It wasn’t a bad introduction to Scala, but it wasn’t a good “Here’s why you should use Scala”. And I’m still not sure how to do one.

The traditional way to present Scala seems to be to present it as a better Java. “Here’s an example in Java. Let’s translate it to Scala. Oooh, look how much shorter it is!”. This seems to go pretty well from what I’ve heard reported. But I have a couple problems with it: Some philosophical, some practical.

The biggest one is that the JVM is not short of languages which are better than Java. I don’t consider the question “Should I use Scala instead of Java” interesting. The answer, as far as I’m concerned, is obviously YES. Except for a few remaining interoperability issues I don’t consider that there’s any good reason to use Java these days (Disclaimer: The one exception I grant is in creating other JVM languages which you don’t want to be burdened with the Scala standard library on top of your language’s runtime). The interesting questions are “Should I use Scala instead of Clojure?” or “Should I use Scala instead of JRuby?”.

And here’s the thing: Rewriting a simple Java example in a better language looks exactly the same with almost any nicer language. You do a straight port, you find opportunities to introduce some functional programming, maybe you take advantage of sequence comprehensions or such like, etc. but basically what you end up with is the original program with a terser syntax and a few obvious abstractions factored in. It’s really not that exciting, and it doesn’t sell the language well. It might, if you’re talking to a group that has no experience of other languages (I wasn’t), but even then you’re basically playing on your group’s ignorance rather than making a compelling argument.

There are a bunch of neat things in Scala that could be used as a compelling argument: Scalacheck, actors, parser combinators, pattern matching in general, etc. but I’m not really how to go from zero to a full fledged example in one of these in only an hour. Perhaps if (rather than starting from a blank slate like I did) I started from a pre written example and disected it, but I’ve no idea if that would work any better.

So, what have you done? Did it work? Any ideas for how to do it better?

Spam

Tuesday, February 24th, 2009

I recieved the strangest message earlier.

“HOt SlutS will be begg1nG for your cock!!!”

Well, yes. I suppose they could be. But it would be a bit childish, don’t you think?

Anyway, I tracked it down to an old archive machine. It seems it had been purely in monitor mode, but through some bug or malice had started forwarding messages from its data source. Rather odd ones, but that in itself wasn’t so remarkable.

Still, it was curious, and I had a few minutes spare time, so I thought I’d investigate further.

It seems it was a very old archive machine, hooked up to the most marvelously archaic setup. A few million ancient computers scattered across the planet, all connected up together with fiber optics. They must have been decades old. I’d never seen the like.

It seemed mostly to be concerned with sending text like the above amongst itself. There were a couple common variations – something to do with “viagra”  or “cialis” (perhaps they were the same thing?) appeared to be the most common theme, but “amateurs” featured frequently as well.

Each piece of text would be sent from one machine to many others. Sometimes it would stop there, sometimes it would be forwarded to another. Occasionally the same mail would be passed on to further recipients. More often it would simply sit there, eventually getting deleted.

It was all very peculiar. I couldn’t quite see the point of it to be honest. Clearly some sort of laboratory experiment someone left running and forgot about. I suppose it might be interesting to some people – there’s no accounting for taste.

Anyway, I took a backup of the whole thing and then shut it down.

It wouldn’t do to let this sort of thing get out of hand after all.

Planet Scala now running on venus

Sunday, February 15th, 2009

And boy is it getting dehydrated.

Ahem. Sorry.

I’ve moved planet scala to run on Venus, the successor to planet-planet. This should fix some bugs we were seeing with post titles getting mangled for some feeds. Unfortunately it may also cause your feed reader to go crazy and report a bunch of stuff as new which isn’t. That should be a one off thing though.

That is all.

New site design

Friday, February 6th, 2009

As you might have noticed if you don’t just come here via the RSS feed, I’ve spent the last day or two redesigning my site (with a fair bit of help from Victoria). The old layout had started to piss me off – the sidebar always either looked too small or too cluttered whatever I put in it, and the lack of definition for the posts made everything look a bit amateurish.

Which is not to say the new look is a miracle of modern design either, but I’m a lot happier with it.

If you notice any bugs with the new version (stuff I’ve forgotten to update, browser bugs, etc.) please let me know. Particularly those of you using IE (that is, IE7+. If you’re  using IE6, get yourself a real browser), as I’ve only tested on firefox and konkeror (the latter is usually bug compatible enough with Safari that I’d expect it to work). Feel free to suggest any visual improvements as well, but I’m more likely to ignore those. :-)

Not really LÖVING it

Sunday, February 1st, 2009

So I spent yesterday playing around with LÖVE, a really cute little platform for writing 2D games. It got linked on reddit on friday, and it looked neat so I thought I’d give it a try.

As you can tell from the title, this is not going to be a very positive post. So in order to brighten the mood I’m going to start by saying positive things about it:

  • I’ve been saying for ages that I wanted to play around with creating little games. I’ve never gotten around to doing so. LÖVE made it sufficiently easy for me to get started that I no longer had an excuse for not doing so.
  • It’s really very good at getting all the annoying cruft of creating a basic game out of the way.
  • I had a lot of fun playing with it.
  • I’m really glad I gave it a try, and if you’ve never written a game before and want to, you probably should too.

Also, the website is adorable.

Unfortunately, that’s about where the positive side of things stops.

First off, the biggest problem with it is that it’s really unreliable. It will sit on a CPU and eat 100% of it, for even the smallest of games. It seemed very crashy – on my work PC it tended to randomly crash other applications. People who tried to play my games said that it seems to crash itself and other things when you try to close it (this was under both macs and windows. I never had this problem under linux). Between these two factors I’d basically never consider it for a real game. Hopefully both will be fixed at some point. (Yes, yes, I know, open source, I should look into it. Unfortunately it seems to be written in C++, which I have approximately zero interest in writing).

The other major problem with it is that it’s actually not very powerful. What it basically comes down to is an infrastructure for loading files, an ok graphics API and fairly basic physics and sound APIs (there’s also an animation API which I didn’t bother to look at. It may be better than the others, I don’t know). So although it helps you get started it doesn’t really do much for you once you have.

As an example to illustrate the above: I had a bit of a play with the physics engine. Basically I created a green square that could jump about (he’s a very abstract representation of Victoria’s very abstract representation of a frog). That worked quite nicely – he could jump, he could move from side to side, he could land on stuff.

The point at which it stopped working nicely was when I wanted him to not be able to jump while already in mid air. See, it turns out that the physics engine has no way (or rather no way exposed in the API) of detecting if two bodies were in contact, so I couldn’t easily detect if he was on the ground or not. I asked in #loveclub on freenode (a much less dubious channel than the name might suggest), and various things were suggested. The best idea I encountered was checking vertical distance from the point of contact. This unfortunately proves to have a bunch of problems as well. The method I eventually settled on was that he could only jump if his vertical speed was already zero (actually, < 0.001) and hope that the player’s reactions weren’t good enough to jump during hang time.

At this point I more or less decided I’d had enough of the physics engine. I went back to the first game I’d made, turned it into something that was actually a proper game (it hadn’t previously been possible to lose. Now it’s only really hard to lose) and declared myself all out of LÖVE. It was a fun little encounter, and I do hope they do well, but unfortunately I’m not really left with any desire to use it.

If you want to check out the code I wrote for this, it’s available from the github repo. Be warned though: It’s really bad. It started out slightly crummy because I was just exploring the API, and then in that last “right, let’s get something actually playable” push I started factoring things out nicely before I realised that I was never going to touch the code again and just brutally copied and pasted and hacked until it worked. I should also warn you that the games themselves are correspondingly lame. :-)

(As an aside, also in that repo are today’s experiments at recreating something like the Love API but more reliable and/or powerful in Scala. But more on those later)