You can't do that in swift.
Objective C was a compromised version of small talk. And swift is a compromised version of a true modern language.
I'd much prefer a non compromised small talk.It's better for medium size mobile apps.
And until the rest of the libraries are in swift it doesn't feel very different.
It's like you're writing Python but you're forced to use Java libraries and Java style apis.
I hope apple doesn't ram it down our throats. Well their own frameworks depend on its dynamism and In many ways in my limited opinion objective c is better for developer happiness.
However I have found benefit in having strict model types that my JSON data must map into — or else cause compiler errors. I far prefer to pick up problems up at compile time then learn about them at run time.
Swift you're always contorting yourself to express things in a way that the language wants, it reminds me of writing java, it worships far to heavily at the altar of type safety as if type safety was a goal in and of itself.
ObjC is practical, Swift is academic.
I've enjoyed my time with Objective-C very much. For consumer coding, I think it's very close to the safety/expressiveness sweet spot.
It was the first place (pre-ARC) that I learned to manage my own memory, and the first (pre-GCD) that I learned to be as safe as possible in a multi-threaded environment.
If in fact Swift is the death-knell of Objective-C, I will be sad. I've written C and C++ and Python and Go and Scheme and Lisp and on and on (Java, C#...) and it will remain one of my favorites for years to come.
Not academic research as in we did a study of developers who write iOS apps and determined that type safety as implemented in swift helps great developers write apps faster. (F# on the other than has a great type system that doesn't get in your way)
Choosing more type safety over less is a pragmatic concern - one input among many into the cost benefit analysis we all do when picking languages and platforms. More type-safe languages tend to have more boilerplate and hoops to jump through, but they also tend to be more robust. The latter can be proven theoretically more efficiently than with empirical research, but it is no less true for it. We are limited by the laws of mathematics, however 'pragmatic' we fancy ourselves.
I think it's worth hearing Linus out on the reasons you might want to choose a less type safe language over a type safe one.
Type safety is not the only good in a programming language.
PL is not an empirical science in that sense, it's more like mathematics. So your initial intuition about type safety, etc. is right on the money—that's the academic side of it.
If you use swift features then your class is inaccessible to ObjC. If you mark your class @objc then you can't use many swift features.
The only thing that works well is writing most of your app in swift and writing ObjC wrappers for C/C++ code, because dealing with C in Swift is atrocious and many libraries simply don't work in Swift because of initialization issues with complex structs.
Also, having two tools to choose from that do practically the same thing is never really a good idea because you waste time trying to figure out whether Swift->ObjC interop is going to fuck you over more than ObjC->Swift interop for this particular class.
Also, once you start mixing code and have your code importing a Swift header and your Swift bridging header importing your ObjC classes you start getting huge compile times as anytime you change an ObjC header your entire swift code has to be recompiled which takes forever because the swift compiler is dog slow.
My advice, pick one language for your project and stick with it, the language I would advise until Apple writes base libraries in Swift is ObjC, because if you run into performance issues C/C++ is going to save your ass far more than Swift will.
And mostly because
var cell = tableView.dequeResuableCell("foo") as! CustomTableViewCell
is MORE typing than
CustomTableViewCell *cell = [tableView dequeResuableCell:@"foo"];
Personally, I find the concept of NULL (though toxic) more comprehensible and manageable than all those question & exclamation marks in Swift.
Sounds like RubyMotion.
I'd expect Objective-C jobs, though, to decline in number over time as Swift jobs rise. If you're doing it professionally, not learning Swift is going to increasingly limit your options, perhaps pretty rapidly — a few months ago, I got turned down for a job in part because of lack of Swift experience. Ended up landing a different job where we're writing a Swift app and step 1 for everyone on the team was "learn Swift".
Swift is not completely bad per se, but it's far from being as approachable as C. In C, you only need to read all the header files, then you “know everything”. In Swift, there aren't even any files with declarations you _could_ read. But then, a completely obscure language seems like a perfect fit for a walled garden.
Instead of realm.io, I went to the youtube url instead:
The notes say: "THIS VIDEO IS NOT MEANT TO BE WATCHED ON ITS OWN. We went to great pains to synchronize it with the speaker’s slides,"
Well, the embedded youtube at realm.io only allows speed of 1.5x.
The direct youtube url has the speed option for 2x, so I watched it there. However, before I saw it, I spent a few seconds to flip through the slides to get an idea of what Aaron was speaking to.
For example, at the beginning, he says the word "tricycle" and when I searched for that word, it wasn't in the text below. That's when I knew it wasn't a full transcript.
When I see the bugs going on in iOS apps, it has to do with models that are broken for what modern programs looks like today: things like asynchronicity. Animation is still a mess to wrap your mind around when you have a series of asynchronous events (animations, loads, what have you) that are tied together, but can also be canceled half way through. This is why I can still break many apps by just tapping all over the place (or clicking all over the place: http://tolmasky.com/letmeshowyou/Yosemite/Safari%20Animation... ).
Combining the determinism of React style immediate mode drawing with JS async/await is truly exciting for app development.
Now, of course the elephant in the room is that neither of these matter that much when most the apps being written are games that will continue using C++ or Unity (if you actually care about speed these are your best bet). Especially with the work Apple is doing with Metal that will improve these platforms as well.
Yes. Performance maybe not. But power efficiency is. If your mobile app is bloated and takes more resources than needed to perform its task then you're wasting the user's battery.
"Swift is not the ultimate language, it’s not flawless, it is compromised because of Objective-C interoperability."
In old mailing lists posts (https://www.geeklair.net/~dluke/PCIdevice_tutorial.txt), Godfrey van der Linden (one of the IOKit architects) made some comments about the IOKit language choice:
As IOKit is a child of DriverKit which was implemented in ObjC we
wanted to reduce the amount of work necessary to convert from one
space to the other, as ObjC is single inherited this was easiest for
most of our drivers. At first we were going to allow multiple
inheritance as we ported to C++ but then we tripped over the whole
can of worms called 'virtual' inheritance. We really, really didn't
want to turn all of our developers into C++ experts, which you have
to be to use virtual inheritance properly. Another side effect is
that we are now reasonable language independent. At some stage in
the future we may be able to move IOKit over to a good programming
- programmer familiarity/comfort level: remember that classic Mac development was mostly being done in C/C++ by the mid-90s, and the Mac developers still around by 2000 didn't need to be given more reasons to jump ship. Carbon was created so that Mac C/C++ applications could be brought to X, and having drivers written in C++ was another easing factor.
This also includes Apple's internal development teams--I don't think all the longtime Apple teams were that bullish on NeXT technologies. Remember that the original OS X Finder was a C++ Carbon app built with CodeWarrior.
- ObjC not considered inevitable: in 2000 it was not at all clear that ObjC would be thriving for another 15+ years. The C/C++ Carbon API was one direction for the future, the Cocoa-Java bridge was another, another was putting C++-style syntax on top of ObjC (which was never completed). C++ wasn't going anywhere, whereas it would be painful to have driver development handcuffed to ObjC if applications abandoned it.
- performance: it probably would have been a non-issue, but C++ is a safer choice performance-wise.
There might be other interesting tidbits on the darwin-development or darwin-drivers if you go back to 2000/2001.
The objects of ObjC work very differently than C++ objects.
In Obj-C for example, there are no "methods" like C++, in C++ when you put a method in a class, (although implementation details may vary) it works like a function pointer in a C struct, and calling that method is just executing whatever code that pointer points to.
In Obj-C in contrast, to call a function of a class, you actually pass a message, that first must be interpreted, then the runtime that interpreted the message find the correct function definition to use and run.
For most apps people don't care about this, but game developers for example frequently make iOS and Mac games that in time-critical parts use pure C or even Obj-C++ so that they can skip this messaging part (that can cause significant performance problems sometimes).
Example: yesterday I was trying to figure why a open source game I like was slowing down, I ran a profiler, and the most called function, and the one with most execution time, was a simple "GetSomeRandomVar()" for spaceships (it is a spacefight battle game), I looked in the source, and saw that every frame, every spaceship call this at least once for every other spaceship, if the spaceship has an AI it calls it many, many times, I inlined it and the code became much faster.
I am very sure that if it was a ObjC call (with messaging) it would be so slow that the original author probably would not even have uploaded that to github. (by the way, the game IS an OSX game, but the original author wisely decided to go with C++ instead of ObjC)
For anyone interested, here's a good analysis of Objective-C's message dispatch machinery: http://blog.zhengdong.me/2013/07/18/a-look-under-the-hood-of...
Mostly the difference is ints vs. strings in my opinion.
As well in C++ if you don't mark your method virtual you can bypass all the vtable crap.
I love ObjC but method resolution is far more expensive than in C++, especially non-virtual methods.
You do still need to do a hash lookup to get the method implementation, since the selector table changes at runtime and objects have to safely respond to unhandled selectors and all that.
They certainly don't have to be, however, they are.
SEL selector = @selector(applicationDidBecomeActive:);
// Prints applicationDidBecomeActive:
That's true only for virtual methods.
Also to add to what you said, no real way of doing stack allocated objects in ObjC is an issue as well.
So using obj-c in the kernel might require giving up some of the language's dynamism. Not sure how this was handled in NeXT.
When swift code that interacts with the base libraries is faster, and when swift code compiles faster.
Swift so far is a language that over promises and under delivers...
FWIW, I think Apple can't ship any base libraries that uses Swift until they finish ABI-compatibility, as they need to be working off the same base Swift runtime as the apps that would run against those libraries. Given that for the last year people have been shipping apps that link against an old-and-incompatible Swift runtime that Xcode bundles into your app, and given how the runtime is "intrusive" (putting stuff into the global Objective-C namespace, for example), it isn't even clear yet (so this may require more time on their end to build out more infrastructure) how they will be able to pull that off without saying "all Swift apps developed before now need to be reshipped or they will stop working on iOS 10".
You hit the nail on the head here. Until the ABI is finalized, Apple can't ship dynamic libraries to developers that are written in Swift. Swift won't be ready to fully replace Obj-C until this happens.
Exactly. I'm not being judgemental about that, but I don't see myself wanting to invest time into being a guinea pig. If Apple wants to build a tool that only works in and for their walled garden, I won't donate any work to it.
I don't see how any of these comparisons diminish the languages in question.