August 22nd, 2024

Objective-C is just, like, a leaky abstraction over C

Objective-C is described as a "leaky abstraction" over C, integrating modern programming features and enabling interoperability. Its design is effective, with Objective-S proposed as a streamlined variant.

Read original articleLink Icon
Objective-C is just, like, a leaky abstraction over C

The blog post discusses the nature of Objective-C as a programming language, describing it as a "leaky abstraction" over C. The author reflects on a decade-old perspective by Robert Atkins, comparing Objective-C to Jimi Hendrix in terms of its revolutionary features that are now commonplace. The post emphasizes that while Objective-C introduced modern programming concepts like dynamic messaging and runtime introspection, these were not entirely new, having been present in languages like LISP and Smalltalk. However, Objective-C distinguished itself by integrating these features with a minimal extension to C, making it more practical and efficient. The author argues that Objective-C serves as a glue layer for various programming languages, allowing for interoperability. Despite its ad-hoc nature, the author believes that Objective-C's design is effective, and its utility has led to its dominance in the Apple developer ecosystem. The post also touches on the potential of Objective-S, a variant that removes the C component, focusing on a streamlined approach to programming. Overall, the author appreciates Objective-C's historical significance and its ongoing relevance in modern programming.

- Objective-C is viewed as a "leaky abstraction" over C, integrating modern programming features.

- The language is compared to Jimi Hendrix for its revolutionary impact on programming concepts.

- Objective-C's design allows for interoperability with other languages, enhancing its utility.

- The author highlights the effectiveness of Objective-C despite its ad-hoc nature.

- Objective-S is introduced as a streamlined variant of Objective-C, focusing on efficiency.

Link Icon 12 comments
By @rramadass - about 2 months
The inventor of Objective-C, Brad Cox wrote the classic Object-Oriented Programming: An Evolutionary Approach where he defines the concept of "Software-IC" for "Software Component" based systems/design/programming. The underlying C language provides the gate/block-level granular abstractions while the OO features grafted on top provides the chip-level reusability with loose coupling. This is a great mental model to have while programming large systems. The book itself is a classic on how to evolve a language.

Brad Cox's above book and Bertrand Meyer's Object-Oriented Software Construction (using the Eiffel language) were my guides to Object-Oriented Design/Programming and Software Engineering in general and i am eternally grateful to them.

By @t43562 - about 2 months
I still program in C at times and would love what Objective-C offers in it's place.

C++? Not so much because, in essence, that is also a leaky abstraction where you have to care about even more issues. Static versus dynamic methods to give an example: code looks the same but works subtly very differently depending on whether the methods used are static or dynamic. So you cannot ignore how the mechanics of the language works underneath and there is a continuous high mental load.

IMO Objective C is simpler - the OO side of it is all dynamic. For performance optimisations you can drop to C and you can really know where you are and what to expect.

To be fair I haven't used Objective-C enough so perhaps there are things about it which would turn me off it in the end. I liked Go for example but the way modules work eventually wore me down.

By @bluetomcat - about 2 months
It's crappy syntax over a couple of "objc_*" helper functions. One of these functions creates an object, another (objc_msgSend) sends a string called a "selector" and a number of arguments associated with it. The dynamic dispatch happens there – the selector string is mapped to a function address at runtime.
By @eadmund - about 2 months
> You don't program your computer with LISP or Smalltalk. Your computer runs a separate LISP or Smalltalk computer that you can then program on its own terms and in its own world.

That’s not really true of all Lisps! Common Lisp may be compiled straight down to assembly (that’s what SBCL does). It can call straight out to the host OS, just like a C program. Now, due to things like garbage collection you have to manage things a bit at the edges, but that’s no different from a language like Go, and I think that no-one would say that Go is its own machine.

It’s true of some Lisps, such as Emacs Lisp. Emacs is really a virtual Lisp machine with an editor as a shell.

I think that it’s also true of Smalltalk.

By @albeva - about 2 months
The real deal is Obj-C++ - now there is a powerful combo xD

For example, we used template wrappers around NSArray for static type checking and "smart pointers" to avoid manual release/retain calls all over the place, which was glorious.

By @sph - about 2 months
Where can I read more about Objective Assembler? Can you go lower level than obj_msgSend?

Also bonus points for mentioning the work of Piumarta, whose paper on extensible object models is my all-time favourite and has occupied my mind for years.

By @mentos - about 2 months
What’s the best example of using Objective-Cs message system at runtime that could not have been achieved at compile time?

ChatGPT is giving me contrived examples or examples that could have been achieved with the knowledge of classes at compile time.

By @apple4ever - about 2 months
Objective-C to me is just the pinnacle of language creation. I love plenty of other languages (hello Python) but I just love coding in it so much .
By @meindnoch - about 2 months
Which is precisely why it's so powerful.
By @bhaak - about 2 months
I remember a 2 hours debugging session when I started learning Objective-C.

I don't remember what I did wrong but I somehow tripped over Objective-C's boolean which isn't a proper type but just a macro of an int value like it is now in C. I did probably something stupid like "if (b != TRUE) {}".

What made this so much more infuriating was that if I knew it was just a leaky abstraction over C I wouldn't have made that mistake. But I thought it was on the same level as languages from the Pascal family or Java or any other modern programming language.

By @revskill - about 2 months
This article assumed you know objective-c.