by jmpt · 8y ago · 0 comments
Rant:
Objective-C is a wonderful language, once you learn it properly. There's a lot of Swift fanboiism (is that a word?) and a lot of Objective-C hate. I have an opinion on why.
The vast majority of people that used Objective-C were drawn to the success of iOS. They were developers, used to languages like Javascript, Java or C++. Coming to Objective-C, their immediate reaction was "WUTT??? Brackets!" Instead of properly learning the idioms, they fought the language on a daily basis and cursed Apple for forcing them to use a language unlike the one they were used to, in order to jump on the iOS bandwagon. These people, once Swift was released, jumped boat immediately because they never really understood Objective-C and Swift is familiar.
Another group of people: the seasoned Objective-C developers, with a clue, went: "hmmm... this doesn't solve any of my real problems," but they weren't stupid and Apple was quite clear that Swift was the future. They learned Swift, got used to the bad, learned how to like the good and went along their business.
Another group of people actively dislike Swift, and really enjoy Objective-C. These are considered dinosaurs and have to either hide their opinion or face hiring difficulties, or even dismissal from companies where they are currently employed. Hiring managers, usually incompetent and non-technical in nature, ask: "Do you use Swift? Do you like it?" If you want a job, you must say yes. Disagree with me? Try a no.
All new documentation is Swift oriented. All conferences and talks are in Swift. All new books are in Swift. You would have to be crazy to stick to Objective-C, but not for technical reasons.
The Objective-C vs Swift debate is similar to vi vs emacs, except that vi and emacs would be built by the same company and that company explicitly said "emacs is the future."
Nat, went like: screw this, and built https://www.mulle-kybernetik.com/weblog/2015/mulle_objc_a_ne...
Objective-C has warts. It is also fast. And stable. And quick to compile. Did I mention stable? It is also: stable. My code from 20 years ago still runs.
Objective-C is a marriage of my two favorite programming languages: C and Smalltalk.
Objective-C is message oriented, like Alan Kay envisioned, instead of object oriented. The focus should be messages and messaging to nil is a FEATURE. I actually quite like it.
In Objective-C you can drop to C at any given time and have access to all the insanely fast libs. You can also write such insanely fast code yourself.
Swift is immature, unstable, bloated, overengineering and extremely complex as a language. Complex as in C++ complex, but without the speed.
Ever heard of Objective-C++? Yup. Everything I said, except exchange C for C++.
Swift sacrifices LOTS of things and introduces new ideas that have yet to be proven efficient, and you get to rewrite your code all the time. Have something you wrote 2 years ago? Good luck with that.
All productivity "supposedly" gained by Swift is lost to slow compiles, rewriting older code and migrating to the new version when it comes out.
Swift is safe and everything. Right. Except developers with deadlines will just ! all the optionals when they get in the way.
Prototype a new idea? Prepare to fight the compiler the entire time.
Now, Swift does have some cool things, but so could a new version of Objective-C. In fact, ARC, which is pretty cool was born out of the development of Swift.
In my opinion, Swift is not a great language. I would even say that it's not good. It's OK. Maybe one day it will be good, but this day is not today.
All the love I hear is based on developers that resist learning something new (like Objective-C's way of doing things) and that's a good thing?
I love Cocoa. There's an impedance mismatch between Swift and Cocoa. Objective-C + Cocoa is wonderful.
Oh well. Objective-C is as good as dead and I'd rather write Go, Kotlin, C, Ruby, Erlang or even C++ than Swift.
I'd like to add a category:
People that are aware of Objective-C's limitations and want(ed) an actual improvement, not the 1 step forward (sort of), 3 steps back that we got. And they were pretty close, even got it in the marketing slogan: Objective-C without the C. Or at least without most of C much of the time. Or some. Instead they consistently doubled down on the things that were the least useful, for example structs. With classes and primitives, structs were always an extra, needed only for backwards compatibility and, historically, performance. What do they double down on? Structs. WTF?
The mix of Smalltalk keyword syntax and C syntax was always a bit of a problem. So let's keep both and make the integration between the two even more awkward!
And so on.
See also Rob Rix's rant:
https://www.quora.com/Which-features-overcomplicate-Swift-Wh...
Crucially, the vast majority of this is incidental complexity, not essential complexity. Swift is a crescendo of special cases stopping just short of the general; the result is complexity in the semantics, complexity in the behaviour (i.e. bugs), and complexity in use (i.e. workarounds).
Note that this is coming from the other side, so someone who doesn't like Objective-C much at all, and even from that perspective, Swift falls short.
I would count myself on your added category. Objective-C has been mostly unchanged for decades. I wanted an improvement, even if a breaking improvement.
We got properties and dot notation, which I was skeptical of. I saw a lot of misuse of those (specially with slower than O(1) accesses.) They were supported to signal intent, but instead were used as a shortcut.
We got ARC, which I must admit is useful for a large segment of developers, even though it creates a false sense of not needing to understand memory management and bites people left and right with circular dependencies. The good thing about ARC is that you can use it on a per-file basis and you can still do the performance sensitive parts with MRC.
The magic isa optimization was good.
But these were either small syntactic sugar/quality of life or internal performance optimizations. None provided significant leaps forward.
Apple could have picked Objective-Smalltalk :) And poached Lars Bak from Google.
Swift's slogan is great, but it's misleading. I read Rob Rix's rant shortly after he wrote it, and it was on the mark.
In John Oliver’s voice : “Fuck you Apple, fuck you.”
The tangible benefits of ARC are at best marginal, and there are downsides, which some can reasonably find more significant, and thus ARC not worthwhile.
First off, "manual" reference counting is misnamed. It is at the very least "semi-automatic" and highly automatable.
So how does a property declaration look with "MRC" vs. ARC?
@property (nonatomic,strong) NSString *str;
vs. @property (nonatomic,strong) NSString *str;
Can you tell which is which?So how about use?
someObject.str = @"Hello World!";
vs. someObject.str = @"Hello World!";
Can you tell which is which? In use, ARC and MRC are mostly indistinguishable, as long as you use accessors/properties for all instance variable access. You do that, right? Right?OK, so there is automatic dealloc. That's a nice convenience, but actually not intrinsically tied to ARC. How do I know? I implemented automatic dealloc for a project once. Didn't use it much after because the small effort spent on dealloc just didn't seem worth it, especially as you also had other boilerplate to implement, the coders, isEqual and hash.
The one biggie was weak, which was previously handled via non-retained references, so no automatic nilling. This could actually be a pain from time to time, but really not that huge a deal and it was also never really intrinsic to ARC, as shown by Apple recently adding weak for non-ARC code.
So those are/were the upsides. Not really that much.
Among the downsides is a performance penalty that could be both significant and somewhat unpredictable, on the order of 50%-100% slower in realistic scenarios (in extreme cases it can be an order of magnitude or more). You could also get unexpected crashes because of retain/releases added in unexpected places. We had a crash in a method that did nothing but return 0;
http://blog.metaobject.com/2014/06/compiler-writers-gone-wil...
However, for me the biggest pain point was the semantic changes in ARCed-C: what used to be warnings about an unknown message are now hard compile errors, and that seriously cramps Objective-C's style as a quick-turnaround exploratory language.
And yes, I have worked with/built both significant ARC and non-ARC codebases.
What's really troubling about these things (GC, ARC, Swift) is the rabid fanboyism. When GC came out, you were complete idiot and a luddite if you didn't embrace it and all its numerous warts (which were beautiful) wholeheartedly, and buy into all the BS.
Then when GC was dropped and replaced by ARC: same thing. Did anyone say GC? We meant beautiful shiny ARC, you ignorant luddite. And it quickly became an incontrovertible truth that ARC was faster than "MRC", despite the fact that this wasn't so. And when people asked about it, mentioning they had measured significant slowdowns, they were quickly attacked and everything questioned, because everybody "knew" the "truth". Until a nice gentleman from Apple chimed in an confirmed. Oops.
So please ratchet down the fanboy setting. Technologies have upsides and downsides. Reasonable people can differ on how they weigh the upsides and the downsides.
And of course we are seeing the same, just magnified by an extraordinary amount, with Swift.
I don’t know how to check this, but that isn’t how I remember it at all.
There was a brief flurry of interest when Apple added GC, but it never caught on. If it had been popular, Apple would have kept it.
Then when ARC arrived, it was genuinely popular, and that’s why it was a lasting success. By automating the exact same retain/release/autorelease protocol that people were already doing by hand, it fit much more neatly into existing Obj-C best practices.
I do partly agree with you, that Swift seems to have some problems that haven’t yet been fully resolved, but Apple are still going full steam ahead with it. It feels more like GC, but Apple are treating it like ARC.
Well, that's the beauty of upgrading to ARC: your declaration syntax doesn't need to change; usually it just means that you can drop a bunch of autoreleases in your codebase.
I read your blog post, where you mention this snippet of code being optimized in an odd way, printing "1 2" in Clang:
int main() {
int *p = (int*)malloc(sizeof(int));
int *q = (int*)realloc(p, sizeof(int));
*p = 1;
*q = 2;
if (p == q)
printf("%d %d\n", *p, *q);
}
Of course, when you have odd things like this happen you're reaching down into undefined behavior, and then all bets are off.Really, I you're just focusing on performance too much and neglecting the fact that ARC isn't there for increasing the performance of your code: it's there so that you can program in a manner that's more safe. Sure, it's easy to manage memory manually, until that one time you double free and SIGSEGV.
It really sums up the current debate as well.
I can't stand Swift. I think what I hate is the hate towards Objective-C.
I agree with you there
> In my opinion, Swift is not a great language. I would even say that it's not good. It's OK.
That's where I'll have to disagree. I really think Swift is a great language, though it's great in a different way than Objective-C is (though, who knows? Maybe one day it will gain enough reflection facilities to match Objective-C).
> The vast majority of people that used Objective-C were drawn to the success of iOS. They were developers, used to languages like Javascript, Java or C++. Coming to Objective-C, their immediate reaction was "WUTT??? Brackets!" Instead of properly learning the idioms, they fought the language on a daily basis and cursed Apple for forcing them to use a language unlike the one they were used to, in order to jump on the iOS bandwagon. These people, once Swift was released, jumped boat immediately because they never really understood Objective-C and Swift is familiar.
I used to be a Java programmer, and I started iOS development when Swift came out because it looked familiar. Sure, at first I really thought Objective-C was ugly and outdated, but once I really got its design I really came to enjoy it. I'm not saying that it's perfect, or that it does everything right, but there is a certain charm in its model.
> Another group of people actively dislike Swift, and really enjoy Objective-C. These are considered dinosaurs and have to either hide their opinion or face hiring difficulties, or even dismissal from companies where they are currently employed.
Sure, to each their own, but I really think that a lot of these developers just haven't spent enough time with Swift to really get its benefits. It's the same issue that you've mentioned with Swift developers, but in reverse.
> messaging to nil is a FEATURE
The Swift language designers hear you; that's why there's the optional chaining operator.
> In Objective-C you can drop to C at any given time and have access to all the insanely fast libs. You can also write such insanely fast code yourself.
You can do both in Swift.
> Complex as in C++ complex, but without the speed.
Swift is complex, and it's still a bit slower than C++ for certain things, but this doesn't mean this won't always be the case.
> Have something you wrote 2 years ago? Good luck with that.
Swift is still a new language, and it's in active development. However, you do have the guarantee that your code from today will continue to compile in the future.
> Swift is safe and everything. Right. Except developers with deadlines will just ! all the optionals when they get in the way.
I don't think you quite understand the safety that Swift offers. In Swift, an optional unwrap is designed to deterministically fail. The same is not true in the C family of languages, where it would be undefined behavior.
> Now, Swift does have some cool things, but so could a new version of Objective-C
There are some things that would be rather difficult to shoehorn into Objective-C at this point, even assuming that Apple is interested in adding these in. For example, Swift's generic functionality is far ahead of what Objective-C offers.
Instead of an ad hominem, you could actually, you know, argue against my points.
You didn't reply to the parent, who stated that Objective-C is puke inducing... I am the one who is a troll. OK :)
I remind you that the OP is about Objective-C being ported to Amiga. Somehow, it attracted people who LIKE Objective-C. The insanity of it all!
Enjoy your day!