r/C_Programming • • 10h 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?

80 Upvotes

58 comments sorted by

134

u/RainbowCrane 10h 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++

8

u/non-existing-person 3h ago

Apple is still atrociously miserable at attracting developers to their platform.

In the past I was doing some extreme portability for my program. I even got QNX and some obscure unixware from the 2000s to work in qemu. Mac tho? Mac said "fuck you". No hardware. No system.

3

u/OrwellWasGenius 2h ago

I am pretty sure this is Apple's deliberate strategy: make its technologies as painful as possible to use on other platforms, so that the only way out is to buy Apple's hardware. There is just no way this level of ignorance is accidental.

Microsoft: C# and the .NET platform for Windows, Linux, and macOS (and it works even better than Java on non-Microsoft platforms). C# for developing Android and iOS apps. TypeScript for everyone. VS Code for all platforms. Hell, they even offer PowerShell for Linux and macOS. Windows Subsystem for Linux.

Apple: You can't even compile for iOS if you don't have a Mac and Xcode.

2

u/Netris89 1h ago

I am pretty sure this is Apple's deliberate strategy

I'm mean, yeah. It's part of their "walled garden, we know better than you what you want" strategy.

2

u/stiggg 4h ago

Didn’t Apple first adopt objective c after they acquired Next in the late 90es?

3

u/qalmakka 4h ago

Yes but basically 100% of objective-c users before the acquisition were on NeXT. They were the one who wrote the GCC front-end for it, and basically nobody else was using it back then.

5

u/RainbowCrane 4h ago

Correct.

And by the late nineties Apple had lost the early wars for developers of end user software, both games and office apps. Moving to objective-c was a great architectural choice, as was the choice to move to the NeXT OPENSTEP model. But despite making some excellent business decisions about the release of i-everything, Apple has never really recovered from those early decisions to attempt to limit who had access to their developer tools.

Steve Ballmer’s infamous “Developers, Developers, Developers, Developers!” rant at one of Microsoft’s Developers Conferences was hilarious and unhinged to those of us who were around the dev community at the time - I wasn’t at that conference, I was at a MS Visual C++ conference a few months later. But that kind of hype and that feeling of excitement among the attendees was a common feature of every conference targeted towards Windows developers.

In the late nineties the development team that I worked on had an MSDN site license for about twenty seats for literally every piece of software licensed by Microsoft for about $20,000. That included MS SQL Server, Visual Studio and SourceSafe, MS Office, MS Project, etc. For comparison, that’s about $1,000/seat for everything. When we first licensed a Java IDE before Microsoft got into Java we spent about $100/seat. So $1,000/seat for everything in Microsoft’s portfolio is a pretty good deal.

When Microsoft came out with their Visual Studio addon for Java they handed out free copies at every developer’s conference.

And Microsoft’s certification program for MSVC++ and other core technologies was actually useful, and came with access to developer forums where the folks who worked on the APIs responded to questions.

Nearly every other tech company was behind Microsoft in supporting the developers using their products and it allowed Microsoft to gain a huge critical mass of loyal developers. One of Apple’s biggest success stories was wooing developers back with Steve Jobs’ charismatic keynotes at WWDC, and with better dev support.

74

u/simonask_ 10h 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.

2

u/tastygames_official 3h ago

I so wish this were true:

"Clean" Code, Horrible Performance
Object-Oriented Programming is Bad
Programming - The Single Source of Truth Principle
The purest coding style, where bugs are near impossible

now I know you said "largely" for free or however you put it, and if done sparingly and in a very C-like way then yes - you can get very similar (still not exact) performance. But unfortunately modern "wisdom" and the OOP abstraction addiction means in reality you're something like a few hundred times slower for typical applications. Now we've 1 milion xed our hardware performance over that time so it's still a win, but it's the reason why all software seems to take the same amount of time to run despite massive increases in hardware capabilities.

8

u/simonask_ 3h ago

My point is that C++ (contrary to Objective-C) lets you opt in or out of things like dynamic dispatch, but you can still have nice things like encapsulation, generics (templates), and so on.

By the way, it's a misunderstanding to say that performant C++ is "C-like". C++ code can very often outperform equivalent C code, because of things like static dispatch. The classic example is std::sort versus qsort(): The former can inline its comparison function, the latter takes a function pointer, a form of dynamic dispatch.

For the record, I think C++ is a terrible mess of a language, but it certainly isn't slow.

1

u/Illustrious_Trash117 2h ago

I also like the templating and compiler abstractions you can get with C++. You can get a whole of abstractions that after compiling boil down to a single function call. I use this in uC software where i wrote a template based abstraction of interfaces and sensors, so you can define multiple sensors and attach them to an interface. Then you just call read() on the sensor, this makes it clear what you want on what interface the sensor is and generally makes the code easy to read. Even with this level of abstraction it all boils down to inlining the register operations to controll the interface and read the data.

1

u/Wertbon1789 2h ago

Yeah, one thing that makes C++ unreasonable good performance-wise is it's ability to almost completely throw away the abstractions used in the code. You can make readable code, reason about performance, and still have resulting assembly that's coming quite close to what one would've done in C, without some of the hassle. Also, that most of the C++ standard library (mostly templates, I think) is inlinable, and not a hard function call gap, is amazing.

2

u/gremolata 2h ago

On the flip side, with these abstractions it's also very easy to end up with kilobytes of code fronted by an innocent looking statement.

Something like if (! map[x]) map[x] = y; looks sensible, but will run 2x slower than a bit more verbose version.

1

u/Wertbon1789 2h ago

Yes, I more meant that you can represent code with more abstractions and not lose out on performance, not that it's always true. And especially C++ is infamous for its foot-guns.

1

u/tastygames_official 1h ago

I personally never find abstraction more "readable". It just hides what's really going on and makes me have to dance around multiple files just to find out how it works. Now I know in really big teams this is actually a boon because you can just know that object.do_thing() will do the thing you request it to do and the documentation/function definition tells you what needs to go in and what comes out so you can work on more things faster, but when there's something that needs fixing inside of ObjectType::do_thing() then it's a royal pain in the ass to figure out what is actually going on and how to fix it. Especially when do_thing() calls multiple other functions and ObjectType implements multiple interfaces and inherits multiple classes and at the end you just have some function like:

PropertyValue BaseClass::get_property_value(PropertyType prop, ValueType val)
{
  return prop[val];
}

and yes - it's "elegant" that so many classes can utlize this very simple function to get at and validate all sorts of properties in a generic way, but debugging and performance-wise I just want to cry.

1

u/gremolata 2h ago

The classic example is std::sort versus qsort()

I'm pretty sure it's the only example :)

Well, maybe the inlining of virtual function calls when the pointer type is of a leaf class... but can't really think of anything else.

1

u/simonask_ 14m ago

Only because there are very few composable things in the C standard library, and qsort() is one of them.

Every time you have anything "generic" (i.e., some behavior is injectable, either in an algorithm, but also a data type like a collection), it makes a difference whether the compiler is able to statically specialize the instance of the generic function or data type, because it can produce optimally efficient code without indirect calls or undue heap allocations.

This is called "monomorphization". In languages without it (like C and Java, and every dynamically typed language), there is a pretty severe performance gap.

The only way to achieve this in C without losing your mind is by using macros to perform manual monomorphization, and you'll still lose your mind slightly. Or just go for the less efficient dynamic solution, which is good enough in many cases.

1

u/tastygames_official 2h ago

yes, I do know individual implementations of some algorithms under some compiler conditions C++ can outpace C (I think I've even seen Rust do the same), but "out in the wild" a complex GUI program written in C++ will generally have way worse performance than the same thing written in C - not because the language or compiler is bad, but because the "standard practices" for the languages are bad ;-)

1

u/simonask_ 10m ago

I don't think that's every remotely true in any sense.

2

u/RappyPhan 1h ago

C++ doesn't mandate that you write 'clean' code, nor does it force you to abuse OOP, or even use it at all. C++ is multi-paradigm.

Your argument essentially boils down to "you can make terrible coding choices in C++, therefore all C++ code results in horrible performance", when the truth is that you can write terrible code in any language.

1

u/montymole123 17m ago

Agreed highly abstracted, templated C++ programs written in modern C++26 style can run much slower than the same algorithm expressed in C. When you compile with optimisation the compiler can often kick out some of the junk and get back to C like performance but it's often necessary for the debug non optimised code to run fast too (eg games). Templated code also takes forever to compile which matters when you code base grows to millions of lines. A C++ code might take 1 hour to compile while the equivalent C would take 5 minutes this makes a big difference to productivity.

18

u/R-ten-K 5h 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.

42

u/an0th3rbrick 10h ago

probably because objective C is more dynamic which comes at a performance cost

45

u/MaxComfort 10h ago

This, and the weird brackety syntax.

Not to mention vendor lockin - is there any serious use of Obj-C outside NeXT/Apple platforms?

4

u/R-ten-K 5h ago

I never really thought C++ had particularly better syntax. If anything, Objective-C always felt (to me) it had a more coherent design when it came to expressing the original ideas behind object oriented programming, especially the message passing model. It felt like the language was designed around those concepts rather than having object orientation layered onto an existing programming model.

I also liked how explicit and expressive the messaging syntax was, even if it looked a little unusual at first.

But I agree that its initially proprietary ecosystem was a significant obstacle to wider adoption.

1

u/aieidotch 6h ago

objfw, gnustep

ApplicationKit and FoundationKit are both well designed, elegant frameworks

18

u/PseudoFrequency 10h ago

C++ is a standard with many vendors. Objective C was virtually only Apple.

5

u/EpochVanquisher 9h ago

At the time, Apple didn’t use Objective C

19

u/imMakingA-UnityGame 10h 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

6

u/stianhoiland 10h ago

back then felt like C syntax

Oh that's a good point.

17

u/zhivago 10h 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.

5

u/finleybakley 4h 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

4

u/Narishma 9h 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.

4

u/xeow 3h ago

Wait till you learn that Objective C++ is actually a thing! :-)

1

u/gremolata 1h ago

Daaaamn... so it's basically Objective C code mixed with C++ ?

God almighty.

2

u/Physical_Dare8553 10h 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

2

u/TheBestAtSpace 7h ago

Objective-C dynamic dispatch was much much slower.

6

u/ElectricSpock 10h ago

Because it was earlier, and there was no single company that pushed for it.

Next question.

4

u/demetrioussharpe 9h 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.

5

u/zlowturtle 8h ago

Objective C is slower than C++. There are plenty of industries where speed is critical. Your last sentence is incorrect.

6

u/demetrioussharpe 8h ago edited 1h ago

I’ve been around long enough to know that languages that are open to the widest range of users have the largest amount opportunities for advancement. Given the opportunity to be used by the masses, the speed issue could’ve been solved. My last sentence isn’t incorrect, you’re simply fixated on what Objective C ended up being -you never considered what it could’ve been.

1

u/RappyPhan 46m ago

> Otherwise, it would’ve most likely relegated C++ to the dustbins of history.

What do you base this on?

1

u/Engineer-4-fun 6h 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.

1

u/Sniffy4 6h 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.

1

u/podule-games 6h 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.

1

u/YouFeedTheFish 4h 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.

1

u/BlockOfDiamond 4h ago

Probably because Objective-C uses slow dynamic dispatch whereas C++ calls functions directly with implicit first arguments.

1

u/Responsible-Bar7165 2h ago

It might have something to do with the fact that reading objective-c code is like sticking pins in your eyes.

1

u/Available_Safe1818 1h ago

Yes, your prediction is naive. C++ was first. Also, Obj-C syntax still looks like diarrhea.

1

u/Leverkaas2516 1h 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++.

1

u/manicakes1 1h 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.

1

u/EpochVanquisher 9h ago

The major reason was tooling availability / licensing. It’s not really about the language.

1

u/LavenderDay3544 9h 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.

0

u/HowardZyn 6h ago

Obj-C syntax just looks hideous

0

u/AdreKiseque 7h ago

Diaresis spotting

0

u/authorinthesunset 6h ago

Objective-c sucks. Though I will admit that NEXTStep was pretty rad at the time.

0

u/Ok_Outlandishness906 10m ago

for me c++ and object C are both terrible languages .