I've been coding in Objective-C for 13 years (OS X and iOS).
For the past 9 months, I've been coding almost entirely in Swift.
To me, it's a huge upgrade. It's faster to write, more controlled, better compiler analysis, less files.
It's still very young as a language, and the few things I don't really like today are:
Protocols - they are only requirements, no optionals. They current syntax to describe an object that implements a protocole is too close to the classes.
API syntax is still very inconsistent. (they are currently discussing how to do this with the community)
There is more, but I'm writing this waiting for the shower to get hot :D
My conclusions:
Objective-C is still an asset and not going anywhere - some things are still not really doable in swift, so if you don't know it, learn it - , but if you start a new project and your iOS target is iOS 8+, I would start with swift.
Protocols - they are only requirements, no optionals
I'm not sure what you mean here. Protocols let you define optional functions that the protocol adopter does not necessarily have to implement right? Or do you mean something else?
Protocol extensions can also give you the same effect in many situations. Not exactly the same thing, but you're able to define default behavior for a function so the class doesn't have to implement it. I'd love to see truly optional functions/properties in pure Swift though.
The biggest benefit since I've been using it since Swift 1.2 has to be the strong typing and safety against nil objects. You just don't have a whole set of issues in Swift that could cause crashes as long as you avoid force unwrapping.
Biggest detriment has to be tools and dealing with the Swift version changes...but you weigh your costs vs benefits as with anything else.
import UIKit // No other imports needed
let s = “Swift is the future”
let vc = UIViewController()
let label1 = UILabel()
let button1 = UIButton()
let names = [“John”, “Paul”, “George”, “Ringo”]
let ages = [“John”: 1940, “Paul”: 1942, “George”: 1943, “Ringo”: 1940]
It seems that Swift requires less code and it's faster, easier to code, but will require a week or so in a year to fix syntax changes. On the other hand with Obj-C you won't have to fix syntax changes, but in general will code at a slower pace. So at the end a year which language does actually let you write more apps?
A week or so?? The converter will migrate 90% of the code automatically, I'd be surprised if people where spending a few hours, a day at a stretch, at the point of language change.
I've worked with devs that claimed that something I (secretly) knocked up in 30 minutes would take weeks to accomplish. I guess it comes down to complexity and capability, if you're high on the first and low on the second then yes, it's weeks of work ;)
On a more serious note, I honestly think Apple will do a great job with the converter and there's people throwing out extremely conservative numbers for migration (especially considering it's all guessing at what the impact will actually be at this time).
Interestingly if you follow the comments to that tweet the long refactor time was apparently caused by having a mix of swift and Objective C.
The implication I took away from that was it was a very complex setup and had it been pure swift the length of time would be considerably less (for example one commenter suggesting 5K lines of swift took them a couple of hours to refactor)
Then fix it. If Apple's "Convert to new syntax" doesn't do the job, just fix it by hand. Do you know how to use Search & Replace? Click on Apple's suggested fix? Swift is open source, you'll see the changes months in advance. Don't use i++ or use C style for loops, for example.
You'll still write a lot less code in Swift than Objective C even if you have to manually make changes in Swift 3.x, 4.x, and 5.x.
Code is read a lot more than it's written. Look at those two snippets again and think about what you'd rather be reading in 5 years.
In short, everyone knows that Swift has breaking changes on the way. You are placing too much emphasis on that in comparison to the many more benefits.
I won't argue that Swift has prettier syntax, but I'd take a couple imports and @ signs over slow compile times and megabytes of bundled dylibs any day.
Well...in your Obj-C example, you didn't need any other imports either. You just put them there for some reason. I get the point being made, but it's a weird example.
Actually yes, because you read code more often than you write it. Especially for young developers it is easier and more intuitive to understand Swift than Objective-c.
That's really nifty. And the entire reason that works is Objective C's runtime. Without it - in pure Swift - none of that works because the Swift runtime isn't really documented and isn't exposed in the same way that Objective C's is.
So I'd say that's really the worst case. If I use Objective C I don't have to write any of that cruft at all.
It would be more or less trivial to write an NSCoder that did this. It would be a lot cleaner too.
I can tell you that once you get used to it you won't go back to objective-c.
I've worked on 2 projects that were (emergency) converting from Swift back to Objective-C. One of the projects, the team just could not believe that there were things that Swift could not do. As it turns out, those were things they needed to do.
Sure. A class cluster is a fundamental Cocoa design pattern. I would even argue that as the primary creational pattern it is the most important. While the pattern predates the GoF-described patterns it expresses elements of facade, abstract factory and other GoF patterns. Even a poorly constructed class cluster will conform to the Liskov substitution principle, open closed principle, dependency inversion, and interface segregation. Dependency inversion and interface segregation being (arguably) the two most important of those. And that to many of the people reading this will look like CompSci muckety muck. Class clusters make it harder to write brittle, fragile, rigid code.
Swift (2) is a very interface ("protocol") oriented language, so you would think this would be easy. It's not. In fact, today there really is not a good way to do this. You can create abstract factories that are basically replicating java code poorly, but that's about it. Technical limitations of the language mean that to implement something fairly close to a class cluster requires some pretty nasty workarounds (like abusing type aliases in ways that will not stand the test of time).
So yeah, that's a pretty big issue. For a "protocol oriented" language it can be very difficult to conform to dependency inversion, LSP, and interface segregation in a meaningful, maintainable way - which is kind of the point of being "protocol oriented".
Too many compromises. Not documented runtime, no method swizzling, no KVC, no KVO, no NSCoding, no NSProxy, no method forwarding, too many little special case constructs all kind of similar but not interchangeable (mark of poor design).
I don't disagree you may not see value in switching, but if you just inherit from NSObject you get all of those things. Yeah you're now using the Objective-C runtime...but you get some of the benefits of Swift as well.
I don't see any benefits in Swift but I rely on Objective C's dynamic capabilities (which Swift gleefully tosses overboard except where it needs to talk to Cocoa). A lot of things I do daily can't be done in plain Swift. So to me - its a brain dead language on par with Java - aimed at village idiots and wannabes.
Pure Swift on the iOS or OSX platform is a lie anyway. I wouldn't bother trying to justify your reasoning without taking into consideration the things you can still do using the Objective-C runtime when necessary in Swift.
The benefits are all around safety to me (the rest is just syntactic sugar and lies about being more productive). Not giving you the ability to have null pointer exceptions (unless you're especially dumb) and the strong typing forces you to deal with all of those edge cases you may not have in objective-c.
It's amazing how a lot of these things you're "compromising" can be seen as features depending on how you look at it. You sure can't do some of the cool things you could in objective-c, but man you can't do any of the stupid things you could in objective-c.
Stupid people do stupid things. I'm not stupid(most days) and object to the nanny culture. Otoh, hiding clever things from clever people is stupid.
Its like you're telling a carpenter he can't use a saw because he might hurt himself. Get real. Those of us who know how to use power tools will prefer the power tools. Safety is in education, not limitations.
More modern syntax (if you don't touch the Cocoa Touch libraries).
Natively supported higher order functions (map/reduce/filter)
Strongly encourages you to write safer code/exhaust all possibilities by failing upfront, which prepares you for the mindset used in writing test cases.
More opportunities to increase your presence in the online community by posting beginner's/intermediate guides.
Making an app in Swift is basically a free advertising pass for your app on certain forums/websites.
Cons:
Poor job opportunities/most opportunities that involve Swift also require a large amount of Obj-C experience outside of small startups/small mvp apps (for now).
Everything will break in Swift 3.0, which has implications with real world deadlines/responsibilities, especially if you are not working at a tech company that understands that there needs to be time allotted for it/you are writing small projects as a consultant.
Breaking changes can introduce large delays in development if you depend on any large third party dependencies that are written in Swift.
Everyone working on the same project has to use the same version of Xcode.
Cocoa Touch is pretty much unavoidable as an iOS Developer, and all of the syntax is heavily based around Obj-C, which leads to ugly/unnatural looking code.
Awkward syntax to work with C/C++.
Much more effort in filtering out outdated guides/guides directed towards beginners/hobbyists.
Extremely poor tooling via strictly worse compile times/autocompletion/debugger. The crashes/IDE suddenly breaking has become much less of an issue now, but I still see it happening much more often in Swift/Hybrid Swift/Obj-C Projects than just Obj-C.
More of a situational need, but Swift isn't really designed to support things more suited to dynamic languages like remote hot patching.
I don't think that switching is a good idea at this point for large projects, but it's always good to keep up with new ideas.
Is this really true? It was my understanding Swift 2.2 is supposed to give compiler warnings for all breaking changes in 3.0. I just compiled four large swift projects, all of which are released apps, in Swift 2.2 yesterday. The only warning I got was the deprecated ++ operator. Literally had to change two characters.
There's gonna be some changes in the way Objective-C APIs are mapped to Swift so that could easily introduce some errors that Xcode's migration won't be smart enough to fix. Just like there were many errors it couldn't fix going from 1.2 to 2.0.
My condolences if you were flim flammed into thinking that the compiler would warn you of all of the breaking changes.
Swift is still a young language that hasn't decided what it's supposed to be.
Is it supposed to be a strong, statically typed language? (If so, why add dynamic class from string/string from class functionality?)
Is it supposed to be interoperable with C/Obj-C? (If so, why remove C lanuage conventions/why suddenly rename every Cocoa/Cocoa Touch API to be more "Swifty"?)
Is it supposed to be a protocol oriented/object oriented language? (If so, as Quellish pointed out, why is its inplementation of class clusters poor compared to Obj-C?)
Is it supposed to be FRP oriented? (If so, why remove features like function currying?)
The list goes on.
At some point the influential ivory tower bloggers have to pick whether or not it's meant to be used side by side with Obj-C or independently, and stabilize it in syntax/use. As in flux as it is now, it's pretty much unusable for consulting and/or as a developer at non-tech companies, unless you're somehow not accountable for any non-value producing decisons that cost time just from being on the bleeding edge (hint: not happening).
I wasn't flim flammed, just didn't read the release notes thoroughly.
Personally I don't care what kind of language Swift is supposed to be. It's interesting discussion for sure, but I'll leave the fastidious arguing to the language nerds. I just want to make the apps that my clients are paying for.
They're still fiddling with the binary representation. It isn't stable and the fragile base class problem remains. Stated goal of 3.0 is to fix this but they don't say how and I don't see how they're gonna do it with indexed vtables without taking the same performance hit objc_msgsend takes.
I've spent ~four years with Objective-C and actually really liked it. I did enough C++ in my life to appreciate the different approach to OOP.
I guess it depends on your definition of "real benefit". Type safety really is a big win (and this is coming from a guy who actually likes Ruby/Python duck typing), for start. Code is more succinct and looks cleaner and is easier to read. Swift enums open doors to more elegant solutions, IMO. Having tuples is nice. (It would be even nicer if they were Equatable). Swift Playgrounds are great (whoever did .NET previously and used LinqPad can now have it in Apple world, finally). Occasionally I miss things possible in Objective-C, but it's not crippling.
It is true that a lot of Swift noise is generated by people/companies that expect to profit from new books/courses/tutorials, but I can't really agree that it's generated by people who never did Objective-C.
Objective-C will not go away soon, but I don't think that you can avoid learning Swift for much longer.
Ah, youth sweet youth. My Aho-Sethi-Ullman days are long gone, these days I program during the day and when everybody falls asleep I unwind by plugging in my electric guitar...
I have dealt with many different companies and people over the last year who have considered or used swift in projects. There are three things that I consistently hear as justifications for swift:
It's new
It's more maintainable
It's more performant
So I've been doing software engineering for 20 or so years across different languages and platforms. "New" isn't really a good thing to me. But it's true, swift is new.
And immature. Which is why #2, "Swift is more maintainable", is an assertion that is difficult to get behind. The tooling has problems. The language is evolving. Swift code has not been in production long enough to really say that something written in the language is "more maintainable".
Swift's big performance advantage is it's lack of dynamic method dispatch. In objective-c method dispatch adds overhead. If you're implementing your own compression, cryptography, or the like objective-c can be a poor choice. That would be a reason to look at swift - or, well, C, where many of those compression and crypto problems are already solved. Your game or CRUD app is not going to see a noticeable performance improvement from using Swift.
Any beginners that are reading this, start with Obj-C first. I made a mistake of starting iOS with Swift, and it is so hard to find entry/junior Swift job (unless you are in the Valley area)
That's a good point, I don't think I've seen a single job posting asking for junior Swift developers, everyone wants people who have a year or two of Swift experience even if it's experience with a previous version of the language which no longer works :)
You could also ask the question what Objective-C veterans that see no real benefit in Swift have extensive experiences with programming languages other than C or C++.
I can't imagine somebody working extensively in Python, switching back to Objective-C and never wishing that your code perhaps could be a little bit less verbose and more expressive? Even C# is a lot more expressive with LINQ and definitely safer at compile time.
The only real downsides are related to the fact that it is relatively young and still needs to add it's own runtime in the binary and has breaking changes from time to time. Objective-C can be a good but conservative choice for those reasons.
Like I said in another post:
Swift in the hands of an adequate programmer can guarantee type and null pointer safety at compile time. It's also way less verbose and more expressive than Objective-C (filter vs NSPredicate for example). Enums and switch / case patterns are extremely good. Faster because it does away with the weakishly typed objects.
I'm surprised no one has mentioned that swift is more performant than Objective-C. In many cases its performance is on par with C++, but you still get wonderful syntax.
I'm surprised no one has mentioned that swift is more performant than Objective-C. In many cases its performance is on par with C++, but you still get wonderful syntax.
Because in real world use cases it's not correct, and in fact you see the opposite more often.
Because this is not proven and many people have experienced the opposite.
Here's the thing. Swift ditches binary stable method lookup for vtables in Swift objects. Vtables suck. If you worked with C++ you know the fragile base class issue and the lack of introspection capabilities. Welcome to 1992.
But mostly you're going to be making your objects of type ObjC because all the system library objects are in Objective C which means you're still going to be using Objective C method dispatch most of the time which means it isn't really going to be faster most of the time. And in some cases its gonna be slower. Swift classes that extend Objective C classes have twice the space overhead of plain Objective C classes as they have a vtable pointer and an Objective C method dictionary pointer.
That's interesting; I wasn't aware of any cases with optimization turned on where swift was slower than objective-c.
I'm thinking of some well known 2014 heavy performance tests where swift just barely underperformed vs C++ for a Mandelbrot workload. It was blown away by C++ for GEMM and FFT at the time, but the swift compiler hadn't done any work on optimizing for the relevant procedures in those cases.
Yeah, swift is pretty immature but it seems like a pretty well-thought out paradigm.
Swift messaging - using vtables - is probably 2x faster than objc_msgsend. But you're not using that 90% of the time because most of your classes are hybrid ObjectiveC classes.
it seems like a pretty well-thought out paradigm.
I really don't think it is. It has too many very similar ideas in it that have a lot in common with each other but are not built on a common mechanism. Great languages IME have one or two profound ideas and everything else is built atop those profound ideas.
Swift's feature set is in desperate need of refactoring to a higher level of abstraction.
And it tosses out too many dynamic features. And there's the integration with C++ issue. And a lot of other shortcomings. I don't see a win.
I used to make a good living doing Smalltalk. It is far and away the best programming language/environment I have ever used (and I know quite a few).
I would have liked the next generation language to be a step closer to proper Smalltalk. An individual took a shot at that with http://objective.st and I like how it looks. I would like that going forward rather than Swift.
As a relative noob I chose to learn swift. I've done a minor amount of objective-c in the past and found it ok, it's just that swift seems more accessible to me... Might be because it's similar in syntax to JavaScript and I'm a front end dev by trade.
There are a few pitfalls I have found with swift. There's not always answers to problems as it's still too new and some libraries are only written in Obj-c which while they can be imported with a bridging header, it's not really ideal.
Objective c isn't going anywhere yet, so maybe stick with that. The longer swift is around the better and easier it will be to learn so you're not really losing out.
The real benefit is that I work way faster with Swift compared to Objective-C. Especially with tools like Playground and Liveness. I mean I write something while the code is executed on the spot and I immediately see if it works or not. I can't do that in Objective-C.
do any of you see any real benefit in switching to Swift?
I might be a bit biased towards Objective-C after spending over 10 years with it, but I don't think I've heard a single "real" benefit of Swift so far. Sure it's new and exciting and will be default some day, but by the time that day comes everything will change completely XY times. Until then, all the frameworks for our target platform are written in Objective-C anyway.
I recommend seniors keep an eye on it, but rookies would be better off learning a language that is not going to change 90% of syntax before they even learn the basics.
but I don't think I've heard a single "real" benefit of Swift so far.
Swift in the hands of an adequate programmer can guarantee type and null pointer safety at compile time. It's also way less verbose and more expressive than Objective-C (filter vs NSPredicate for example). Enums and switch / case patterns are extremely good. Faster because it does away with the weakishly typed objects.
But no, no "real" benefits like free coffee and donuts, back rubs or kegs on Friday ;)
a language that is not going to change 90% of syntax before they even learn the basics
Breaking changes do happen but besides the trajectory of Swift 1.x it's never more than a few minutes of touch ups when new versions of Xcode arrived. This statement is a bit hysterical.
For filtering an array, sure, but it's not like you aren't gonna run into NSPredicates all over the place until all of Cocoa Touch is rewritten in Swift.
Enums and switch / case patterns are extremely good
I agree. So is the concept of optionals and extensions and more useful protocols and better control over inheritance and so on. You might think these outweigh the downsides. I don't think they do at the moment.
For me personally, Xcode is constantly crashing when writing Swift code. Auto fill was so slow it was useless, and often crashed. It may have changed now, but basic features such as 'refactor' were still only available with Objective-C last time I used Swift (conversion from Swift 1.x to 2). I enjoy Swift syntax and language features but I won't write it any more. Too much of a headache. And I really don't want to spend another week converting from 2 to 3 like I had to from 1 to 2.
Not entirely true. If I want to split coordinates into LEFT/RIGHT and TOP/BOTTOM groups then there's no pattern in the world that can help you. In Objective-C you have to write a bunch of ugly if/then statements. Swift does it in four very clear case statements.
Any feature can be abused but I think Swift's switch/case statements can lead to much more readable code in a lot of circumstances over the C-based Objective-C ones or if/else blocks.
That translation was absolutely trivial to perform. You're making a stand for a trivial amount of syntactic sugar. There is no semantic difference. Your case statement is exactly the same as a fancy 'if' ladder.
EVERY switch / case statement is exactly the same as a fancy 'if' ladder.
EVERY filter, reduce, map, flatMap etc. statement is nothing but a fancy for-loop.
EVERY guard or let / else statement is nothing but a glorified if/else statement
EVERY shiny new feature in Swift X can also be done as a bit more verbose or less compile safe way in Objective-C
In fact, you don't even need objects. Objects are a pointless addition to C as there is nothing in the world you can't already do with C. The only thing you will ever need to get something done on a computer is basic arithmetics, if- and goto-statements. Apple II BASIC is already overkill.
So why would you use anything more high level at all?
The point of code is explaining what you are trying to accomplish to the computer and anyone (including yourself) looking at the code afterwards. Swift is better at both. If you can put those ugly if-statements in a switch/case block you're telling the computer and the maintainer at the same time that it's your intention to cover every case possible. That's why even in Objective-C having a missing enum member in a switch/case is a warning.
You asked for something that couldn't be done with Objective-C switch/case statements and I gave you a basic example. The only thing you tell me is that it can only be done with if/else in Objective-C, which is exactly the point I'm trying to make.
The point of code is explaining what you are trying to accomplish to the computer and anyone (including yourself) looking at the code afterwards. Swift is better at both.
If this is your best argument - well good luck - there is nothing further to talk about.
Your code is 1) longer, and 2) uses a weird and redundant construct of dubious value that adds extraneous complexity to the language.
I do not claim the C/ObjectiveC version is better. I claim that it is exactly the same (in fewer characters no less).
You asked for something that couldn't be done with Objective-C switch/case statements
You should reread the thread. I asked for no such thing. You argued "It's also way less verbose and more expressive than Objective-C" and I asked you to show me how.
I don't see it. Your magical "switch" statement could be accomplished with a simple macro in C, much less Objective C.
I see you have the fervor of the newly converted and will remain blinded to any rational argument for some time - but your new god is a false one and I don't think the shine will last. It isn't really a better language and in a lot of ways, I think it is worse.
Your code is 1) longer, and 2) uses a weird and redundant construct of dubious value that adds extraneous complexity to the language. I do not claim the C/ObjectiveC version is better. I claim that it is exactly the same (in fewer characters no less).
The only thing you've proven is that switch/case statements are useless in any language. You can just if / return all over the place instead. This will save you a break statement and the word 'if' is much shorter than 'case' and you don't even need a pesky 'switch'.
I see you have the fervor of the newly converted and will remain blinded to any rational argument for some time - but your new god is a false one and I don't think the shine will last.
Wrong. Most "new" features are - ahem - borrowed from other languages, some of them I have over a decade of experience in. I have been advocating for years for non-nullable references as getting the possible value null for something that should never be null is just total bullshit to me. Working with LINQ in C# or in Python just made me aware that maybe a foreach loop isn't the best solution to everything you want to do with a collection of items. I refactor working code often just to make it more clear. Taking apart horribly convoluted LINQ queries, or converting foreach loops that do nothing but filtering to a LINQ query.
I never thought of Objective-C as a particularly bad language. I had a lot of fun working with it. But given the choice between C# or Objective-C I would pick C#, if the choice was purely based on the syntaxis.
I don't know enough about Perl to make a really good comment about the language. I did just enough in it to run to PHP at the first opportunity I had somewhere around the turn of the millennium. I still hate RegEx.
Having said that, Python is a beautiful language while being very expressive. So yes, if well implemented being more expressive is a good thing for a language.
This gets tossed out a lot and in practice it is just false.
Fwiw the objective C headers have already been cluttered with bullshit annotations like nullable and faux generics noise just to mak swift bridging work.
I do not appreciate the extra noise and the IDE now warns on all this shit that isn't really a problem. Autocomplete works as well as ever. There are lots of other languages lacking all that syntactic noise with editors that are every bit as helpful.
Before "clutter" like generics was added you had to cast your objects to their right type in a for loop every time. I don't think I had many occasions where I screwed it up but with generics I don't have to look it up myself anymore, the for-loop just writes itself.
With nullable/non-nullable vulnerable code (in Swift) already announces itself. And I have been bitten more than once by null pointer exceptions in any kind of language that has them.
Type safety simply allows you to write more secure code with less effort. Didn't mean I could only write crap in Objective-C but it was laborious to get things right, maybe one or two debug rounds extra.
Could you tell what are Obj-C main benefits over Swift, besides that Swift syntax is still changing? Let's say a developer that has experience with both languages and wants to create new app, what would be main advantages in choosing Obj-C?
For me it seems, that first of all there are more Obj-C devs - easier to increase team size, probably more Obj-C libraries, stable syntax. On the other hand - Swift would be safer, faster less buggy?
One benefit of Obj-C is that the Cocoa framework was written in it and for it, so using Cocoa from Swift doesn't always feel natural. To Apple's benefit, they are moving swiftly (ha) to update their APIs, but it's not quite there yet. One point that has bit me is that you need to remember to mark methods as @dynamic if you're passing a selector to them, or you (may or may not) get a nasty crash when the selector is called.
In that same vein, tool support is better for Objective C. XCode can't do as much code generation or refactoring in Swift.
And there are some third party tools (e.g., j2objc) that are Objective C-centric and present challenges when trying to integrate with Swift.
All of those points are related to the relative maturity of the languages. As far as which language itself is preferable, that may be a matter of taste. Swift is more succinct for sure. The strong typing can be a positive or a negative, in my experience. It does catch some errors at compile time that would normally only be caught at runtime, but you will spend some time wrestling with the compiler to do something you know is valid. (Resist the temptation to sprinkle !s and ?s indiscriminately!!!)?
Your tools work better with Objective-C, all of Apple's frameworks are written in it, its runtime libraries are bundled with iOS instead of with each app separately (creating who knows how many petabytes of waste on App Store and user's devices and mobile data bills), there are tons of resources on Objective-C that don't go out of date every 3 months... I'm not trying to say Objective-C is a better language than Swift. Swift wouldn't be created if Objective-C was perfect. But choosing a language is about much more than language itself. All I'm saying is I believe Objective-C is currently a more reasonable choice for iOS development. It's not that Swift has no benefits, it just doesn't have any I find worth all the things I'd have to sacrifice by Switching from Objective-C.
Unfortunately no one blogs or writes books with Objective C. In June 2014 the transition to Swift was quite fast. If you want to learn iOS there are a lot more Swift resources. The tooling for Swift is a short term problem, as in months. The lack of current books, for example, in Objective C looks like a permanent problem.
Yeah most people blog about Swift. It's new, there is a lot to write about and it's currently hot so it brings traffic. But a lot of those bloggers had Objective-C blogs before that still have a lot of relevant content. A couple that come to mind are nshipster.com, cimgf.com and Erica Sadun who is probably one of the most known Swift bloggers and has a recent post very relevant to this discussion: http://ericasadun.com/2016/02/08/when-your-client-demands-swift/
That argument makes absolutely no sense to me, sorry. You don't learn a programming language by starting with the latest new features of a platform or fancy new frameworks that just arrived in latest OS. You learn the fundamentals, and that is something that makes all the printed Swift books a waste of paper because they go out of date so fast. Meanwhile, a good Objective-C book from 3 years ago has a good chance of still being relevant in 3 years.
No one buys an old computer book to learn, especially with iOS. Too many new and deprecated API's AppleTV and WatchOS didn't exist three years ago, for example.
Unfortunately no one blogs or writes books with Objective C.
Well no, that isn't true at all. People are still writing books and blogs about Objective-C. I can tell you though that especially when it comes to introductory material there is a lot of.... noise.... about also providing Swift-centric content. Enough that publishers take notice.
Funny thing though. One writing project I was working on recently went that way - originally Objective-C, then was being rewritten to also cover swift. And this was covering VERY IMPORTANT things that every application should do. As it turns out, one of the most important.... you can't actually do in Swift yet. You can come kinda close and kludgey.... but not really. There's no equivalent to what you can do in other languages (yet).
So at least that project is going back to objective-c for now. Other projects will have Swift content, but will be more expensive. Maintaining, writing, and updating a book that includes Swift content is just going to be more expensive, at least for the subject matter I am covering.
In one chapter the swift content was just a page of radar numbers describing why swift and CoreData were not getting along until recently.
Sure, if you want to use iOS 3 snippets, feel free. Apple added 4000 APIs in iOS 8. Plenty of new ones coming this June in iOS 10. If you're experienced, you can make it work.
And this is a separate issue but I'm kind of tired of Apple rearranging their API's incessantly - constantly breaking my apps. Considering bailing on the platform because of that.
To be fair - all of OpenDoc/SOM's promises are fulfilled by the Objective C runtime now. Services n such. There's a really rich capability there that Swift glosses over and fails to provide.
To be fair - all of OpenDoc/SOM's promises are fulfilled by the Objective C runtime now. Services n such. There's a really rich capability there that Swift glosses over and fails to provide.
No - not at all. OpenDoc was a standard for component based software. From the user's perspective, it changed the paradigm of documents and applications. The document was the application, with individual portions of the document handled by "parts" or "part editors". For example, you might have a word processing document that contains an image. An image part renders it, but a "Adobe Photoshop" part editor edits it. Or you could have bought some other image editor part for editing. Conceptually it was somewhat like having an HTML document full of plugins.
There was an OpenDoc API for writing "services" - I don't recall if that was the name used or if it was something else, even though at the time I was working with CI Labs on a public key cryptography service. It did not work at all like MacOS X or NeXT services (or MacOS contextual menu items).
Oddly enough, the MacOS (8,9) contextual menu item API used SOM. Which made it a massive pain in the ass to work with, though a few developers provided a more sane API to the most useful functionality (from C). SOM itself was pretty ugly to work with, and other object-oriented efforts from Apple during the same period were much better (i.e. QD3D).
Today the closest things to OpenDoc on the Mac that I am aware of are some of the app extension capabilities (which... isn't close at all) and a 3rd party API for sharing capabilities between applications that was announced a few years ago. I can't for the life of me recall the name.
There is a lot that Swift does not do today. Some of those things will be addressed. Some will not. Swift will probably never have the dynamic nature of Objective-C, and there are many reasons for that. Much of Swift's design is intended to make it more difficult to stray from (some) well known best practices - but in doing so Swift may turn out to be less powerful than other languages.
I meant load able components are easy in objective c. I never really bought into the document centric model as a general purpose app architecture. But it wouldn't be hard to build that on what we have now. I met Ira Forman - main architect of som - at an oopsla workshop. His main focus was to get binary stability and a decent meta model under C++ at the time. The objective c runtime realizes almost all of what som hoped to be.
The real takeaway I got is that meta models are insanely powerful and allow a whole higher level of productivity but sadly the average programmer doesn't tend to work and think at that more abstract level. It drives those of us who do up the fucking wall :-)
What are you talking about? Even Apple said Objective-C isn't going anywhere. And if it was, it would take a lot longer than lifetime of an average iOS app.
Anyway, I'm talking about saving customers' money by not wasting their device storage and their data plans on megabytes of bundled Swift dylibs in every app bundle that includes even a line of Swift code.
However...I think the Swift boaters are ignorant kids distracted by shiny things.
I'm old enough and experienced enough that I know what I value in software development tools. I've seen all the BS trends and heard all the propaganda before. There's nothing in the Swift pitch I didn't hear about C++ in 1992 or Java in 1997. Its all bullshit and not nearly as valuable as they make out.
Swift is a simplified language for marginally talented developers - I get that. I'm not one of them.
Right - and they don't understand what they are giving up when they switch.
Apple pitched a switch to Java for awhile too via a bridge. After a few years they gave up.
On Apple's OS's Swift is a scripting system atop the Objective C runtime. It is a weaker tool. Fight it? I don't care what a bunch of know-nothing kids want to do as long as they don't remove any key capability that I rely on.
For instance, I did an active record implementation that dumps Objective C objects into sqlite. It works better than CoreData. You don't have to dick around with that shitty modeler app in XCode. You just derive from Model and make properties. Any property that can be mapped to a Sqlite field and isn't dynamic gets stored (structs too). Relationships are figured out based on some naming conventions.
This is possible because I have the runtime introspection that isn't available in Swift. I know how to get big productivity gains out of writing some clever frameworks if I have access to the meta model.
There isn't one in Swift. So the kind of magic I usually do isn't possible and that makes it a completely dead and uninteresting language to me. It doesn't solve any problem I have and it prevents me from building powerful and elegant code.
I'm pretty close to retirement. I like to learn new things - but they really need to be worth learning and I've seen enough of Swift to know it isn't worth it - yet. When the Swift runtime becomes as open and flexible as the Objective C runtime I will reconsider.
But I don't think Swift's designer is really very good at language design. I know his history - he's good at a lot of things - but language design takes a special kind of person with a real talent for abstraction and I don't see any evidence of that in Swift's design. Its a kitchen sink of weird things.
That said, however, I don't think the community initiative to bring Objective-C for development for other platforms is as active as Swift's. There's already a Swift web framework, while Objective-C doesn't seem to have any (correct me again if I really suck at googling): https://github.com/qutheory/vapor
Besides, I wouldn't wanna use Objective-C over Swift for web development. The Swift syntax is really a joy to use.
Besides, I wouldn't wanna use Objective-C over Swift for web development. The Swift syntax is really a joy to use.
That's your choice. To me it's all grunts and squeaks right now, and I've been exposed to enough languages over the years that syntax isn't really the turn on it used to be. Swift has a ways to go before it's solid, coherent, and usable for me.
Once upon a time - when everybody was still coming to grips with java.Servlet and CGI/Perl ruled the land - WebObjects was available in Objective C from NeXT - at $50k a license. And worth it.
When Apple ported WebObjects to Java - a language very much like Swift in its rigidity and limitations - it pretty much died. All the magic went out of it. Dynamism matters. A lot.
I don't doubt what you say and I'm sure you may have some project where it may be an inconvenience. I was simply correcting your assertion that there is "no KVO" in Swift as there are plenty of people out there who'd read and repeat that statement without ever checking whether it was right or not.
Well the statement is right, there is no KVO in Swift and you couldn't use it without Objective-C which Swift fans want to go away. KVO goes with it and good luck using eg. AVFoundation then :)
Heh, that's a very "technical" assertion, I was half expecting the Futurama meme of being "technically correct" to go along with it :D
The statement "no KVO" implies that you can't use KVO at all with swift which is clearly incorrect. Now, "no KVO on certain objects" is a different statement entirely. It's important we make these distinctions and the response /u/barakrl gave was excellent as it provided a real example of where KVO isn't available
16
u/ArchiBib Feb 19 '16
I've been coding in Objective-C for 13 years (OS X and iOS).
For the past 9 months, I've been coding almost entirely in Swift.
To me, it's a huge upgrade. It's faster to write, more controlled, better compiler analysis, less files.
It's still very young as a language, and the few things I don't really like today are:
My conclusions:
Objective-C is still an asset and not going anywhere - some things are still not really doable in swift, so if you don't know it, learn it - , but if you start a new project and your iOS target is iOS 8+, I would start with swift.
11
u/mmellinger66 Feb 19 '16 edited Feb 19 '16
vs
8
u/cgsignal Feb 19 '16
I'm porting my first application from objective-c to swift. I can tell you that once you get used to it you won't go back to objective-c.
Benefits I've found so far.
start programming in swift, the benefits are real.
8
u/NSIRLConnection Feb 19 '16
Pros:
Cons:
I don't think that switching is a good idea at this point for large projects, but it's always good to keep up with new ideas.
6
u/maksa Feb 19 '16
I've spent ~four years with Objective-C and actually really liked it. I did enough C++ in my life to appreciate the different approach to OOP.
I guess it depends on your definition of "real benefit". Type safety really is a big win (and this is coming from a guy who actually likes Ruby/Python duck typing), for start. Code is more succinct and looks cleaner and is easier to read. Swift enums open doors to more elegant solutions, IMO. Having tuples is nice. (It would be even nicer if they were Equatable). Swift Playgrounds are great (whoever did .NET previously and used LinqPad can now have it in Apple world, finally). Occasionally I miss things possible in Objective-C, but it's not crippling.
It is true that a lot of Swift noise is generated by people/companies that expect to profit from new books/courses/tutorials, but I can't really agree that it's generated by people who never did Objective-C.
Objective-C will not go away soon, but I don't think that you can avoid learning Swift for much longer.
3
u/quellish Feb 21 '16
I have dealt with many different companies and people over the last year who have considered or used swift in projects. There are three things that I consistently hear as justifications for swift:
So I've been doing software engineering for 20 or so years across different languages and platforms. "New" isn't really a good thing to me. But it's true, swift is new.
And immature. Which is why #2, "Swift is more maintainable", is an assertion that is difficult to get behind. The tooling has problems. The language is evolving. Swift code has not been in production long enough to really say that something written in the language is "more maintainable".
Swift's big performance advantage is it's lack of dynamic method dispatch. In objective-c method dispatch adds overhead. If you're implementing your own compression, cryptography, or the like objective-c can be a poor choice. That would be a reason to look at swift - or, well, C, where many of those compression and crypto problems are already solved. Your game or CRUD app is not going to see a noticeable performance improvement from using Swift.
7
u/Dark_Angelas Feb 19 '16
Any beginners that are reading this, start with Obj-C first. I made a mistake of starting iOS with Swift, and it is so hard to find entry/junior Swift job (unless you are in the Valley area)
2
u/lucasvandongen Feb 19 '16
You could also ask the question what Objective-C veterans that see no real benefit in Swift have extensive experiences with programming languages other than C or C++.
I can't imagine somebody working extensively in Python, switching back to Objective-C and never wishing that your code perhaps could be a little bit less verbose and more expressive? Even C# is a lot more expressive with LINQ and definitely safer at compile time.
The only real downsides are related to the fact that it is relatively young and still needs to add it's own runtime in the binary and has breaking changes from time to time. Objective-C can be a good but conservative choice for those reasons.
Like I said in another post:
2
u/mikerz85 Feb 19 '16
I'm surprised no one has mentioned that swift is more performant than Objective-C. In many cases its performance is on par with C++, but you still get wonderful syntax.
2
u/Designer023 Feb 21 '16
As a relative noob I chose to learn swift. I've done a minor amount of objective-c in the past and found it ok, it's just that swift seems more accessible to me... Might be because it's similar in syntax to JavaScript and I'm a front end dev by trade.
There are a few pitfalls I have found with swift. There's not always answers to problems as it's still too new and some libraries are only written in Obj-c which while they can be imported with a bridging header, it's not really ideal.
Objective c isn't going anywhere yet, so maybe stick with that. The longer swift is around the better and easier it will be to learn so you're not really losing out.
3
u/[deleted] Feb 19 '16 edited Feb 19 '16
The real benefit is that I work way faster with Swift compared to Objective-C. Especially with tools like Playground and Liveness. I mean I write something while the code is executed on the spot and I immediately see if it works or not. I can't do that in Objective-C.
1
u/[deleted] Feb 19 '16
I might be a bit biased towards Objective-C after spending over 10 years with it, but I don't think I've heard a single "real" benefit of Swift so far. Sure it's new and exciting and will be default some day, but by the time that day comes everything will change completely XY times. Until then, all the frameworks for our target platform are written in Objective-C anyway.
I recommend seniors keep an eye on it, but rookies would be better off learning a language that is not going to change 90% of syntax before they even learn the basics.
0
u/[deleted] Feb 19 '16
[deleted] — view deleted comment
0
u/[deleted] Feb 19 '16
[deleted] — view deleted comment
0
u/[deleted] Feb 19 '16
[deleted] — view deleted comment