Slashdot Mirror


Swift Vs. Objective-C: Why the Future Favors Swift

snydeq writes: InfoWorld's Paul Solt argues that It's high time to make the switch to the more approachable, full-featured Swift for iOS and OS X app dev. He writes in Infoworld: "Programming languages don't die easily, but development shops that cling to fading paradigms do. If you're developing apps for mobile devices and you haven't investigated Swift, take note: Swift will not only supplant Objective-C when it comes to developing apps for the Mac, iPhone, iPad, Apple Watch, and devices to come, but it will also replace C for embedded programming on Apple platforms. Thanks to several key features, Swift has the potential to become the de-facto programming language for creating immersive, responsive, consumer-facing applications for years to come."

19 of 270 comments (clear)

  1. Uh... by EmeraldBot · · Score: 5, Insightful

    Since when is embedded programming associated with "immersive, responsive, consumer-facing applications"? I don't think Swift is going to replace C anytime soon in that department.

    --
    "Set a man a fire, he'll be warm for the rest of the night. Set a man afire, he'll be warm for the rest of his life."
    1. Re:Uh... by Entrope · · Score: 4, Insightful

      More to the point, who outside Apple develops embedded software for an Apple platform?

    2. Re:Uh... by ColdWetDog · · Score: 5, Funny

      The NSA.

      --
      Faster! Faster! Faster would be better!
  2. Unlikely by msobkow · · Score: 4, Insightful

    It is highly unlikely that Apple is going to rewrite all that GPL and BSD code at the heart of iOS with Swift. As long as those core projects are based on 'C', they'll stay in 'C'.

    --
    I do not fail; I succeed at finding out what does not work.
    1. Re:Unlikely by Trepidity · · Score: 5, Interesting

      I think a wholesale rewrite is unlikely, but I would guess that they are going to eventually do something about the GNU code they use. Apple doesn't like the GPLv3's patent clauses, so they have frozen all their imported GNU utilities at the latest GPLv2 version. Some of these are now getting quite old and not maintained upstream, so Apple has to handle even routine maintenance. They managed to transition off one big one by moving from gcc to clang/LLVM, but there is still a bunch of old GNU code shipped in the base system that I don't see them keeping forever. Now whether they rewrite it in Swift seems more questionable.

    2. Re:Unlikely by Feral+Nerd · · Score: 3, Insightful

      It is highly unlikely that Apple is going to rewrite all that GPL and BSD code at the heart of iOS with Swift. As long as those core projects are based on 'C', they'll stay in 'C'.

      Precisely, that's what wrapper code has been for since I started coding back in the early 90s. It always cracks me up when people let fly gold nuggets like "...the Python implementation of OpenCV...". As far as I am aware, nobody rewrote all of OpenCV in Python, they created Python bindings which is a fancy way of saying they created a Python wrapper for OpenCV. Programmers don't always realise that the API's they are using are actually wrappers. I used to use a C++ Linear Algebra library but because I just installed it with yum or apt-get I didn't pay it much thought. it wasn't until I tried to compile it for an embedded computer that I realised the thing was actually a wrapper for a Fortran 77 library that was ported to Fortran 90 and then given a C++ wrapper and that made it a bit of a bitch to compile (largely due to the fact that I didn't know squat about Fortran). Apple will provide Swift wrappers for at least some of the C/C++ libraries and the ObjC stuff if that's necessary (never used Swift myself so I don't know how well ObjC libraries integrate into Swift). Any other approach would have Apple's developers busy doing nothing but rewriting and debugging ported code for the next decade at least. What interests me is how far up shit creek will a developer be if he/she realises that they need a C/C++/ObjC library for his Swift application?

  3. On iOS platforms. by FireballX301 · · Score: 5, Insightful

    The future favors Swift only because Apple is going to phase out use of ObjC. That's it. Arguing about languages is silliness when Apple will likely force you into using Swift for iOS9 compatibility in the next 12 months.

    1. Re:On iOS platforms. by Dog-Cow · · Score: 4, Insightful

      How should Apple be able to force you to use one or the other?

      should or could?

      Apple can easily do both.

      should: because Apple says so, and they control the App Store. Apple doesn't have to give a reason other than deprecation.

      could: compiled swift code looks different than objective-C code. It also links against the swift runtime and not the objective-C runtime. It's not hard to tell the difference.

    2. Re:On iOS platforms. by BronsCon · · Score: 3, Interesting

      This oft-quoted line of complete bullshit is why people think iOS and Apple's walled garden is more secure than any other mobile platform. The reality is that Apple gets a binary to review, just like Google, Microsoft, or Blackberry. Apple and Google actually review the binaries, even; and Google even actually catches some nasties (I'm sure Apple does, as well, but they aren't as transparent about it) and prevents them from entering the Play store. Apple has pulled malware from the iOS store in the past, but has never made any official comment on it, unlike Google, which does leave one wondering... Knowing that malware authors likely submit to both platforms at the same rate, we know how often Google rejects or removes malware from their store (because they publish the statistics), one should expect that Apple's numbers are roughly the same, but are they? If anyone has a link to some official (e.g. from Apple) stats on that, I'd love to see them.

      --
      APK quotes people (including myself) without context and should not be trusted. Just thought you should know.
  4. Debate settled. We know the future! by Paradoks · · Score: 4, Funny

    It's nice that there's a programming language debate where the future has been entirely settled. Thanks infoworld!

  5. Re:Swift is destroying Rust. by EmeraldBot · · Score: 3, Insightful

    The important thing to remember here is that Swift is absolutely destroying Rust.

    Rust has been nothing but hype so far. Many Ruby on Rails hipsters have rallied around it, but they haven't actually managed to produce anything useful with it.

    Anything that can be done using Rust can be done better by using C++.

    C, C++ and Go are the dominant languages on Linux. Rust has made no inroads here.

    C++ and C# are the dominant languages on Windows. Rust has made no inroads here.

    Now that Swift is seeing tremendous uptake within the iOS and OS X sphere of influence, Rust has even less of a chance than it had before.

    I think that Swift will be seen as the final nail in Rust's coffin. Swift has provided developers with productivity, while Rust has provided them with false hopes.

    We're seeing a convergence on exactly three languages: C++, C#, and Swift. Every other language is becoming a minor player compared to these Three Giants.

    According to the TIOBE Index, Java has more usage than all three of them put together. I'd hardly call it a "minor player".

    --
    "Set a man a fire, he'll be warm for the rest of the night. Set a man afire, he'll be warm for the rest of his life."
  6. Objective-C was ahead of its time by jblues · · Score: 3, Funny

    Objective-C was ahead of its time. It uses messaging for communication between Objective-C, and using "the runtime" (a tiny virtual machine that is embedded into each executable) messages are resolved to a function pointer. Other compiled languages use static dispatch, vtable dispatch (allows overriding) or in-lining. However, messaging gives an advantage in that it affords features that are available in higher-level 'interpreted' or 'managed' languages:

    • * Object introspection - describe the methods and properties of an object
    • * Dynamic invocation - reflectively invoke methods of an object.
    • * Method interception - add or reroute methods for all instances or a single instance of an objection, optionally calling the original.

    The above features allow all kinds of useful things like Aspect Oriented Programming, instrumented objects at runtime (eg for object-relational-mapping), Cocoa's elegant property observers, etc. Another advantage is that Objective-C is close to the bare-metal so its very easy to take advantage of the above, while dropping back to raw C (or C++) as needed for performance tuning, which given the 95-5 rule is not too often.

    Contrast these dynamic features, with C++ which fills another niche. Now the industry has had 30 years to forget how useful these features are, so Swift uses static and vtable dispatch. Given a virtual machine, with just-in-time compilation this is no problem, but as a compiled language it means forfeiting the above. Swift allows the above if a class extends a Cocoa Foundation class, but this problems are:

    • * Developers are excited about writing 'pure' Swift.
    • * The advantage or dynamic dispatch is that it can be applied to any class. Now if Swift adds compile-time AOP, this will only work with code that you have the source for.
      • I'm surprised more people didn't raise concerns about this.

    --
    If it acquires resources on instantiation like a duck, then its a shared_ptr<Duck>
  7. What is Swift written in? by Areyoukiddingme · · Score: 5, Informative

    What is Swift written in?

    It is built with the LLVM compiler framework included in Xcode 6, and uses the Objective-C runtime...

    So... C. Ok, we're done here.

    No wait. One more thing. It's the Objective-C runtime. Which means Objective-C programs will just keep running, as they ever have.

    Swift and Objective-C code can be used in a single program, and by extension, C and C++ as well.

    The new language can't supplant the old one while the old one exists in the same environment. More to the point, compatibility with Objective-C, C, and C++ was an explicit design goal. So you can just pack up all the bullshit about taking over the world.

  8. Re:Swift is destroying Rust. by lucm · · Score: 4, Insightful

    We're seeing a convergence on exactly three languages: C++, C#, and Swift. Every other language is becoming a minor player compared to these Three Giants.

    Baghdad Bob, is that you?

    --
    lucm, indeed.
  9. Swift is not ready to replace ObjC by Anonymous Coward · · Score: 4, Insightful

    > 8. Swift supports dynamic libraries

    The swift runtime is a static library (written in C++11) and linked in every executable, everytime there's an update to swift (runtime) you need to recompile all your code (see Apple's swift blog, first entry). This is why swift cannot be used for system API / libraries, at least until they have a stable runtime that can made a dynamic lib (like Obj-C is). But it being C++, I don't know if that ever gonna happen.

  10. I disagree by SuperKendall · · Score: 5, Insightful

    I've done Objective-C since before the release of the iOS App Store, and Swift almost full time since Apple released it last year...

    Some of the things you mention beginners do not have to use (generics, and struts for example). To keep things simple to start with, they could just use classes instead.

    I will agree that optionals might be a bit rough on the beginner - but perhaps not as starting from nothing, the concept of a bucket that holds a value instead of just using the value directly, would not be so foreign...

    You also mention different ways to specify params, and shortcuts - but I see those as a major plus. You can just pick a level of detail that makes sense to you and work with that, until you feel comfortable with reducing further the syntax you use.

    I think the function syntax is one of the cleanest and easiest styles to understand... I believe a few other languages have this form also, but in swift you just say something like "a function named takes in these params, and outputs those params" So it looks like:


    func myFunc (a:String, b:Int) -> (a:String, b:Int)

    it's just so balanced that you can have any number of things in or out.

    There are a few things I think make Objective-C less approachable.

    The separate header files, and the heavy modern use of private categories to define most internal properties confuse people as to where they need to define things.

    Simply more verbose syntax all over. I like verbosity myself, I love named parameters... you get that with Swift though with a lot fewer characters typing.

    Part of that extra syntax in ObjC is the shorthand to make arrays like @[] and @(value) to make NSNumbers... but in Swift Integer is treated the same as String, both are first class objects that you can do things with so it's more consistent. That in particular is I think a large benefit for newcomers.

    --
    "There is more worth loving than we have strength to love." - Brian Jay Stanley
  11. Re:Swift is destroying Rust. by TWX · · Score: 4, Insightful

    I suppose it depends on what you want to do with it, and what you see Java's future as a wholly-owned subsidiary of Oracle is.

    I was studying programming in college when the hype for Java began. We were using C and C++. What was true then still holds true today, in that in C/C++ you can write operating systems and conventional programs, but in Java you are limited to conventional programs. Java has the theoretical interoperability feature between OSes and hardware platforms, but in practice there's a lot of customization to make programs actually do this, and if one has to write versions for several platforms, it's not a whole lot more burden to compile those and distribute binaries instead of Java runtimes.

    As for servers, I've always liked the mindset of putting as little as possible on the production server beyond what its job is. Hell, the idea of statically-compiling everything to allow one to eliminate libraries, let alone compilers on the production box, appeals in that if someone does break in there's a lot less they can do once on there. Java for server-side applications flies in the face of that, there are more general-purpose tools on the server rather than less.

    I'm aware that I'm not in the majority for this stuff, and I didn't make programming my profession anyway so perhaps even I should be taken with a grain of salt, but it seems like in this speed to push features we've taken steps backward in real system security, and we're being bitten in the ass by it with ever increasing frequency. The very choice of programming language appears to be fundamental to that.

    --
    Do not look into laser with remaining eye.
  12. There's some of us who've seen this before... by mark-t · · Score: 3, Interesting

    And we know from experience that WHENEVER somebody uses terms like "language <XYZ> is the future", it is inevitably baseless speculation, and often rests on the false belief that some single programming language, or any single technology for that matter, can actually be the "best" one.

    Brooks said it best, There is No Silver Bullet

  13. Re:Swift is destroying Rust. by goose-incarnated · · Score: 3, Insightful

    We're seeing a convergence on exactly three languages: C++, C#, and Swift. Every other language is becoming a minor player compared to these Three Giants.

    Wait, what? Swift is basically statistical noise at this point. "Dead" languages like ML and Pascal are higher in the tiobe index than swift is. It may become a force in the future but it's nowhere near that now.

    --
    I'm a minority race. Save your vitriol for white people.