codersnotes

A Swift Step Forward September 10th, 2014

I've been following the progress of Apple's new Swift programming language over the past 4 months since it's announcement.

I have to admit I'm actually quite excited by it. It's common nowadays for people to fling out new languages left-right-and-center, but most of them tend to just re-hash existing ideas and not provide anything new.

But I think Swift actually has the potential to go somewhere. Let's break it down a little and see what Swift gets right and wrong.

It looks like C

Or to be more correct, it looks like JavaScript. It used to be that people referred to a language as having a C-like syntax, but you have to move with the times.

It's a well known fact that every time someone creates a new language, one of two things happen:
  1. They use curly bracket syntax, and the language is a great success.
  2. They use any other syntax, the language is heralded by computer scientists as being the best thing ever created, and then no-one uses it and it dies a slow, painful, and lingering death.
I'm glad to see they made the right choice.

It has native support for lists, strings, and hash tables

Well, that's not exactly surprising, I mean most languages do now. Python does, Perl does, Lua does, C# does, the list goes on. (C being the elephant in the room here). Even C++ does, although having used Python's elegant array slicing makes it painful to have to go back to the STL again.

No manual memory management

And there was much rejoicing.

But none of this really answers the question of why Swift would be a better language than, say Python, for writing an application in. Well there's one extra little feature that almost all modern languages seem to want to avoid nowadays:

It's statically typed

For those who don't follow programming-language implementation, this means that the compiler is able to catch an enormous amount of errors before the program has even run.

I've never been able to understand the love for dynamically-typed languages. The argument is often made that removing typed variables allows the language to be more expressive, but Swift is able to follow Python's lead, allowing simple manipulation of types without any syntactic mess:
foreach i in [1:100]
{
    array << (i*2)
}
Because of it's static typing, that means yes, this is a natively compiled language. No bytecode, no VM. You can ship executables with this.

The only other viable contenders in this field right now are D and Go. D, despite, being a very good effort, has never seemed to quite be able to gain the traction it deserved.

Go however has managed to gain an immediate foothold.

It remains to be seen as to which of the three will win out, or whether a fourth contender will step up. But the future certainly looks very rosy for Swift. Except for one small disadvantage...

It's Apple only.

Yep, OSX/iOS only right now.

But- I fully expect in time this may well change. Either Apple may choose to open-source their Swift compiler, or failing that an open-source project may step up to fill in the gap.

Seeing as Swift's main architect is Chris Lattner, who is the creator of LLVM, and is generally considered to be an all-round good guy in terms of open-sourcing things, I personally think there's a very good chance we'll see an open-source release from Apple within the next few months.

I certainly hope this happens. Programming has spent too long stuck in the crack between C and JavaScript, and the future is crying out for something with the speed of C++ and the ease of Python.

Is Swift the answer? I don't know, but I'm excited to find out.

Written by Richard Mitton,

software engineer and travelling wizard.

Follow me on twitter: http://twitter.com/grumpygiant