Tuesday, June 10, 2014

Swift - for a Scala Developer

Reading through the Swift programming language book was pretty familiar for a Scala developer - loads of the stuff I'm used to using every day is there: Options, Type inference, Types (including bounds), closures etc.

I have to say, that some of it is a bit clunky though (I realise this is the first version of Swift, so these things will likely improve, and that there might be some short cuts I haven't discovered yet)

For instance:

if let unwrapped = someOption {println(unwrapped}

vs.

someOption map println

OK, so that's super-compressed scala

someOption.map((unwrapped)=> println(unwrapped))

is a better direct translation

I think the reason this syntax particularly jarrs is that further on in the book it's specifically mentions that assignment operations don't return anything, so you can't mistakenly use them when you meant equality - yet here, let is returning a boolean.

I haven't started coding properly with Swift yet (or even made it to the end of the book), but already it's very familiar, with the playground being an improvement on the Scala REPL. I'm really looking forward to writing my first iOS apps.

No comments:

Post a Comment