Slashdot Mirror


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.'

123 comments

  1. Next year by 110010001000 · · Score: 1, Insightful

    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.

    1. Re:Next year by thoromyr · · Score: 0

      I'm also not impressed with "guard". The article claims it makes for simpler and easier to maintain code, but I don't buy it. They say it avoids being if/else trees which, if true, would be a good thing. But you can have *simpler* code than "guard" by using if. For example, the following are equivalent:

      guard validate(param) else { printError(); return; }

      if not validate(param) { printError(); return; }

      The "avoid if/else trees" is just a matter of returning from the function early. Guard in no way enables this. Further, the full structure is "guard/else" which separates the keywords while "if not" puts the intention forward immediately.

      If this is a "great" or "must have" feature of swift then... meh

    2. Re:Next year by Kjella · · Score: 2

      I read the first item ("guard" keyword) a couple of times, and I'm still having trouble figuring out what it does that a simple "if" statement doesn't do. It is just syntactic sugar for the if statement, but used to indicate precondition checks? I feel like I'm missing something obvious.

      From what I understand it also unwraps the variable, Swift has int? that can either be an int or nil. If you just use if, you have to force-unwrap it inside the "safe zone" while guard morphs it to a non-nil int type.

      --
      Live today, because you never know what tomorrow brings
    3. Re:Next year by ashpool7 · · Score: 2

      Guard: http://ericcerney.com/swift-gu...

      They've basically said Swift is sorta-beta by not solidifying ABIs until maybe Swift 3. Until then they will make auto-updaters for migrating your code.

    4. Re:Next year by NotInHere · · Score: 1

      In fact you are right. From the swift-evolution repo:

      Swift 3.0 will not provide full source compatibility. Rather, it can and will introduce source-breaking changes needed to support the main goals of Swift 3.0.

    5. Re:Next year by fulldecent · · Score: 2

      The only difference between guard and if ! is that guard requires an exit of some form.

      Practically, as a programmer who is maintaining code, it is very expressive to find a guard. You can immediately scroll down to the bottom past the block and you will understand the preconditions of what your eyes are currently looking at.

      I never use code folding, however guards would be an attractive case to use them. Because it is truly: guard precondition and then the rest does not matter.

      --

      -- I was raised on the command line, bitch

    6. Re: Next year by JadeBurton · · Score: 0

      I agree re figuring this basic stuff out before v1. Actually I wish Apple would save us all the hassle of sharing their experience of "learning how to make a programming language". Buy MS already and take C#, a mature and generally well-regarded language. C# 1 was usable and they didn't make weird fundamental changes constantly afterwards as Apple is with Swift. Making programming languages is kind of a well understood domain, but Swift smells like hipsters fresh out of uni to me, learning from their mistakes as they go.

    7. Re:Next year by Anonymous Coward · · Score: 0

      And recruiters will demand five years of Swift 3 on their mandatory qualifications lists, as they do with Swift 2 right now.

      Can someone explain to me why they do this? I can understand five years of Swift with OpenStack, but not Apple Swift.

    8. Re: Next year by Applehu+Akbar · · Score: 1

      Because all the programming languages were declared frozen for all time after Kernighan & Ritchie. No further innovation will ever occur.

    9. Re:Next year by xxxJonBoyxxx · · Score: 1

      >> Can someone explain to me why recruiters will demand five years of [brandnewtech]?

      In recruiter speak, "experienced" translates directly into "5 or more year of experience with..." and many recruiters don't know how to describe technologies without including the version number. Certainly very few understand how long a technology has been around (and whether 5 years of experience is realistic). And a lot more gets lost in the translation chain from lead team who needs the resources -> manager -> HR -> recruiter.

    10. Re:Next year by Anonymous Coward · · Score: 0

      Swift 4 will be even more intentional, pragmatic and procedural, and reach syntax equivalency with the Microsoft QuickBasic.

    11. Re: Next year by Anonymous Coward · · Score: 0

      Actually, they were already pretty much frozen before then. We already have Lisp, and generally no further innovation in terms of language design will ever occur over Lisp.

    12. Re: Next year by JadeBurton · · Score: 0

      Swift is not a good example of an innovative language. Apple just wants something that is different enough to assist developer lock-in. That's what they used to love about Obj-C: it was resistent to being ported, thanks to its incredibly weird method-calling syntax.

    13. Re:Next year by Logic+and+Reason · · Score: 1

      There are two differences between guard and if:

      • Guard requires that you exit the outer scope somehow in its body.
      • While an if-let binding only exists in the true branch's scope, a guard-let binding becomes part of the outer scope.

      I haven't used them much myself, but guards aren't just a synonym for if-not.

    14. Re:Next year by Megol · · Score: 2

      From the perspective of a C# developer, none of this is terribly ground-breaking, and some of it is downright idiotic.

      "guard" appears to be a "not-if". Pointless. If I want not-if, I'll use if(!whatever).

      Then you fail to understand its usefulness: if is a clear indication that it is a guard(!) and it is easier to read. Some languages have a unless statement which makes code easier to read but this is a statement specific for validating arguments.

      "defer" is a clunky way of copying the "using" block from C#, but without requiring the code-by-convention IDisposable implementation. Useful, but could've been better. At least it has notable improvements over the status quo.

      It is a statement that have uses but can make code much harder to read if used wrongly. The example in the article illustrates that well.

      "repeat/while" is retarded and an unnecessary change away from well-known and accepted language conventions. This is the kind of convention that is actually worth sticking to, and Apple just broke it. "Nice job breaking it, hero."

      Surprise! There are other programming languages than C out there, some of which use repeat ... while constructs. So it isn't breaking anything (well, Swift code but isn't that an Apple standard?).

      "do" is a sign that their language parser developers are lazy and bad at their jobs, because they can't handle a set of curly braces as a start-a-new-scope delimiter. Fire these lazy bastards.

      Easier to read...

      "error" is a goto label. It also converts "do" into try, and "try" into assert(). I guess you've got to call it something, and if you make it too much like your competitor's language, people will be skilled across both! A travesty! And who's with me in thinking that "catch let error as FooType" is clunky as shit? It's as bad as VB. C# has this one right: catch(FooType error) ... and done.

      Again this is something that makes code more readable. By including the fact that a routine can fail in the declaration a lot of problems can be avoided, the requirement of the try keyword on things that can fail is much better than having it hidden from the programmer. Yes going in the direction of explicit error checking have problems but those are IMHO preferable to the alternative (hidden data passing).

      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, and they're quite useful. It's good to see that Apple is adding that sort of thing to Swift, as it can prevent a measure of code rot.

      OptionSetType is the same as .Net's FlagsAttribute. Not special, but, again, a nice addition. It even goes a step further and adds easy bitwise comparison handling for you. Again, good on Apple for taking an existing good idea and making it better.

      What does it do that Pascal's set type doesn't (except being much more verbose)?

      And the last item appears to be an improvement to what .Net developers would call "interop". Any improvements are welcome, as interop is universally a pain. It will never be "right", but it may be tolerable.

    15. Re: Next year by Anonymous Coward · · Score: 0

      It's not the syntax that kept Objective-C from being ported, as you claim. The syntax is pretty minimal. The meat of an Objective-C iOS app lies in the LIBRARIES (Cocoa APIs, etc.).

      Without all those libraries being ported over, who cares if you can compile Objective-C on your machine? Objective-C is the least of it.

    16. Re:Next year by jader3rd · · Score: 1

      I haven't used them much myself, but guards aren't just a synonym for if-not.

      You're right, guard is a synonym for if-not return.

    17. Re:Next year by Anonymous Coward · · Score: 1

      "guard" is primarily used to unwrap optionals into the current scope, rather than creating a new scope like "if" does. (This is safe/doable because the failure case must return or otherwise exit the current scope.) That means multiple unwrappings don't cause you to descend into nested-if hell.

      guard is probably my favorite addition to Swift so far.

    18. Re:Next year by Anonymous Coward · · Score: 0

      So guard is assert(). But then again, so is try. Pick one and stick with it, dammit!

      There's so much wrong with do/while anyway, It's best left to languish in half-supported obscurity as it is. I'll keep plugging away with while and syntactic-sugar-while (a.k.a. for).

      OptionSetType is a bitflag type with operators to match. I'm unfamiliar with Pascal's set type, but it sounds a lot more like it should be a collection (like a HashSet) than a bitflag type.

    19. Re:Next year by BinBoy · · Score: 1

      And recruiters will demand five years of Swift 3 on their mandatory qualifications lists, as they do with Swift 2 right now.

      Can someone explain to me why they do this? I can understand five years of Swift with OpenStack, but not Apple Swift.

      Advertise impossible requirements to Americans. When no American qualifies, you can now legally hire an H1B. https://www.youtube.com/watch?v=TCbFEgFajGU

    20. Re:Next year by Anonymous Coward · · Score: 0

      No, guard is nothing like assert. And OptionSetType IS a collection - it's a set!

      So many comments here from people who have no idea what they're discussing. Certainly it doesn't help that TFA is particularly shitty, but seriously...!

    21. Re:Next year by billDCat · · Score: 1

      From what I see in the documentation, the "guard let" combination is sort of the opposite of "if let". Normally you would have something like this which would both assign destinationViewController to a new constant and would check to see if the result of controller is nil:

      if let controller = segue.destinationViewController { // do something with controller
      }

      with guard you can do the opposite:

      guard let controller = segue.destinationViewController else { // handle a controller that contains nil
            return nil
      }

      You can also use it to check a complete expression for errors. The following will check if someController is nil OR someController.bunchOfItems is nil OR someController.bunchOfItems.count == 0

      guard someController.bunchOfItems.count > 0 else {
              throw MyError.OutOfStock
      }

      The guard statement is used for error management, and must transfer control using return, throw, break, or continue from within the block

    22. Re:Next year by BasilBrush · · Score: 1

      No. The guard statement also allows unwrapping an optional, with scope of the rest of the block AFTER the guard.

      The if statement allows unwrapping with scope of the block IN the if.

    23. Re: Next year by BasilBrush · · Score: 1

      Blah blah blah hate Apple blah blah.

    24. Re:Next year by BasilBrush · · Score: 1

      Nope you are still missing the scope of the unwrapping of optionals. This is also different.

    25. Re:Next year by Goaway · · Score: 1

      Yes, that horrible, horrible Apple. How dare they make their code BETTER!

    26. Re: Next year by macs4all · · Score: 1

      I agree re figuring this basic stuff out before v1. Actually I wish Apple would save us all the hassle of sharing their experience of "learning how to make a programming language". Buy MS already and take C#, a mature and generally well-regarded language. C# 1 was usable and they didn't make weird fundamental changes constantly afterwards as Apple is with Swift. Making programming languages is kind of a well understood domain, but Swift smells like hipsters fresh out of uni to me, learning from their mistakes as they go.

      There's a simple solution: Don't use Swift, or STFU.

      And how many full-blown programming languages have you written?

    27. Re: Next year by macs4all · · Score: 1

      Swift is not a good example of an innovative language. Apple just wants something that is different enough to assist developer lock-in. That's what they used to love about Obj-C: it was resistent to being ported, thanks to its incredibly weird method-calling syntax.

      Right. That's why they Open Sourced Swift. Lock in, that's it.

  2. WTF is "guard"? by xxxJonBoyxxx · · Score: 1

    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").

    1. Re: WTF is "guard"? by Anonymous Coward · · Score: 0

      TRUMP argument is shit

    2. Re:WTF is "guard"? by Anonymous Coward · · Score: 0

      It's like Perl's "unless" keyword, but appier!

    3. Re:WTF is "guard"? by DahGhostfacedFiddlah · · Score: 1

      Came here to ask this. Glad to see it asked, disappointed that there's no answer. The article does a terrible job of explaining guard, making it look like an alias for "if", but it seems there are real benefits.

      (http://stackoverflow.com/questions/30791488/swift-2-guard-keyword).

      It still looks like it provides some benefits, but I don't know Swift that well, so it could be that all the alternatives that come to mind aren't possible or are more cumbersome than I expect. The primary benefit I see is quick assign-and-check for Optionals.

    4. Re:WTF is "guard"? by ecotax · · Score: 1
      As NSHipser describes it:

      guard is a new conditional statement that requires execution to exit the current block if the condition isn’t met.

      You can exit the current block from an if-statement, of course. But it doesn't force you to. Also, having a separate keyword for things like preconditions can make code more readable, because you can express your intent.

      --
      "Money is a sign of poverty." - Iain Banks
    5. Re:WTF is "guard"? by R3d+M3rcury · · Score: 1

      I was going to say, it's sort of like an NSAssert.

    6. Re:WTF is "guard"? by Anonymous Coward · · Score: 0

      Jobs didn't have any 'if's in his management style, so the employees had to guard their asses. That's why.

    7. Re:WTF is "guard"? by Goaway · · Score: 1

      Guard forces you to exit the function in the else branch, and "guard let" introduces a symbol in the containing scope rather than the contained scope.

  3. This looks intentionally proprietary, Apple by xxxJonBoyxxx · · Score: 2

    >> 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.

    1. Re:This looks intentionally proprietary, Apple by thoromyr · · Score: 1

      Holy cow. Those are actually comments from the article pimping this? \me checks. Crap, he's right.

      Now, in Apple's defense, I think their use of "do" reads well and is a nice way to introduce a scope block. I mean, you could just use the curly braces (like C), but I can kinda see the point of putting a keyword there. And repeat/while similarly makes sense. And I don't think the argument that "everyone else does it this way" automatically outweighs other concerns.

      But, damn, to put statements like those in an article *supporting* swift's syntax? Acknowledge that its different? Sure. But phrased the way those comments are, positioned in the article how those comments are, it comes across as hostile. Wow.

    2. Re:This looks intentionally proprietary, Apple by Megol · · Score: 3, Insightful

      I wouldn't run code from a programmer who'd have a problem porting code for that reason! He/she wouldn't be worthy of being called a programmer at all in fact.

    3. Re: This looks intentionally proprietary, Apple by hondo77 · · Score: 1

      Any programmer that can't port because of the "do" keyword should probably go back to writing PHP.

      --
      I live ze unknown. I love ze unknown. I am ze unknown.
  4. 1 title slashdoters will hate by pesho · · Score: 3

    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]

    1. Re:1 title slashdoters will hate by halivar · · Score: 1

      How far the mighty have fallen. Now we are plucking click-bait titles from the yellowest pages of the web.

      Hardly a new development. Dicevertisements were pure click-bait.

    2. Re:1 title slashdoters will hate by mwvdlee · · Score: 2

      7 most painful ways in which the editors should go fuck themselves.

      --
      Slashdot social media options: AIM, ICQ, Yahoo, Jabber and Mobile Text. Why no MySpace?
    3. Re:1 title slashdoters will hate by Anubis+IV · · Score: 2

      Thinking the same thing. We already deal with enough clickbait here, but if we've sunk to the point that we're re-posting those sorts of headlines verbatim, we've hit a new low. Is this what we should expect going forward?

    4. Re:1 title slashdoters will hate by xxxJonBoyxxx · · Score: 1

      I might click on that.

    5. Re:1 title slashdoters will hate by godrik · · Score: 1

      In particular I hate that title because it is completely unclear because it has two numerals in the first three words. "7 pictures of dogs you will love" is fine. But "7 Swift 2 features are amazing" is hard to parse. "Seven Swift 2 features are amazing" is MUCH easier to parse.

      It always amazes me that many people write without thinking of how the text will be read.

    6. Re:1 title slashdoters will hate by Anonymous Coward · · Score: 0

      Not to mention Swift 2 has been available for EIGHT MONTHS and out of beta for five. We're a month away from the Swift 2.2 release and four months away from the Swift 3 beta (and a lot of interesting stuff is happening with 3.0 now that Swift is open source, write THAT article!).

      I don't know how old TFA is because I don't want to give them the clicks, but this is old, old, old.

  5. Such a terrible article by Anonymous Coward · · Score: 0

    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.)

    1. Re:Such a terrible article by Anonymous Coward · · Score: 0

      "repeat... while" instead of "do... while" might have been good thinking if they rolled it out with version one. But now they're changing the "do... while" which swift programmers are already using to "repeat... while", and the "do" keyword is being re-purposed to something else, when swift v1 is already in the wild? Way worse than anything python v3 ever did for sure.

    2. Re:Such a terrible article by Goaway · · Score: 1

      They also have automatic migration tools to fix these things for you. In practice, it is not a problem.

  6. Swift is making Rust obsolete already! by Anonymous Coward · · Score: 0, Troll

    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.

    1. Re:Swift is making Rust obsolete already! by Anonymous Coward · · Score: 0

      Woah, we have an Apple shill day today. Guess Dice is getting desperate huh?

      Swift is in the same league as Go - only the corporation that invented it is going to use it.

    2. Re:Swift is making Rust obsolete already! by jcr · · Score: 1

      Woah, we have an Apple shill day today.

      Why would an Apple shill care about Rust? The only impact it has on Swift is the occasional question that comes up on the swift-evolution mailing list, like "should we add this feature that Rust has?"

      -jcr

      --
      The only title of honor that a tyrant can grant is "Enemy of the State."
    3. Re:Swift is making Rust obsolete already! by Anonymous Coward · · Score: 0

      Dice sold Slashdot, dipshit!

      And there's no "shilling" going on here. Why the fuck would any company pay to try to influence the opinion here at Slashdot, of all places?! There's next to no audience here. They'd be better off spending a small fraction of the amount buying an AdWords campaign.

      It makes you Rust supporters look really desperate when instead of admitting that your language is flawed and obsolete, you start with your false accusations of "shilling". At least you didn't falsely accuse anyone of violating Rust's Code of Conduct, I suppose!

      People like Swift because it's already a very good language, and better than Rust will ever be. Many people are using it to make software for iOS and OS X, and soon they'll be using it to target other platforms, too. The only people using Rust are Mozilla, and the Ruby hipsters who try it out for a weekend and put their incomplete library code on GitHub to rot away.

      Apple doesn't need to pay anyone to promote Swift. Swift basically promotes itself by being a damn good language.

    4. Re:Swift is making Rust obsolete already! by NotInHere · · Score: 1

      I don't believe that apple will want swift to grow outside of the apple walled garden.

      The main reason for using swift is that apple wants their developers to be locked in, on a language level. Their applications should be re-written from scratch if they want them to run on android or other plaftorms. They always went a different path to ensure this kind of lock-in. And they even found imitators, Google basically did this when they introduced java based apps.

    5. Re:Swift is making Rust obsolete already! by jcr · · Score: 4, Insightful

      The main reason for using swift is that apple wants their developers to be locked in, on a language level.

      Oh, for crying out loud.

      The reason for Swift is that Apple is highly aware of where they spend their engineering time, and Swift makes the most common Obj-C mistakes difficult or impossible to write at all. It's not some kind of Machiavellian plot.

      -jcr

      --
      The only title of honor that a tyrant can grant is "Enemy of the State."
    6. Re:Swift is making Rust obsolete already! by NotInHere · · Score: 0

      True, swift had been heavily influenced by Objective-C. Swift now serves the same goals Objective-C served, namely adding lock-in. It basically ports the improvements rust brings to the C++ world over to the Objective-C world.

    7. Re:Swift is making Rust obsolete already! by Anonymous Coward · · Score: 0

      Why the fuck would any company pay to try to influence the opinion here at Slashdot, of all places?! There's next to no audience here.
       
      Because 10 years ago some site had Slashdot listed as one of the most influential tech sites on the internet. CmdrDumbo and his crew played on that for years to come and there are still some braindeads out there who still think that Slashdot is relevant.
       
      Odd that they haven't noticed how much this site bled users between the endless political jabbering, Beta and Dice. Now Slashdot is a hollow shell of its former self but we still have people who like to think that they're being insightful and their voice is being broadcast across one of the most respected sites on the net. The reality is that they're pretty much in an echo chamber with about 10 other big mouths who claim to be on top of everything but still have time to post a few dozen times a day about nothing but their opinion. Slashdot's real claim to fame was being able to take down sites by having tons of people bombard a webserver that normally was hosted on an old 486 in some guys basement. I can't even recall the last time the "slashdot effect" was felt anywhere.

    8. Re:Swift is making Rust obsolete already! by Anonymous Coward · · Score: 0

      Where to start with your declarations?

      "Swift now serves the same goals Objective-C served, namely adding lock-in." Such ignorant B.S. Apple uses Objective-C because THAT'S WHAT THEIR OS WAS WRITTEN IN, HAVING BEEN WRITTEN 30 YEARS AGO. Recall the name NextStep? That was the computer company headed by Steve Jobs in the 1980s after he got fired from Apple. This next-generation machine's OS was written in Objective-C because C++ was just starting out at that time. Objective-C was already the mature object oriented language that C++ would not become for many years. When Steve came back to Apple many years later, Apple desperately needed a replacement OS for their aging, flaky, obsolete Mac OS. They purchased NextStep to use as that replacement, and it was all written in Objective-C. This is why Apple to this day uses that language. No other reason. Are you telling me that Apple should've chucked it all in the bin and rewritten it from scratch in C++? For what? Get real.

      As for "swift had been heavily influenced by Objective-C", well, I would hope so, since iOS is written in that (at least the high level APIs), so for interoperability, Swift must "play nice" with Objective-C.

    9. Re:Swift is making Rust obsolete already! by Anonymous Coward · · Score: 0

      LOL I'm pretty sure I said Ruby, not Rust. Not like I'd expect you to read what you're replying to though; been here long enough.

      It just seems so petty and un-news-for-nerds-worthy to bicker about how a shit language is better or worse than a single corporation language uses.

      Swift is not a bad language (and neither is Rust), but in the grand scheme, no fscks will be given. Neither is going to be the next Java, JavaScript, C# or C++. C# really only took off after it stopped being a Microsoft only language - and all these years it's been a dang fine language I daresay - and so as long as Swift is something only Apple uses, it's not going to grow past that walled garden. So from a more practical perspective, real languages will be picking up what Swift is going to get right.

    10. Re:Swift is making Rust obsolete already! by schlachter · · Score: 1

      not to mention it was their developers themselves who came up with Swift and pushed for its usage...not some CEO decree.

      --
      My God can beat up your God. Just kidding...don't take offense. I know there's no God.
    11. Re:Swift is making Rust obsolete already! by Trailer+Trash · · Score: 1

      I don't believe that apple will want swift to grow outside of the apple walled garden.

      The main reason for using swift is that apple wants their developers to be locked in, on a language level. Their applications should be re-written from scratch if they want them to run on android or other plaftorms. They always went a different path to ensure this kind of lock-in. And they even found imitators, Google basically did this when they introduced java based apps.

      Right. And open-sourcing swift is just part of this nefarious plot that you've uncovered.

      How, I don't know.

    12. Re:Swift is making Rust obsolete already! by Anonymous Coward · · Score: 0

      And to top this off, they made it open source. And not just the language, but Apple's Foundation framework, too. It's the polar opposite of lock-in.

    13. Re:Swift is making Rust obsolete already! by Goaway · · Score: 1

      I don't believe that apple will want swift to grow outside of the apple walled garden.

      Yes, this is why they are porting it to Linux. Because they don't want people using it on Linux. This makes perfect sense.

  7. IF is an ugly word. by denzacar · · Score: 5, Funny

    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
    1. Re:IF is an ugly word. by MagicM · · Score: 2

      Quite true. While "if" is an awful, tinny word, "guard" is nice and woody. You can't beat wood.

    2. Re:IF is an ugly word. by Anonymous Coward · · Score: 0

      Mod point goooooone.

    3. Re:IF is an ugly word. by s122604 · · Score: 1

      Guard has warmth and complexity, IF is digital and antiseptic

    4. Re:IF is an ugly word. by david_thornley · · Score: 1

      Rats. I was going to say that you can already program with white characters, but the official site for the Whitespace language is not responding. I don't know if it's been taken down or if there's a temporary problem.

      --
      "When you have eliminated the unacceptable, whatever is left, however improbable, must be the truthiness" - Holmes
  8. Dear Slashdot Admins by sunderland56 · · Score: 0

    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.

    1. Re:Dear Slashdot Admins by Anonymous Coward · · Score: 0

      They want you to click the link. Any form of explanation would conflict with this goal.

    2. Re:Dear Slashdot Admins by Anonymous Coward · · Score: 0

      Well, in fairness you're obviously not a professional programmer. Swift has been out for over a year and it has been impossible to not hear about it in the technical press. You might find visiting tmz.com or huffingtonpost.com instead of /. to be more toward your liking.

    3. Re: Dear Slashdot Admins by Anonymous Coward · · Score: 0

      bingo. the shitlobbers are out in full force.

      logicall, that implies swift is a great language and some well fundee entity wants to discredit it.

  9. and in turns? by Anonymous Coward · · Score: 0

    And in Turns? WTF is "and in turns"???

  10. Can somebody fix the modding of the parent? by Anonymous Coward · · Score: 0

    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.

    1. Re:Can somebody fix the modding of the parent? by Anonymous Coward · · Score: 0

      The comment literally contained no substance other than: "Rust sucks rust suck rust sucks whaaaaa whaaa whaaaaaaaaaaaa why aren't more people using Swift instead?" Makes me wonder if the retard Swift developers that ripped off Rust are getting antsy that people are more interested in the real language instead of their counterfeit crap.

  11. And then there's stribgs by Anonymous Coward · · Score: 0

    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.

    1. Re:And then there's stribgs by Anonymous Coward · · Score: 0

      Delimited text files are not easy. I wrote a CSV (character-separated values, not comma-separated values) file parser in C#, and it is most definitely not 5 to 10 lines of code.

      There are 3 special characters you have to watch for: The delimiter, the encapsulator, and the terminator. The delimiter should be a single character, always. The encapsulator can be a single character or a pair of matching characters (like parentheses, brackets, or curly braces). The terminator is a sequence of one or more characters (think "\n" for Unix-style line terminations vs. "\r\n" for Windows-style line terminations).

      What happens if your fields are not properly encapsulated? If the starting encapsulator is present, but the ending one is not, you're hosed. But if it's the other way around, then you might not have a problem at all.

      There are about a million other corner-cases to watch out for. CSV is not easy. It's deceptively simple, but not easy.

    2. Re: And then there's stribgs by Anonymous Coward · · Score: 0

      The problem in Swift is that the indexes in the string are private. You cannot do something like find a string writhing a string and then add one to the index. That's because they don't return an index but a Range. Want to advance by one compared to that? Ok, use advanceBy on the startindex of the range to get an Index object then make a new Range with that index. All of this is rediculous, every other modern language uses ints, and Apple simply hasn't exposed the API.

    3. Re:And then there's stribgs by Anonymous Coward · · Score: 0

      CSV is not easy. It's deceptively simple, but not easy.

      And in your description you forgot to handle the escape character and/or lack of escape character (either \" or "" = " )

    4. Re: And then there's stribgs by jcr · · Score: 1

      Swift doesn't limit its strings to ASCII characters, and moving from one character to the next in a unicode string isn't as simple as ++.

      -jcr

      --
      The only title of honor that a tyrant can grant is "Enemy of the State."
    5. Re: And then there's stribgs by BasilBrush · · Score: 1

      Every language that is indexing into Unicode string is not handling composed characters correctly.

  12. Quick! by Anonymous Coward · · Score: 0

    Make a fart app!

    1. Re:Quick! by Anonymous Coward · · Score: 0

      Only LUDDITES use their ANUS to fart. Modern app appers use apping apps to fart!

  13. How are you geek? by Anonymous Coward · · Score: 0

    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.

  14. Open source doesn't mean much in this case by DrXym · · Score: 1

    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.

  15. **GASP** IT'S NOT C / C++!!! by Anonymous Coward · · Score: 0

    OH NO It's a story about a language that isn't C, C++ or Perl. SLASHDOTTERS LET US UNITE IN HATE

  16. Introducing iSwift! by mlw4428 · · Score: 1

    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!

    1. Re:Introducing iSwift! by Anonymous Coward · · Score: 0

      You've got a Taylor Swift song right there.

  17. News for nerds? by johannesg · · Score: 1

    "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...

  18. That's been true all along by SuperKendall · · Score: 1

    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
    1. Re:That's been true all along by Dutch+Gun · · Score: 1

      Language stability is a very big deal if you've got a sizable body of code, say a few hundred billion lines or so that have been written, bugfixed, and hardened over the past few decades. It's something that people with very large investments in very large code bases that are maintained for a long time tend to care about.

      I suppose if you're banging out the latest iOS app in six or twelve months the stability of the language isn't as big of a deal. Nothing wrong with that, but you have to remember that different developers and different projects value different things in their programming languages.

      --
      Irony: Agile development has too much intertia to be abandoned now.
    2. Re:That's been true all along by Anonymous Coward · · Score: 0

      When they announced Swift nearly 2 years ago, they specifically warned that they intended to rapidly evolve and for the next two years there'd be no ABI or source compatibility between releases. If you could put up with that, Swift is great. If you couldn't, Objective-C is still there (and has actually inherited a number of improvements from Swift). Swift 3 is intended to be the final big, breaking release at the 2-year mark (which is why they're cramming as many necessary core changes in as the community can think of), and things should settle after that point.

    3. Re:That's been true all along by Anonymous Coward · · Score: 1

      ... if you've got a sizable body of code, say a few hundred billion lines or so that have been written, bugfixed, and hardened over the past few decades.

      If you have written a few hundred billion lines of high quality Swift code over the past few decades, you have just the experience my employer is looking for.

    4. Re:That's been true all along by Dutch+Gun · · Score: 1

      Fair enough. If they warned everyone ahead of time that they'd be making breaking changes to the language, then that's not quite so bad (I must have missed the memo). And of course, the inclusion of migration tools certainly helps to mitigate whatever minor pain is involved. It's just that I tend to view those sorts of changes as the hallmark of a beta product - one still below the 1.0 release threshold. I guess that's what happens when version numbers don't mean what they've historically represented anymore. It confuses old-timers like me.

      I recently began porting my project to OS X (and will eventually do iOS as well), so I had to pick up Objective-C. Swift looked interesting, but didn't work for me because it couldn't as easily interop with my native C++ libraries. So, yeah, of course... there's no way that Apple can abandon Objective-C anytime in the near future either (as some have speculated), because again, a lot of people have a very substantial investment in Objective-C code as well.

      --
      Irony: Agile development has too much intertia to be abandoned now.
  19. Guard force you to exit the scope, if does not... by Anonymous Coward · · Score: 0

    and you can do multiple optional unwrap..

  20. More like hidden bug introducer by jader3rd · · Score: 1

    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.

    1. Re:More like hidden bug introducer by Anonymous Coward · · Score: 0

      It's like the Swift designers said, "We need something like RAII or try-with-resources, but how can we royally fuck it up?" The very concept is just awful and ripe for abuse in bizarre ways.

      As for repeat, the fact that they used a different keyword than the c-family of languages is nothing, it's the fact that they changed the meaning of do between versions of the language immediately breaking Swift 1.x code. If I was bothering to code in Swift I'd have to seriously consider whether I'd take the risk knowing that the language developers are more than willing to break your codebase with grammatic changes like that.

    2. Re:More like hidden bug introducer by Anonymous Coward · · Score: 0

      Um, defer is for cleaning up local resources when you return from a function. How can a local resource possibly be cleaned up "before you've used it"?? Once you've left scope all an unclosed resource can be is a memory leak!

    3. Re:More like hidden bug introducer by rasmusbr · · Score: 1

      I guess defer is only every useful in a function that creates a resource R, uses R itself and does not share R with any code that can run at a later time.

      That last requirement might be a little tricky to check for at compile time.

    4. Re:More like hidden bug introducer by Anonymous Coward · · Score: 0

      The day Swift was introduced they said "We expect to be evolving quickly so for the next two years we will be guaranteeing *no* ABI or source compatibility." If you're "nothing to code in Swift" then yeah, you goddamn better have seriously considered Apple's warning there. (On the plus side, they provide an automatic migrator that typically updates 95% - whatever is automatable - of the syntax for you.)

    5. Re:More like hidden bug introducer by Anonymous Coward · · Score: 0

      A warning that Apple very much glosses over, assuming you know how to even find it at all. The shit that they're deciding to break is largely stylistic, as in it would not have negatively affected the language if they had chosen a different keyword for denoting a scope block rather than do.

    6. Re:More like hidden bug introducer by jader3rd · · Score: 1

      It's not even that. The way it looks to me is that if you currently have two statements which are immediately after each other, and now you interject a defer, it'll work. But it's easy to break up how immediately statements follow each other when maintaining code. So one little misstep, and BAM, all of a sudden resources are getting cleaned up unexpectedly.

    7. Re:More like hidden bug introducer by rasmusbr · · Score: 1

      I think the defer block will always run as the last thing that happens before its containing scope finishes. So as long as you're just writing a function that opens a resource and does not hand that resource over to anything else you should get a very predictable behaviour regardless of what you do inside that function.

      The placement of the defer block itself probably doesn't matter. I suppose it would give you a compile time error if you place it before the resource is declared.

    8. Re:More like hidden bug introducer by rasmusbr · · Score: 1

      Actually, I just gave it a try, and there is a problem with where you place your defer block.

      The following program compiles and the value of the string at the end of execution is "newValue", not "newerValue" as the programmer probably intended.

      var someString = "oldValue"
      func deferTest() {
              someString = "newValue"
              return
              defer {
                      someString = "newerValue"
              }
      }
      deferTest()
      someString

    9. Re:More like hidden bug introducer by mandolin · · Score: 1

      That defer keyword looks like the mother of all hidden bugs.

      At first glance it looks to me like Apple ripped defer straight from Go. I think it has its use -- in a language that doesn't support RAII. But I prefer the latter.

    10. Re:More like hidden bug introducer by Anonymous Coward · · Score: 0

      The defer statement has to actually be executed. You should be getting a warning from the compiler that the line is never reached due to the return statement.

    11. Re:More like hidden bug introducer by Anonymous Coward · · Score: 0

      Error: "Code after 'return' will never be executed." (I mean, no shit.)

      An actual example of what defer is for, imagining the string is just a proxy for some opened resource (eg. using fopen() and fclose() to read a file), and realizing that our example string variable exists outside the scope of the function just so we can check it afterward:

      enum ResourceError: ErrorType {
              case CouldNotParse
              case MissingFields
      }

      var someResource = "uninitialized"
      func deferTest() throws {
              someResource = "initialized"
              defer {
                      someResource = "closed"
              }

              if someResource == "unparseable" { // Oh no, our data was corrupt or something! Bail.
                      throw ResourceError.CouldNotParse
              }
              else if someResource == "missing fields" { // Oh no, our data was not complete! Bail.
                      throw ResourceError.MissingFields
              }

      // Our resource is fine. Do some work!

      // Work work work.

      // More work.

              someResource = "completed"
      }

      try? deferTest() // Ignoring errors for simplicity's sake

      print(someResource) // "closed"

      (Sorry, slashdot is eating the newlines before each comment in the code no matter what I do.)

      There are three ways out of this function: the two errors, and the implicit return at the end of the success path. Without defer, we would need to write code to close the resource three times; not only is this a lot of code duplication, it's a huge potential source of leaks - the exits may be far from the initialization so it's easy to forget we need to close the resource (especially in the future when someone adds an additional error check halfway through all the lines of "work work work").

      defer solves both of these problems. You only have to write the cleanup code once (it runs regardless of how you exit). You can write it directly after the setup so it's hard to forget to do. When you look at it again a year from now you can tell immediately that your ass is covered. And if you should happen to add another error check and throw in the future without realizing the fact that the resource needed to be closed... It's fine, you didn't need to!

  21. Bad example of guard by Anonymous Coward · · Score: 0

    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

  22. No actually it's not by SuperKendall · · Score: 1

    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
    1. Re:No actually it's not by Anonymous Coward · · Score: 0

      Reading your posts you sound like a complete retard

  23. Guard is much more useful than you are thinking by SuperKendall · · Score: 3, Informative

    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
  24. 7 Headlines Click-Seekers Will Love! by scratchy_king · · Score: 2

    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

  25. IF by Anonymous Coward · · Score: 0

    ...there is a build system capable of compiling and linking 100E9 lines of code in the course of a year. I sincerely doubt this.

  26. assert(Recruiter == E_IDIOT) by Anonymous Coward · · Score: 0

    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.

  27. Go Back by Anonymous Coward · · Score: 0

    ..under rock, a$$.

  28. Really ? by Anonymous Coward · · Score: 0

    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 :-)

  29. Not Entirely Correct by Anonymous Coward · · Score: 0

    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.

  30. Vote Trump by Anonymous Coward · · Score: 0

    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...

  31. Totally inaccurate by Anonymous Coward · · Score: 0

    No. They're open-sourcing their entire Foundation framework alongside it.