8 ms·
There is no doubting the legacy of Objective-C (especially given the high likelihood you are reading this post on a mobile device, using app written in Objectiv
by gigantor 6y ago
There is no doubting the legacy of Objective-C (especially given the high likelihood you are reading this post on a mobile device, using app written in Objective-C), but to truly appreciate Brad's legacy, am curious about the appeal of using Objective-C.
Having developed only one small iOS app with Objective-C code, I was mostly turned off by its overall verbosity in the context of NS prefixes. Hence, I ask the question on behalf myself and others who did not appreciate the language and did not give it a proper chance... what did I miss and what are its top appeals?
Nevertheless, Rest In Peace to a pioneer.
- acjohnson55 6y agoIt's not a modern language, so appreciating it has to be in its original context. I think it does an admirable job of augmenting C with object-oriented capabilities. It's certainly easier to master than C++. I'm not an expert on this, but I suspect that the main reasons it was chosen for iOS were: - The technical limitations of the original iPhone meant that you needed to use a low-level language. - The legacy of NeXT at Apple.
- saagarjha 6y agoMostly the latter, I would assume. Apple didn't really use anything other than Objective-C for its application frameworks (and still generally does not, for the most part).
- pjmlp 6y agoI read in multiple sources, usually the kind of comments that is only possible to validate with inside info, that to this day not all business units are sold on Swift.
- saagarjha 6y agoSold or not, it's easy to see that most of the code being written is still in Objective-C just by looking at the code that Apple ships publicly.
- redwall_hp 6y agoIn the context of the time, C++ didn't exist yet. Objective-C was actually introduced just prior to C++, and both languages were effectively solving the same problem in different ways: C was the dominant language, and both language designers were trying to graft the OOP paradigm onto it. Objective-C is a thin-layer on top of C, adding Smalltalk-inspired object support. That's pretty much all there is to it. C, with some new syntax for objects. In the context of a world where C is the norm, that's pretty appealing. This is before Java existed, too. The "NSWhatever" stuff, as far as I'm aware, isn't part of the language. That's all in the frameworks Apple/NEXT developed for Objective-C. (Note that the base object is called Object, not NSObject, and the integer class is Integer.) NSString is probably named that way because Objective-C doesn't include a string class (nor does C, as a string is just an array of bytes until you write a wrapper to get fancy) and NEXT made one. They were just namespacing the NEXTStep classes.
- astrange 6y ago> Note that the base object is called Object, not NSObject, and the integer class is Integer. Objective-C actually doesn't require a base object (although these days it essentially does), but Object and NSObject are both examples of root objects. IIRC, reference counting is not in Object and was a NeXT invention.
- yawaramin 6y agoI'm curious--what happened to Objective-C in that fight with C++? Why didn't people go for its simplicity?
- jfb 6y agoPart of it was licensing. Probably more of it was the personalities involved at e.g. Microsoft or SGI.
- PaulDavisThe1st 6y agoObjective C loses to C++ for performance if you really start exploiting OOP a lot. The fact the you can swizzle methods in ObjC says a lot about the "weight" of the underlying implementation ("it's all messages") compared to C++.
- mojuba 6y agoObjective-C is verbose not just because of the NS suffixes. Everything is verbose (by today standards anyway). ObjC is a "child" of the 1980's when verbosity was considered a merit and a norm in programming. Two things that I used to like about it: - Combination of static typing and at the same time pretty high level dynamic typing: it was practically possible to call any method on any object, right or wrong, just like in dynamic languages. For performance critical parts you could always resort to C. Later, as a little bonus it was also possible to resort to... C++. There was such a beast as Objective-C++. - The method calling syntax. Quite unusual but neat. I liked it a lot. However, Swift ruined it for me. Now that I'm a total Swift convert and I feel a 2x or even 3x boost in productivity I can't even look at Objective-C code anymore.
- _qulr 6y ago> ObjC is a "child" of the 1980's when verbosity was considered a merit and a norm in programming. It's still considered a merit by some.
- Klonoar 6y agoI agree with this. Verbose code is code you can come back to an understand years down the road. The easiest projects for me to pick back up are the ones I wrote in Objective-C, hands down.
- PaulDavisThe1st 6y ago>Verbose code is code you can come back to an understand years down the road. For ObjC, "verbose code" means "code you can come back to years down the road and hope there's still a manual to translate those message argument names into whatever current programming terminology uses".
- saagarjha 6y agoThankfully, in computer science terms like "array" and "string" still mean what they did many years ago.
- saagarjha 6y agoObjective-C is a very simple, clean language–very much unlike its other "object-oriented-C competitor" C++. Unlike C++ it's a 100% superset of C, and it takes its cues from Smalltalk where objects send messages to each other rather than statically call each other's procedures. To support this, there is a very rich runtime that allows all sorts of reflection and metaprogamming atypical in a compiled language.
- PaulDavisThe1st 6y agoI don't see how you can call ObjC any more of a superset of C than C++. Object-related syntax in ObjC is completely alien to C. Object-related syntax in C++ (mostly) extends C structure syntax. Yes, ObjC takes its cues from Smalltalk. C++ does not. And so... ? [EDIT: ok, so people want to interpret "superset" as meaning "every valid C program is a valid Objective C program too. This is, with very few exceptions, true of C++ as well ]
- astrange 6y agoObjC doesn't change any existing C syntax, it only adds messages. C++ is an entirely different language with a different spec that merely looks like C.
- PaulDavisThe1st 6y ago"Yes! C++ is nearly exactly a superset of Standard C95 (C90 and the 1995 Amendment 1). With very few exceptions, every valid C95 program is also a valid C++ program with the same meaning." https://isocpp.org/wiki/faq/c https://isocpp.org/wiki/faq/c
- astrange 6y agoThe implicit casting rules are different, it doesn't allow VLAs, you can implicitly create static constructors instead of having your program rejected for non-constants at the top level, more keywords are unavailable as variable names…
- astrange 6y ago> Having developed only one small iOS app with Objective-C code, I was mostly turned off by its overall verbosity in the context of NS prefixes. This is actually a blessing because NS-/name prefixes are a simple approach to naming that keeps you humble. If you let programmers have namespacing they will invent enterprise software frameworks where every class is six layers deep in a namespace of random tech buzzwords they thought up. > Hence, I ask the question on behalf myself and others who did not appreciate the language and did not give it a proper chance... what did I miss and what are its top appeals? It implements message-based programming, which is "real" OOP and more powerful than something like C++, where OOP just means function calls where the first parameter goes to the left of the function name instead of the right. In particular it implements this pattern: https://wiki.c2.com/?AlternateHardAndSoftLayers https://wiki.c2.com/?AlternateHardAndSoftLayers which is great for UI programming and lets you define the UI in data rather than code. Although iOS programmers seem to like doing it in code anyway.
- jonhohle 6y agoThis plague of object wiring in code is pervasive in the Java world as well. The joy of declarative late binding and decoupled objects at compile time seems to be very lost on the vast majority of programmers.
- PaulDavisThe1st 6y ago> It implements message-based programming, which is "real" OOP No, it's message-based programming, which is a very powerful and useful tool. It's not the one true inheritor of the fundamental OOP concept. OOP wasn't defined by "you send messages to objects", it was defined by the idea that objects had their own semantics which in turn constrained/defined the things you could do with them. Some OOP languages implemented "doing something to an object" as "send it a message"; some didn't. ObjC is in the former group; C++ is in the latter.
- mpweiher 6y agoWell, considering that Alan Kay coined the term...
- 6y ago
- deleted 6y ago[deleted]
- apple4ever 6y agoThat verbosity is exactly why I love it. It's easy to write and easy to read (especially years later). It's just such a joy to work with.