7 Swift 2 Enhancements iOS Devs Will Love
snydeq writes: InfoWorld's Paul Solt outlines how Apple has made good on Swift's emphasis on performance, approachability, and ease in its latest update, offering up seven worthwhile enhancements to Swift 2, along with code samples. 'Many of the enhancements to Swift, through both the Swift 2.0 update and subsequent Swift 2.1 update, have made the language more explicit and intentional, and in turns, Swift 2 code will be safer and easier to maintain for years to come (especially now that Swift is open source). New language constructs (keywords) in Swift 2 improve the readability of control flow — the order in which lines of code are executed. Thanks to these new keywords, collaborating on Swift code will be much more productive and efficient.'
Next year the headline will be "Swift 3 Introduced by Apple". Swift 3 is more intentional and safer than ever allowing iOS developers to do more, faster. Swift 3 addresses all the problems with Swift 2 and will be completely incompatible with Swift 2 and the syntax has completely changed. Swift 2 support is dropped as it is now obsolete.
In the code example, the dude's using something called "guard" like an if statement (e.g., "if argument is shit, return null now, mofos" is written as "GUARD argument is shit, return NIL now, mofos").
>> The do/while loop is now the repeat/while loop...it goes against the convention of established languages like Objective-C, JavaScript, C++, and Java.
>> The do keyword has been repurposed to create new scope, unlike every other popular language that uses it for loops.
The only rational reason I can see for these kinds of hostile changes would be to DECREASE the ability of programmers to port code between Apple and non-Apple platforms.
How far the mighty have fallen. Now we are plucking click-bait titles from the yellowest pages of the web. Did the new managment fire all human staf and program the bots to spit out random stuff that fits a particular template:
Who wants to read about [N, where N is less than 10] [insert a noun here] that [insert a reference to a group that the reader would identify with] would [love/hate/be shocked with/never new about/should have known about/must read]
The author clearly has no idea how other languages work and instead repeats multiple times "Apple has worked hard to make Swift good for everyone by..." and then doing what has become more or less common practice in programming, but attributes it to Apple. In other words, a good Apple fanboi.
That said, there is some good thinking, like with using "repeat" as keyword instead of "do" in "do..while" contexts. But wtf is "guard"? The article doesn't explain how it is different from just an ordinary "if". Also, they decided to reinvent exceptions, and did it poorly again. Yawn. Welcome to the club.
(Still, no reason to use Swift if you have the option to go with Ruby instead.)
The most critical thing to understand about Swift is that it's rendering Rust completely obsolete.
Rust was trying to fill the niche between C and C++ on one side, and C# and Java on the other. Rust wants to be low-level, but it also tries to be high-level, too, and without the VM baggage that Java and C# bring.
But now Swift has come along, and it fits much better than Rust does. Unlike Rust, Swift is a developer-friendly language. It's not there to force an ever-changing "right way" on programmers, like Rust tends to. For example, Rust's supporters tell you that "inheritance is bad, you should use composition" even when the tool you need is inheritance, and if you question them they essentially tell you to fuck off. Swift, on the other hand, provides real OO, and it's a pleasure to use.
Now that Swift is open source and is going cross platform, the few benefits of Rust are dwindling away to nothing. It's even more important to note that Apple is backing Swift, while Mozilla is backing Rust. As anyone who follows the industry knows, Apple is wildly successful and innovative, with a bright future ahead of it. Mozilla, on the other hand, has been struggling lately. Users are rapidly fleeing Firefox, the only real product Mozilla has these days. Mozilla has also had its share of internal turmoil, especially with how the best CEO Mozilla ever had was forced out merely because of his beliefs about marriage, of all things. I have much more faith in an Apple-sponsored language being around in 5 or 10 years than I do in Mozilla itself surviving that long.
Mozilla, if they have any sense, would strongly consider dumping Rust in favor of Swift. Swift is the language they need for their Servo browser engine, even if they don't realize it yet. Swift is the future, and Rust is a failure.
Letters I and F have sharp and thus ugly corners, making the word IF ugly.
G and D on the other hand are rounded and smooth on the outside, making the word GUARD beautiful and stylish.
In the next iteration all words will have round corners and will be white.
Mit der Dummheit kämpfen Götter selbst vergebens
When posting a story about some obscure software that nobody has heard of, how about a short description of what the heck it is? Readers should not need to break out Google to understand what you're talking about. This was covered this in Journalism 101.
And in Turns? WTF is "and in turns"???
Can somebody please fix the modding of the parent comment? It should not be -1. It's on-topic, it's relevant, and it's one of the most informative comments posted so far. Maybe it offended some Rust fanboi, but that's no reason for it to be modded down.
whipslash, if you're reading this, that comment is a great example of how the moderation system here is broken. Good comments like that should never get modded down. That's why the mod system here needs some serious reform. We should at least know who modded that comment down, for example, and there should be a process put in place so that that person never moderates here again. We shouldn't let angry Rust fanbois ruin Slashdot like they ruined Hacker News, Reddit, and Stack Overflow.
I just wrote some code to parse a colon delimited text file in Swift 2. It took maybe 25 lines when it might have been 5 to 10 in anything with a modern string library. Now I know this is really a problem in the libs not Swift itself, but it goes to show store if the problems you have using it in the real world. So I went to SO to see if someone had a better solution and I got a responce that was one line using the map and similar features. Which really man there's a lot of power that might not be obvious to us old obj c hacks.
Make a fart app!
It is expected that Slashdot readers know the names of any top 20 programming from Rust to Go to Swift.
If you don't, why are you here? You don't even have a high user id in the 3m to 4million range.
Do you like --- not ever read the articles here or something? There are usually 3-6 Swift topics a month.
Apple have tossed out a compiler and a very rudimentary stdlib. I'm sure it ticks a box but it's not a practical language that people can use for much.
OH NO It's a story about a language that isn't C, C++ or Perl. SLASHDOTTERS LET US UNITE IN HATE
Swift 3 is having a name change: it's now iSwift. Do more, faster with iSwift. Code! iSwift. It's magical, iSwift! Bring magic and buzzwords to end uers with iSwift! iSwift can do it all! Faster! Sleek! iSwift! Magical! User friendly! No more text interfaces for coding! iSwift! intelligent! iSwift secure! Do more, iSwift! Now supporting Retina! iSwift! Brushed Aluminium! Unibody iSwift!
"control flow — the order in which lines of code are executed"
Well, thanks for explaining control flow to us. Who knows, maybe there is someone here who cares about programming languages and reads news about iOS devs, and yet somehow has no clue about control flow.
Actually that would probably be a prolog programmer, come to think of it. But even then...
Swift has had source-breaking changes with nearly every version change...
What Swift ALSO has, is a migration tool built into Xcode to upgrade to new versions - so when you feel like Swift has moved into production, you run the migration tool and spend perhaps an hour or so fixing any other issues you find.
Swift has shown that languages of the past have been WAY too afraid of messing with syntax as the language changes, because it's not nearly as big a deal as it would seem.
"There is more worth loving than we have strength to love." - Brian Jay Stanley
and you can do multiple optional unwrap..
That defer keyword looks like the mother of all hidden bugs. If you end up finishing a statement, not in the way you intended, and all of a sudden resources are getting cleaned up before you used them. I'd stay away from that one.
I get introducing repeat to replace do, but at the same time giving do a different meaning than the rest of the languages! There will be no end to confusion over that.
Solt misses entirely the correct usage of guard. When I read the article, the guard made no sense. This was my first exposure to Swift.
I did a search on "guard swift vs if" and found natashatherobot post on this topic.
Much better technique for guard: localized error handling vs Solt's technique that creates an invalid object to signal an error
Language stability is a very big deal if you've got a sizable body of code
That's my point though; it's really not.
I'm working for a client who moved to Swift at release. At this point we have a LOT of production code in Swift, and this is all heavy database and UI code (for an enterprise app). This is not simple stuff, nor simple code...
But the language migration has caused as most a handful of hours of work over the last year or so. Much of that is because of the migration tool, without that it probably would have been more but I don't think it would have been a huge amount more. After all, we have a lot of modern tools for dealing with changing text in batch across a large codebase.
Languages forever have treated syntax as something they simply cannot change, compounding mistake after mistake of initial design because they are too afraid to break existing code. I'm here to say that fear is overblown, and more languages should not be afraid to re-work terrible syntax to make the language better.
I suppose if you're banging out the latest iOS app in six or twelve months
The app i"m on currently has been around for about five years, so no.
I've worked for many large companies with many large and very old codebases so I'm acutely aware of the need to worry about maintainable code. It's just that it turns out worries about language changes are mostly unfounded in terms of being an undue amount of work.
"There is more worth loving than we have strength to love." - Brian Jay Stanley
Guard has the nice side effect of turning an optional into a non-optional, so that you can use a value through a whole method without having to unwrap (or worse, force unwrap) it.
without requiring the code-by-convention Disposable implementation
Frankly that sounds a lot clunkier to me than just having a nice defer block.
"repeat/while" is retarded and an unnecessary change away from well-known and accepted language conventions.
I don't know how long you've been programming but over the years I have run across times where I wanted to run through a loop at least once before checking the end condition, and had to contort a variety of things to accommodate a check at the top of the loop... I hardly think such a useful tool is retarded, when is serves so well in a specific niche.
Protocol extensions are nice, and are probably going to be quite useful in keeping your code readable. C# has had extension methods for a while now
They aren't really the same as extension methods you are talking about, because protocol extensions allow for default implementations that get overridden... both Swift and ObjC have had extensions on classes forever.
Swift protocol extensions are more like C# Abstract Classes. But you can have a class declare conformance to multiple protocols and so gain all of the methods from each, and furthermore you can in an extension on a class make any class implement a protocol and thus gain default protocol implementations...
"There is more worth loving than we have strength to love." - Brian Jay Stanley
Honestly, Slashdot, this is is the type of headline that I'd expect to see on my Facebook feed... PS. secretly hoping the use was ironic
...there is a build system capable of compiling and linking 100E9 lines of code in the course of a year. I sincerely doubt this.
Comprendre ?
Just claim you have those 5 years, even if in truth it is just two. Two years is already lots of Swift experience, especially if you have 10 years of real C or C++ experience.
..under rock, a$$.
I do not know who CmdrDumbo is and I also disagree with your analysis.
For reasons of future operational success I will not be bragging here about specific missions. But you can be assured SD posts HAVE EFFECT.
After all, most visitors are in the "information business". Quite a few people can look through the BS. As soon as correct and novel information is published here, it WILL disseminate and it WILL have effect.
Many sites will censor unpopular views, even if they are 100% factual. Because you cannot offend those so-and-so-people-and-religion etc. SD will reliably moderate those to -1, but the professionals won't care about that. -1 is often a sign of quality :-)
It was the then-CTO who was sold on the idea of memory safety by a guy from a different continent using good old email.
He said he will stop criminal action as you described it.
Actually it would be very easy to haul said recruiters in front of a court and slap a massive fine on them.
But that requires a government who is not bribed blind and mute by some national and international billionaires.
I am sure that would be "fascist" in the lingo of Cultural Marxists...
No. They're open-sourcing their entire Foundation framework alongside it.