r/C_Programming • u/ThePenguinMan111 • 7d ago
Discussion Why did C++ crush Objective-C in popularity?
I know C and C++ are largely source-compatible with each other, but Objective-C is specifically a strict superset of C, not just a fork of it, like C++. You’d think that scratching that OOP itch while also giving you complete source compatibility with C would cause more companies or projects to utilize it, at least in some respect, but that may just be a naïve prediction. What does C++ have that Objective-C doesn’t that you think caused such a large popularity gap between the two languages? Am I missing some nuance?
214
Upvotes
259
u/RainbowCrane 7d ago
One major reason for Objective-C’s lower adoption in the eighties and nineties was that it was strongly tied with NeXT and Apple, and Apple was fairly miserable at attracting developers to its platform.
I was a UNIX (Berkeley and AT&T) and Windows (NT, Windows for Workgroups, 95) developer in the eighties and nineties and the toolchains for UNIX and Windows were either free or were handed out like candy at developers conferences. Apple toolchains were comparatively expensive.
So there were a whole lot more academic and amateur developers creating software for C++
114
u/simonask_ 7d ago
C++ tries and largely succeeds to provide zero-cost abstractions, meaning you can use most high-level features without any additional overhead.
Objective-C has a very different goal in mind, and only give you high-level features at the cost of dynamism and heap allocation everywhere. This is a very reasonable tradeoff in the UI space, but not in many of the niches where C++ dominates.
50
u/an0th3rbrick 7d ago
probably because objective C is more dynamic which comes at a performance cost
33
u/R-ten-K 7d ago •
Besides the common points other posters have made already.
I think C++ ultimately won over Obj-C partly because of the New Jersey Unix School of Software Design: Worse is Better. Pragmatism, simplicity, and ease of adoption always beat overly complex elegance that requires jumping through hoops.
IMO, both languages sort of suck in different ways at translating the object oriented (OO) concepts of Smalltalk into a language built around C. Which may not be possible anyway.
Obj-C stayed closer to some of Smalltalk's original ideas, particularly dynamic message passing. It preserved more of the original OO model, but paid for that with a somewhat awkward syntax and the additional complexity of integrating that model into a language that retained C as a proper subset.
C++, on the other hand, is IMO a Frankenlanguage. It introduced OO features halfassedly, not fully embracing some of the underlying principles of the model, while also evolving into a language that wasn't a proper superset of C. In that sense, it ended picking up more the of the disadvantages than advantages of either (worst of both worlds?).
However, C++ was designed by a compiler expert, and that shows in its implementation philosophy; Static binding/compile time abstractions, aggressive optimization, and deterministic object lifetimes made it a better choice for performance and latency critical workloads (system stuff, and compute kernels/tight loops).
Its zero overhead abstraction philosophy was a particularly important differentiator. You could build relatively sophisticated abstractions without necessarily paying a runtime penalty for them.
Obj-C took a different approach. Its dynamic message passing model was to me more elegant and closer to Smalltalk's original philosophy. It also made experimentation, introspection, and iterative development considerably more natural. Which were also some of the goals of the original OO dev approach. But that flexibility came with runtime slowdowns vs C++.
So, IMO, both languages have fundamental limitations. IMO Obj-C was the more coherent expression of the original OO philosophy, while C++ offered more compelling performance.
TL;DR: both languages suck. It's just that C++ sucks faster.
21
u/PseudoFrequency 7d ago
C++ is a standard with many vendors. Objective C was virtually only Apple.
8
u/Narishma 7d ago
Probably because Objective-C started as a proprietary language and it took until the early- to mid-90s before there was an open implementation.
7
u/manicakes1 7d ago
Objective-C had poor performance characteristics out of the box. Dynamic message passing is great in many ways but also causes a table lookup and function call to every method invocation. When you use the collection types you have to convert basic C types into Objective-C objects (eg int has to be boxed up as NSNumber).
This made the language pretty bad for performance sensitive code because you wouldn’t want to use these abstractions in low level code or in hot loops. C++ with all its warts was usable in all levels of a big project.
Fun fact, all the core frameworks used by iOS and macOS developers are heavily written in C/C++. For the reasons I note above.
20
u/imMakingA-UnityGame 7d ago
Zero overhead performance in C++ and it actually more or less esp back then felt like C syntax, not being effectively locked into Apple ecosystem
11
u/finleybakley 7d ago
Have you written in obj-c? It's like dragging your skin against pavement. Truly a horrendous language to write in.
Not saying C++ doesn't have its learning curve and annoyances, but compared to obj-c it's a dream to write in
19
u/zhivago 7d ago
Smalltalk and C were never good bedfellows.
The result was an uneasy frankenmonster unsure of what it was.
C++ on the other hand was consumed by the holy purity of its purpose and entirely sure of itself, especially where it was wrong.
You'll notice that C++ has quietly become much less C++ like over time.
8
u/xeow 7d ago
Wait till you learn that Objective C++ is actually a thing! :-)
4
u/Responsible-Bar7165 7d ago
It might have something to do with the fact that reading objective-c code is like sticking pins in your eyes.
4
u/Leverkaas2516 7d ago
Lots of great answers here, but that phrase "giving you complete source compatibility with C " just seems like a strange statement. Have you never read Objective-C code? It's fundamentally not C and not compatible with C. Once your code is littered with square bracket message passing, you are never going back to C. It's a one-way trip regardless whether you choose to convert your code to C++ or Objective-C, so compatibility is not a factor.
If you mean that your code can call C libraries, well, you can do that just fine from C++.
4
u/nacaclanga 7d ago
Objective C and C++ follow a very different approach of adding Object oriented features to C.
To understand this one has to keep in mind, that object orientation was originally invented for dynamically typed interpreted languages. Binding a method to a message happens at runtime in these languages.
In Objective C the approach was to effectivly keep the dynamic, interpreted nature of this interaction and only compile the actual interpretation. This is then coupled with a runtime, which is basically an interpreter minus the functions that are easy to port to native code.
The usual runtime for Objective C is propietary and part of the NextStep / macOS ecosystem.
This approach is nice for GUI calls and the like but ultimativly rather slow.
In contrast C++ went further and modified the ideas of object orientations by imposing static typing and similar feature (like linking polymorphism to inheritance) to allow the OOT logic be fully lowered at compile time. Which is how C++ gets no performance penalty for it.
10
u/demetrioussharpe 7d ago
The truth? Because Objective C was bought by Next before it had a chance to gain market usage, & became the default language of NextStep. Since next owned the language & targeted solely at NextStep, there were no real opportunities to use it outside of NextStep. So, its growth was stifled. When Apple bought Next, it became Apple’s main language, but it was still only used for that ecosystem. It never got a chance to thrive outside of those 2 companies. Otherwise, it would’ve most likely relegated C++ to the dustbins of history.
3
u/Physical_Dare8553 7d ago
at the very least, c++ has a whole bunch of features, from the beginning, Bjarn's second goal for the alnguage was popularity so that he didtn have to maintan ts himself
3
u/TheBestAtSpace 7d ago
Objective-C dynamic dispatch was much much slower.
3
u/Engineer-4-fun 7d ago
With small changes to C, which do not reduce its utility or power or increase its complexity, but do enhance its clarity and safety, one can produce a language I think of as C-saner. C-saner is a proper subset of C++. Every C program is improved by conversion to C-saner and can then be compiled as if it was C++.
Objective-C was viewed as a niche language with proprietary aspects which, together with the appearance of C++, hindered its widespread adoption.
3
u/Sniffy4 7d ago
Obj-C was used for Apple platforms (because Apple bought NeXT in 1997) and nowhere else. That is the simplest explanation.
>You’d think that scratching that OOP itch while also giving you complete source compatibility with C would cause more companies or projects to utilize it,
C++ also has overwhelming compatibility with C. The difference is the style of OOP they implemented.
3
u/YouFeedTheFish 7d ago
Objective-C combines the worst of C and smalltalk. Everything you can do in objective c, like message passing, you can do in a c++ library, but in a typesafe way.
3
u/Available_Safe1818 7d ago
Yes, your prediction is naive. C++ was first. Also, Obj-C syntax still looks like diarrhea.
3
u/xpusostomos 6d ago
Objective C is a very very different beast than C++. It's slower, but very dynamic. Which makes it perfect for what Apple used it for: user interfaces. The syntax is half Smalltalk half C which made it an oddball stylistically. It didn't try to have all the bloat of C++ for better or worse. It was trying to be Smalltalk... Not strongly typed, but dynamic.
2
u/podule-games 7d ago
Obj-C was basically NeXTSTEP only until Apple bought NeXT, so even at its height, it was Mac/iOS only which isn't really a big market, especially considering it's not the *only* choice on Mac/iOS, you can easily write apps in something else, and most big players do.
The big players like Adobe might well make Mac apps, but they weren't using Obj-C, they'd be using C++. Same for most big Mac apps really. Obj-C was really mostly for "cottage industry" apps like I used to make, very few larger companies would bother with a Mac-only, or even an iOS-only language.
While I have a lot of affection for Obj-C, I won't pretend it's a good language, it's not. I have affection for a few languages like this, such as BASIC or RPG, languages that I find fun to use, but I don't attempt to make the argument they are good, well-designed languages that standard the test of time.
Basically Obj-C was Apple-only and really not that good.
2
u/BlockOfDiamond 7d ago
Probably because Objective-C uses slow dynamic dispatch whereas C++ calls functions directly with implicit first arguments.
2
u/Hopeful_Push_9712 7d ago
I'm convinced C++ took off because of STL
2
u/Living_Fig_6386 6d ago
Marketing. Objective-C was adopted by NeXT and seen as an important differentiator for their platform so they took moves to prevent adoption outside of NeXT and tied some core libraries into NeXTStep. C++, on the other hand was quickly adopted in UNIX environments. The GNU compiler collection had compliant implementations of C++ by 1987 and they didn’t get a full Objective C runtime until 1992. A lot of software was written in that intervening period. By 1992, Microsoft had decided that C++ would be the primary language for Windows native programming and they released MFC. Once the juggernaut that was Microsoft crowned it, it became king.
8
u/ElectricSpock 7d ago
Because it was earlier, and there was no single company that pushed for it.
Next question.
1
u/ReallyEvilRob 7d ago edited 7d ago
C++ was also considered a superset of C. Over time, the language standards have slightly diverged.
As far as why C++ is more popular, I think it's because C++ is just older and more mature. Objective-C dominated on Mac OS and iOS, but that dominance was eroded by Swift. On other platforms like Windows, C++ has dominated since before Objective-C had any relevance and just simply kept its place.
1
u/EatingSolidBricks 7d ago
ObjectiveC ew 🤢
1
u/Far-Championship-883 6d ago
Because university's and tooling companies pushed c++ because it was good for business. EG very profitable to make a bad programming language that then rely upon external software to build software.
1
u/gokhan_plt 6d ago
FunctionDeclerationWithLongLongDumbFunctionName
1
u/Guycrimson99 6d ago
Because learning it was a plus
1
u/vegaseat 6d ago
Apple did make an effort to replace clumsy Objective-C with Swift.
I enjoyed exploring Swift and some of its Python like features.
1
u/Leop0Id 6d ago
Even at this very moment Apple demands a $100 annual subscription just to put an app that only I will use onto my own phone.
1
u/Mementoes 6d ago
I think probably the main reason is the C++ STL. Objective-C's Foundation was only available on NeXT (which later became macOS and iOS). All expensive platforms with small marketshare.
1
u/roopjm81 6d ago
I mean have you tried Objective C? It's atrocious
1
u/happywoodcutter 5d ago
Have you tried [writing in objective C]?
1
u/a11yChief 4d ago
I can only speak for why I didn’t use it for long, the language was way less of an issue than the documentation. I was only a kid at the time, but I learnt several languages for windows, Visual Basic and VB.NET, a scripting language called AutoIt, php and eventually started looking at C for some short time before exams got in the way. Apple expected anyone getting onboard with Objective C to already know C front to back, which was way more common in 1990 than in 2007.
Then combine in the other stuff like the syntax looking like it was made for a bet, the main interface builder being separate to the code writer but still needing you to drag and drop to link code (I’m blind so that’s a nightmare), programmatic UI documentation was almost non-existent, you couldn’t use any other ui framework besides Apple’s, you couldn’t compile the code on anything other than Apple’s hardware, so in the end it just became easier to learn something else.
I stopped writing code for ages after I lost a hard drive, and the thing that got me back into it was the rust book, because it’s that well written. Documentation matters, and approachability matters. Apple’s languages have never had either at the same time.
1
u/Terminator_1_ 2d ago
I think because objective C is highly used for apple computers and early phones,while C++ was used in UNIX ,Linux and later windows. And people have been aleardy familiar with C because it was most used in UNIX and linux.
1
u/SauntTaunga 1d ago
Objective-C could be a bit clunky. It is C with a Smalltalk lookalike bolted on. It’s two languages stuck together.
The Smalltalk bits, conceptually sending messages to objects to get stuff done, was probably too strange for many.
1
u/me0262 22h ago
C++ was much more standards based and kept the same C syntax.
Objective C was more like the retarded cousin that no one really cared for, but with Apple using it for iPhone development, you had to use it most of the time (you could use C++ code in it, but you still had to have an Objective C framework to handle events and touches).
1
u/EpochVanquisher 7d ago
The major reason was tooling availability / licensing. It’s not really about the language.
1
u/HowardZyn 7d ago
Obj-C syntax just looks hideous
1
u/LavenderDay3544 7d ago
One is an ISO standard that is completely vendor neutral while the other is tied to locked down proprietary vendor hardware, OS, and compiler platform.
1
u/authorinthesunset 7d ago
Objective-c sucks. Though I will admit that NEXTStep was pretty rad at the time.
0
u/AdreKiseque 7d ago
Diaresis spotting
0
u/pedersenk 7d ago
As per the C++ FAQ:
So C++ scratched the OOP itch whist giving complete source compatibility with C. Hence Objective-C wasn't very competitive.
That said, I really can see Objective-C++ coming back for Apple's ecosystem. Internal code never moved on to Swift and the drivers are all still C++.
-2
u/Ok_Outlandishness906 7d ago
for me c++ and object C are both terrible languages .