Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

> Objective-C looks like a clusterfuck and I never want to touch it.

This is pretty much moot now, the Apple world is abandoning Obj-C, but AFAIK it's just old, not bad. Like, came out at the same time as C++ old, and has seen fewer changes to the language than C++ has. It's a compiled, C-like language, so yeah, hard to use and very easy to crash, just like C & C++.

Interested to hear your point of view on what makes it seem like a cluster, if you want to share. (And I'm only interested in hearing and understanding your opinion, not on debating or contradicting your experience.)

Obj-C had a pretty cool calling mechanism underneath, known as "message passing" -- more or less the analogy to C++'s virtual member functions. But it is the only compiled language I know where you can actually call functions by name, like construct a string dynamically and call, and you get those dynamic calls at the same speed as compiled code (minus a fast function lookup you can usually do once).

I used that mechanism in some games to build a nice state machine class for actor behavior. I did the same in C++, and the Objective-C code was way nicer & easier to use.



I remember trying to do the "construct a function name as a string and call it" thing in VB6 many years ago before I "knew better". Any idea what that functionality is called? I always wondered why languages wouldn't let you do that.


>I remember trying to do the "construct a function name as a string and call it" thing in VB6 many years ago before I "knew better". Any idea what that functionality is called?

It's called by various names - not sure if there is an official one - such as dispatch tables, jump tables, dynamic dispatch, etc. It's a pretty old technique, I would say it probably dates from the time of early high-level languages, and I seem to remember that it was used in assembly languages too (so probably even earlier), by using various addressing modes (indexed, indirect indexed, etc. (those terms are from long-forgotten 6502 instruction set BTW), storing the address of a function at a location and then jumping to that address (where the address is dynamically set at run time by some other bit of code based on some condition), etc.

Here is a simple example in Python:

Simulating the C switch statement in Python:

https://jugad2.blogspot.in/2016/12/simulating-c-switch-state...

Edit: Googled and got a couple of relevant links:

https://en.wikipedia.org/wiki/Dispatch_table

https://en.wikipedia.org/wiki/Branch_table


I don't think there's another widely used name for it except dynamic or virtual dispatching (with inline caching of the lookup table). C is too low level and simple a language to have it in the string lookup form and in C++/Rust name mangling, symbol stripping from binaries, and generics would make the feature very difficult to implement and rather unergonomic. C#/F# and CLR C++/VB probably already have this in the form of the reflection/.Net runtime APIs (including JIT for generics) but implementing it in C++ or Rust would be very complex and it would be yet another feature that bifurcates the language ecosystem (like heap allocation for embedded). Python and Javascript do have this feature but you still have to have access to the scope to do it (self['fn_name'] or this['fn_name']) and this implementation exists in one way or another in most dynamic languages.

You can do this as a hack in most compiled languages by exporting symbols from a shared library and just using the OS specific dynamic linker but this is ugly, slow, and pointless in a static language.


You usually get that through either reflection or an "eval" command.




Consider applying for YC's Summer 2026 batch! Applications are open till May 4

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: