When the Apple introduced swift, it was like WOW! Finally we get the real next-gen (mean trendy-scripty) language for i-devices development (but without private class members, hmmm...). Well now this [squareBracketsDinasour language] can be sent to the museums, and we've got all this shiny new features. Of course we shouldn't be naive: the new language has to live some time to get well enough after children diseases. That's why i didn't started rewriting all my stuff using Swift just after announcement.

      (did you notice, that this bird is falling down?)



A year later, i finally decide to learn it. To do it i started writing a small game about the most horrible thing in the world (in the world of Window 3.1, ok): the SkiFree monster. You can read about it here.

Disclaimer: i write about one-year old Swift. I'm sure the Apple guys will fix this issues, and the swift will become an elegant tool. Or a hulking hippo, like XCode 7 does.

Back to Swift. After a night, spent with the "The swift programming language" book i was ready to do something cool. The language charmed me by simplicity and transparency of constructions and the hidden power, which allows writes safe code (and yes, they've added private members). I've started writing a SpriteKit game, and...



Are you serious? My 60 000-lines of objective-C code compiles just 2 times longer, than a 600-lines of swift's hello world. I suddenly remember those beautiful days (just a four months ago, actually), when i was working on very huge project, and this picture precisely describes some of my days:



This non-doccumented feature of swift was very uncomfortable for me: since i was developing a little game, i used to change some hardcoded constants and little parts of logic in a very frequent way. Thus every change made me recompile the code. I know, that there was a dozen of ways to solve the issue with constants like moving them to some config files or creating in-game menu for change it, but all these require additional steps, but i prefer focusing on main mission: creating the simple fun game.

Well, after all the human being can get used to anything, but the compiler confused me again:



Well hm.... Can't sum up two floats... Okey....

For those of you, who are sharpening the knifes to teach this code-monkey to not use hardcoded values and not mix the floats and doubles, i want to say: first of all - all this CGFloat's came from UIKit, but doubles come from 3rd party code. And there are a lot of situations, when you have to deal with that. Moving hardcoded values into constants can improve the code, but it doesn't matter, when we talk about compiler's behaviour: and it's behaviour is a something special! Of course this little scamp can sum two floats! But he hides from me the real issue.

You know i always treat compiler as an kinda old wise Gandalf, who explains the little hobbits, how everything works.




Yes, sometimes it's really hard to understand, what's this old buddy talking about, but at least he don't lie to us, and after time we see the wiseness in his words.

But the compiler, who tells, that me about floats issue, is more like this junkie from the Hobbit movie.



After a black mess with the code, it started working. Here is fixed:




I didn't save every single error like that during the development, but this one is nice for illustration, i suppose.

Another problem, which is related to the first one - is the low speed of statical analysis in compare to objective-c. There was a time, when i turned off the live syntax errors highlighting in XCode, because i used to write code much faster than this analysis is done (Man vs machine: 1:0, ho-ho), and the laggy information just annoyed me. Since i get a new mac the analysis is done almost immediately, and i turned on this feature with pleasure. But in swift i see the same issue (2:1. Man wins).

And now i would like to introduce you the gem of my collection:




I've seen a lot of things in my programming live...
I've seen an compiler optimisations which ruined performance because of inserted 'if (0) { ... }' statement.
I've seen this horrible bugs, related to missed 'volatile' keyword.
I've seen what kinds of destructions can be led by undefined behaviour.

But never before compiler complained to his hard job.


This message would be an extremely useful thing, if it was an warning message. But this is a critical error. So yes, after that you must split your code to the little parts. And i would fully understand this situation if i saw this message for a very long construction - but i had a less than a 120 symbol line. For some of programmers i can looks ok, but i was raised by wolves of C/C++ and x86 assembly languages. So, for me it's very odd.

So what's the bottom line? We have a language, which really looks some kind of Python/Go/Ruby. But what the real reason to start huge project on it?

Generics? Yes, this is very nice, but Objective-C now have generics (ugly, but have). And for example Go-guys says, that they feel quite well without them.

Optionals? In my opinion, this is extremely questionable concept - it's very elegant, when we talk about parameters passing, but can be painful, when we have patterns with a class members, which can be null for long time (for example with lazy initialisation).

Passing by values? Well if you need performance you still can write C/C++. If you you want to use optional values, then yes, in C/C++ the same thing can looks ugly, but still possible.

So, Apple. Honestly, looks like you created language just because the developers laughed about your square bracket ('write code just like in native english', heh) and this YES/NO in boolean. And what is the price for this? Now we have a language with low compilation performance and sometimes extremely weird compiler's behaviour.

Well, the old man said all, he wanted to. But you, trendy-scripty-language-lovers shouldn't take too serious my buzzing: in fact i find swift a very nice language with a good design. All described issues are really minor, because they can be fixed without huge language changes, so once they will disappear. So now Swift is the best language to write Hello world, but now i don't advice you to start a huge project for iOS on swift.