Slashdot Mirror


Ask Slashdot: Swift Or Objective-C As New iOS Developer's 1st Language?

macs4all (973270) writes "I am an experienced C and Assembler Embedded Developer who is contemplating for the first time beginning an iOS App Project. Although I am well-versed in C, I have thus-far avoided C++, C# and Java, and have only briefly dabbled in Obj-C. Now that there are two possibilities for doing iOS Development, which would you suggest that I learn, at least at first? And is Swift even far-enough along to use as the basis for an entire app's development? My goal is the fastest and easiest way to market for this project; not to start a career as a mobile developer. Another thing that might influence the decision: If/when I decide to port my iOS App to Android (and/or Windows Phone), would either of the above be an easier port; or are, for example, Dalvick and the Android APIs different enough from Swift/Obj-C and CocoaTouch that any 'port' is essentially a re-write?"

25 of 316 comments (clear)

  1. Obj-C by occasional_dabbler · · Score: 4, Insightful

    The one really good thing that has come out of the Apple fashion parade is objective C. Jobs' legacy isn't all the shiny fashion crap, it is this powerful and really rather beautiful language. This is from someone usually branded a Microsoft shill. If you want to write iOS/OSX take advantage of the native tools.

    --
    "Our opponent is an alien starship packed with atomic bombs," I said. "we have a protractor"
    1. Re:Obj-C by occasional_dabbler · · Score: 4, Interesting

      I grew up with Fortran, C was a revelation and obj-C was an epiphany. C++ was, of course, a heresy...

      --
      "Our opponent is an alien starship packed with atomic bombs," I said. "we have a protractor"
    2. Re:Obj-C by taharvey · · Score: 4, Insightful

      Anyone who says 'X' language is crap, can safely be ignored.

      Unlike our previous poster, though My opinion is that Java, is actually one of the least useful languages out there. It doesn't provide a higher level syntax than objC or C++, like the "better languages" Ruby, Python, etc. Nor does it provide the performance or memory footprint of systems languages like C, C++ or objC. It is bound by a runtime, that is meant to make it run-anywhere. Yet ironically the universal crown is going to javascript+HTML5, not java. Java in many ways is the new pascal, it is largely an educational language with a strong base in corporate intra-net applications.

      You can use c, objC & C++ for decades to come. However Swift is very exciting (and I'm a embedded guy). It is the first serious language to come along that can challenge the C family of systems languages that I can remember. It has all of the native performance of C, the memory footprint advantages of reference counting, all of the syntactical goodness of ruby or python, the inherent parallelism of groovy and haskell, yet can morph into a JIT language in development with a very enticing hot-coding environment. With Chris Lattner & Apple backing it, it will be successful. I can't wait till it filters down to the open source space so I can use it in embedded systems.

    3. Re:Obj-C by dottrap · · Score: 4, Interesting

      Agreed. And for the op, Obj-C is the best language to use right now. Being well versed in C means he can learn Obj-C in a day. Obj-C is a very small superset of C.

      The hard part is learning Cocoa, but that is true of any framework whether that is Swing, Android, MFC, GNOME, Qt.

      Swift is so new, you will have to learn Obj-C anyway to learn Cocoa.

      The best bet is for the op to write model/cross-platform code in C, and then use Obj-C for the native UI layer. Then repeat for Android/Java (via JNI) and Windows Phone/C++CX.

    4. Re:Obj-C by Dutch+Gun · · Score: 3, Informative

      I was recently pondering whether my game engine (written in C++) should have it's native OSX back-end / interop written in Swift or Objective-C. From what I can see, for what I need to do, Objective-C remains the clear choice, at least for now. There's a lot of good documentation on Objective-C / Cocoa, as well as lots of examples for how to interop between Objective-C and C++. I haven't even been able to determine if this is possible with Swift after searching around a bit on the net. Interop with Objective-C, yes, but that's pointless for me. I don't see Apple obsoleting or depreciating Objective-C in the near future. There's a heck of a lot of legacy code in that language, and like you mentioned, it seems like Swift wouldn't even be a proper replacement at this point for everything Objective-C can currently do.

      As with pretty much any other language-choice debate, you really first need to know what someone plans to do with it before you can make a worthwhile recommendation. All languages have strengths and weaknesses, so it's foolish to point to one without even knowing what you'll be doing. The OP first wants to know about "quick and easy" for which I'd probably recommend Swift, but then wants "portability", for which I'd recommend C (for him, since he knows that - personally I use C++) with carefully walled off interfaces to the GUI frontend, but *only* if the complexity merits such treatment rather than a simple port in native code for each version. Without any more info, I can't make a better recommendation than that really.

      --
      Irony: Agile development has too much intertia to be abandoned now.
    5. Re:Obj-C by maccodemonkey · · Score: 4, Informative

      It was my understanding that if you want "complete" control, you still need to use ObjC, and that Swift was for dashboards, things previously known as WebApps, and other lightweight situations where you aren't actually doing anything novel, just packaging an interface to a datastore or moving sprites around.

      That said, Swift is just as good on inheritance as ObjC, and does garbage collection correctly (benefits of a CLR).

      ObjC has been tuned to OS X/iOS, and if you write in ObjC, you should be able to make a single back end that's easily portable to OS X as well as iOS; Swift would be more for iOS only.

      I really do like the real-time iteration available in Swift though.

      That said, my opinion must be crap, because I'm older than Java too :D I still like Pascal and Common LISP, but wouldn't write a modern application in them (flashback to writing Avara mods in the 90's using ClarisWorks). Most stuff I write these days is in C or Python.

      Oooof. So much wrong in a single post. Let's review....

      Swift definitely does not do garbage collection. Obj-C actually had a garbage collector for a while (Swift never has) but it was optional, and support for it has ended.

      What Obj-C has now is something called ARC (Automatic Reference Counting). At compile time (not run time) the compiler does a static analysis of the code and determines where it needs to add memory management code, and then quietly does so for you. This means there is no run time hit, and behind the scenes everything is still manual memory management. Sometimes you still need to hint to the compiler what to do (usually when trading pointers with C), but 99.99% of the time it just works.

      Swift is built on the same runtime as Obj-C, so it inherits ARC. With Obj-C, you can turn ARC off and continue writing manual code, and I'm not sure if Swift allows the same, but it's the exact same behavior. Swift uses the same manual memory management functions as Obj-C in the background, while in the foreground the developer still writes without memory management. I'm not sure what this "benefits of a CLR" is you're talking about, as that's a term usually associated specifically with the Common Language Runtime of the Microsoft language family, but it's neither here nor there. Swift does not run in a VM (it's natively compiled just like C or Obj-C), and it does not have a garbage collector. (But the compiler will add your memory management code for you.)

      As far as Swift being multi platform, Swift most definitely for sure runs on OS X, so the language choice has absolutely no bearing on what platforms you want to port between. I have a partially Swift project going on the Mac right now. Swift is definitely not iOS only. Beyond that, it looks like Apple will be working to open source much of it and move it to other platforms.

      I'm not sure what this business is about Swift being for lightweight solutions. It runs on the same runtime as Obj-C, it's starting to be as fast as Obj-C, and it interoperates with any Obj-C code (as Obj-C will interoperate with any Swift code). Apple has never messaged that it's for lightweight apps, and developers aren't treating it that way. I still prefer Obj-C, but I'm not sure what that bit is about at all.

    6. Re:Obj-C by ArhcAngel · · Score: 3, Informative

      Sure Java exploded but it became the Honda Civic of languages while C is still around but Delphi is not.

      The news of Delphi's death has been greatly exaggerated.

      --
      "A person is smart. People are dumb, panicky dangerous animals and you know it." - K
    7. Re:Obj-C by silfen · · Score: 3, Informative

      Objective-C didn't "come out of" Apple or NeXT or Jobs. It was created by Brad Cox and Tom Love at ITT and Stepstone in 1983 and is derived from Smalltalk-80. Jobs just bought the company in 1995.

    8. Re:Obj-C by taharvey · · Score: 3, Informative

      Nobody said Java was useless. I just can't think of why I'd use it over another language unless I had to. I'd either pick C/C++/objC for speed, or I'd pick Ruby/Python for efficiency, or I'd pick Groovy or Haskell if I was leaning functional... depending on my needs. I can't think of why I'd go in the middle. Seems like the worst of all worlds.

      Rust and Swift are very on par languages attempts, with the exception that Swift also has a very nice compile time JIT and hot-coding environment. However, and this is crucial: Swift is beating Rust to the punch - and that is an important factor in languages. Swift had 200,000 devs download the language spec in the 1st 24 hours. That is probably 10x more than have ever downloaded the Rust spec.

      Rust is still listed as experimental, as Swift is being rolled out to developers. The Rust team is still arguing over implementation, in an unfortunate design-by-committe kind of way. Rust has no killer-application driving it. Swift does. Swift is Driven by Chris Lattner, who has probably done more for the compiler world in the last 10 years than the next 25 guys put together (LLVM, Clang, OpenCL, etc). And Swift is backed by a huge amount of Apple dollars. Even the Original developer behind Rust has tipped his hat to the project. So Yeah, I expect Swift to rocket to the Top 5 languages in the next 2 years while Rust stays a academic plaything for many years to come.

    9. Re:Obj-C by Jeeeb · · Score: 5, Insightful

      Unlike our previous poster, though My opinion is that Java, is actually one of the least useful languages out there. It doesn't provide a higher level syntax than objC or C++, like the "better languages" Ruby, Python, etc.

      Java doesn't provide a higher level syntax than C++/Obj-C but it does provide a much more easily parsed syntax. The result is lightning fast compilation, sane compilation errors and excellent tooling support. Auto-completion, powerfull refactoring, background compilation and powerful lint tools make for a very productive programming environment. Even C# doesn't have full proper background compilation yet. Intellisense is close but there are whole classes of compile time errors that it doesn't pick up.

      Similarly stability has done a lot for the language. Java is one of the few languages were I'm confident that I could build a project I wrote ten years ago with no issues. C++ on the other hand... ugh! Just last week I shifted a project from VS2012 to VS2013 and had spend an afternoon fixing random code breakage because MS broke their Chrono libraries and their retarded compiler gave errors in the template definition in their header file rather than the actual lines breaking compilation. Not to mention the ball of fun that was trying to get the latest versions of our dependencies to compile... Fun stuff like the 64bit build for some reason produced 32bit obj files... In Java land I add a line to Maven or for Android drop a library in the libs file and add it to the dependencies... Presto, nothing more to think about.

      It's also a very readable proramming language imo. Packages=directories and one public class per file make navigating Java code very easy. Types are obvious and code is simple to follow. I've worked in C++,Java,C#,Javascript,Python and also on my own time in C and Haskell. Out of those I'd say Java and C# easily have the best readability. (For the record Haskell has the worst by far imo.)

      It is bound by a runtime, that is meant to make it run-anywhere. Yet ironically the universal crown is going to javascript+HTML5, not java.

      I'm not sure if that is ironic. The Java runtime brings other benefits than cross platform compatibility. If I dereference a null pointer or use an index outside of array bounds, the Java runtime will give me a nice error telling me exactly what the error was, which line of code in which class caused it and what the sequence of calls that lead to the error was. Try doing the same thing in C++/Obj-C. If you're lucky the code will be running on a developer machine and you can hook in the debugger and if the code isn't too heavily optimized maybe even get the line of code it occured on. If you're unlucky the code is on a production server/client system somewhere and your stuck trawling through a log to find the error. (For the record record Haskell easily takes the title of hardest to debug language thanks to lazy evaluation.)

      Plus it's not like C++/ObjC have no runtime. For example, if you don't have the right VC++ redistributable installed, you'll get nowhere trying to run C++ application compiled in VC++. Their runtime just doesn't include a JIT compilation stage (for better or worse)

      Anyway here's the tl;dr: Java doesn't have exciting language features but it does have excellent tooling, excellent readability and is one of the easiest languages out their to debug. That too me is way more valuable than exciting language features. I prefer C# but I'm happy to work in Java instead.

    10. Re:Obj-C by Cyberax · · Score: 3, Insightful

      Java is just as fast in the RealLife(tm) as C++. Or more exactly, I'll write a fast-enough Java application faster than you'll write a third of it in C++. And Python for efficiency? Don't make me laugh.

      Swift right now is a slow toy with incoherent semantics (lambdas and no GC, really?). It has _NO_ real advantages over Rust as they both use the same LLVM ecosystem for the backend. And I don't get where you got the idea that Swift uses any kind of JIT, it's a strictly compiled language like Rust. Compile speed of Rust is excellent (it's self-hosting, so there's a fair amount of code to compile) and by now Rust's design is mostly finished.

      But of course, as we know, Apple has invented programming languages.

    11. Re:Obj-C by philip.paradis · · Score: 4, Insightful

      public class HelloWorld {
          public static void main(String[] args) {
              System.out.println("Hello, World");
          }
      }

      --
      Write failed: Broken pipe
  2. Doesn't really matter! by Anonymous Coward · · Score: 5, Insightful

    Learning the language itself is not that difficult. Learning the SDK and how things work in Cocoa-land is the important part.

    For example, if you need to display a list of of items in a list, an UITableView will work the same regardless of your language choice. You will still need to understand the idiosyncrasies of working with UITableViewDelegate and UITableViewDataSource.

    I would stick to Objective-C for the moment as there are more learning resources online.

    1. Re: Doesn't really matter! by dagamer34 · · Score: 4, Interesting

      Ditto. Because learning the framework takes a LOT longer than learning the language and the fact that the framework was designed with Objective-C in mind, it is foolish to think that you will be able to write a pure Swift iOS app without knowing Objective-C anyway because there isn't enough Swift material out there for Google to find to solve your problems. And unless you *really* enjoy solving those problems on your own, you'd need to convert an Objective-C solution to a Swift one on your own, at which point you are basically learning both languages anyway. So I would say all new iOS developers need to learn Objective-C because writing a Swift-only app would be too painful otherwise. This all changes when The Big Nerd Ranch puts out a Swift book, but there's no indication that is anytime soon.

  3. Five years of Swift minimum... by Anonymous Coward · · Score: 5, Funny

    I'm already getting barraged by headhunters asking for five years of Swift minimum for contracts now...

  4. More help is available on Objective-C by notthepainter · · Score: 4, Interesting

    If you're just starting out you're going to be learning a lot, reading blogs, reading stackoverflow, and there is far more Obj-C out there than Swift now. So you since you want fast, not best, Obj-C is the correct choice for you. Not necessarily for everybody, but for you.

  5. either works if you take advantage of by musikit · · Score: 3, Insightful

    since you are already a C programmer and are talking about maybe moving to android at a future time. i would write as much as possible in C and just bind to the UI with java/objc/swift.

    take advantage of what you know. build wrappers around the java/objc code you will need to you can easily transport that to whatever platform you are on as long as it binds with C.

  6. Objective-C, hands down by tyme · · Score: 5, Informative

    Swift is still a very immature language, with lots of bugs in the compiler, rough support in the debugger and IDE, and the syntax isn't even set in stone yet (don't expect the syntax to settle down before Swift 2.0, probably some time in late 2015 if not 2016). There are a number of things that you still can't do in Swift (e.g. providing a callback function for APIs that expect a C function pointer), and you'll just spend a lot more time hitting your head against walls than writing working code. On top of this there are many more resources available for learning Objective-C than there are for Swift, and the pitfalls and corner cases are better understood for Objective-C than they are for Swift. As a bonus most of your instincts honed on C will carry over to Objective-C (while they are likely to lead you astray in Swift).

    Swift is a really exciting language, and fun to play around with, but it's not ready for production work (yet). It will get there, but in the mean time you should stick with the established tools, which means Objective-C for iOS and Mac OS X app development.

    --
    just a ghost in the machine.
  7. Right now, Obj-C by GrahamCox · · Score: 5, Informative

    A lot of comments here saying how Obj-C is "ugly", and so forth. I wonder how many commenters are actually using it to any great extent, on a day-to-day basis, rather than have just looked at it out of curiosity for five minutes?

    If you want to write an app now, Obj-C is the only sensible choice. Swift looks promising, but it's not ready. It's changing almost weekly and at the moment it's actually introducing bugs into the frameworks where none exist in Obj-C. If you want to live on the bleeding edge, go for Swift, but if you want to write an app, get it working and ship it out of the door, Obj-C is the only game in town today.

    Once you get into Obj-C, it's a much more elegant language than it's usually given credit for anyway. Sure, it's old, but the runtime and compiler work put in in recent years makes up for many of its older roots. Manual memory management is not required, there is a dot syntax for properties and so on, so square brackets are not the only way to call getter/setter methods. As a pure superset of C99, it's easy for a C programmer to learn. It's also a small language. The real power lies in the frameworks, and that will take you far longer to learn than the language. Don't be put off by the superficial "ugliness" of Obj-C code, it isn't relevant. It's expressive and straightforward, and as a former C++ programmer, I also found it dramatically more productive when I first adopted it over a decade ago. It is possible to become fond of it, believe it or not. Whether the same eventually becomes true of Swift, only time will tell. Ignore the nay-sayers who have probably never actually used Obj-C in anger in their lives.

  8. Why are you in charge of the decision? by BarbaraHudson · · Score: 4, Insightful

    Although I am well-versed in C, I have thus-far avoided C++, C# and Java, and have only briefly dabbled in Obj-C. Now that there are two possibilities for doing iOS Development, which would you suggest that I learn, at least at first? And is Swift even far-enough along to use as the basis for an entire app's development? My goal is the fastest and easiest way to market for this project; not to start a career as a mobile developer.

    This portends badly. You don't know enough about any of the languages currently in use on any platform, and your goal is "the fastest and easiest way to market?" The obvious solution is to give the job to someone else who knows what they're doing.

    So, since that's not what's happening here (and any sane - and most insane - business would go that route), this is a case of "I've got a cool idea for a mobile app but I don't know anything about the platforms or how to code in the languages behind them, and I don't want to give any details about what its' performance and resource requirements are because someone might steal the idea." This is further borne out here:

    If/when I decide to port my iOS App to Android (and/or Windows Phone), would either of the above be an easier port; or are, for example, Dalvick and the Android APIs different enough from Swift/Obj-C and CocoaTouch that any 'port' is essentially a re-write?

    Why not just download the dev kits for Android and iOS and ask yourself if you can even understand the development documentation, the APIs, etc? The problem right now is yo don't even know enough to ask the right questions: you don't want to commit to something (objc vs swift) this early in your learning curve and then find out you made the wrong choice because you didn't take a month to pick up some basics.

    --
    "Transparent" is a shit show that trades on every stereotype going. A man in drag is NOT a transsexual.
  9. Re:If you 'speak' C by evenmoreconfused · · Score: 3, Informative

    Using a text editor to write code for a device like an iOS device, that simply displays the weather or a stock price is so ... 1960s?

    Well -- 1970's maybe. 1960's were more about drum storage and all that. Even in the early '70s, the 029 keypunches didn't let us correct typos -- you had to hold the "dup" key down to duplicate the bit you got right, and then carry on keying from where the mistake started. The 129's were much better, as they only punched the card after you finished the whole line.

    Although come to think of it, I did write a nice simple weather app in 360/Assembler for a class in 1974.

    --
    No. Well...maybe. Actually, yes. It really just depends.
  10. Re:Neither by Shadowmist · · Score: 3, Insightful

    Adobe flex. Cross platform, works on everything.

    Your choice then... to be good on the platforms you write for, or evenly craptastic for everyone. Cross platform equals lowest common denominator. If you want to put out apps that people will call good... do the extra mile and code for that platform.

  11. Re:C# using xamarin by Jeeeb · · Score: 3, Informative

    I was very tempted by Xamarin but put off by the $$$. Is it as good as claimed?

    My company got a few licenses for a project recently since our client wanted it done in C#.

    From version 3 it has the ability to write cross-platform GUI code. The other option being to write Android/iOS GUI code seperately through C# mappings of their native apis. I wasn't responsible for trying the x-plat GUI part out but I do know that ultimately we were unimpressed and elected not to use it, instead developing for Android and later porting the GUI code to iOS. From memory it was just too limited.

    It may be acceptable for routine business apps but then why not just develop them as a web-service and avoid the Apple-tax and pain of dealing with Apple's provisioning cluster fuck. (Seriously why do so many company's want to use iPads for internal apps? Distributing apps on them is a major pita)

    The other pain point for us was third party libraries. In theory you can import jars and it will automatically map them to C#. In practice that doesn't work. We had to support mobile scanners with a laughably bad and somewhat broken API and broken default apps. I ended up writing an Android service to deal with all that crap. When it is time to add iOS support we'll have to write an iOS specific layer.. (iOS bluetooth access is too limited to directly access the scannner so that will probably involve treating it as a keyboard and capturing keystrokes...)

    IMO. the real value is for Windows shops that want to utilize their existing investment in tooling/developer training, reuse existing core-logic code and/or write their core logic once in C#. For places like that it could be worth the several thousand dollars per developer.

  12. Re:They are wrong... by dgatwood · · Score: 4, Informative

    Don't listen to these ass clowns saying "Go with Obj-C". If they had any clue they would know that introducing Swift was the first step towards obsoleting Obj-C.

    Here's why you should learn Objective-C first:

    • There are billions of lines of production Objective-C code out there, and remarkably close to zero lines of production Swift code out there. If Swift is the first step towards obsoleting Objective-C, then the second step must be waiting fifty years for all the Objective-C code out there to get rewritten.
    • Swift isn't finished. From what I've read, they expect to make syntax-incompatible changes. Although they plan to have translators to move old code forward, do you really trust automated translators enough to run them on huge chunks of production code?
    • There's no assurance that Swift has staying power. Over the years, Apple has released bridges to many different programming languages over the years. Java? Check. Perl? Check. Ruby? Check. Python? Check. Now ask yourself how many of those bridges are still supported by Apple. If you only have time to learn one language, it should be the one that you know will still be popular in ten years.
    • Swift is designed to make it easy to build apps that include a mix of Swift, C, and Objective-C. Therefore, there's no reason to believe that it won't be possible to write fully capable apps for iOS and OS X in Objective-C for the foreseeable future. And even if, God forbid, Apple decides to be a bunch of a**holes and starts shipping a bunch of Swift-only classes in a reckless and desperate attempt to pressure developers to switch to Swift, you'll still only be a tiny bit of glue code away.

    That's not to say that Swift isn't interesting. The ability to test code on the fly is certainly cool, and if Swift proves to be a long-term-viable language, I'd imagine it will eventually (over a couple of decades) become the dominant language for OS X and iOS development. However, there's plenty of time to learn Swift. If you want to start writing real-world code today, you're better off learning Objective-C, because there are orders of magnitude more examples, you'll be more likely to find employment (there's way more Objective-C code out there to maintain), and more people can help when you run into problems.

    Ask again in five years, and the answer might be different, but for now, IMO, Objective-C is the clear choice unless you don't already know any C-based language, and probably even then.

    --

    Check out my sci-fi/humor trilogy at PatriotsBooks.

  13. Don't do apps. by Animats · · Score: 3, Insightful

    You say you're an experienced embedded-systems developer. Those are rare. Stay with that and get better at it. There are already a huge number of people grinding out appcrap, more than the app market can support. Soon there will be a glut of former phone app programmers, if there isn't already.

    Try to get in on the back end of the "Internet of things". That crowd is overrun with appcrap people and has no clue about embedded.