12 ms·
This is interesting - a 'clever' trick to give the functionality of generics. Although one could argue that its also fantastically stupid by using a macro in s
by jheriko 13y ago
This is interesting - a 'clever' trick to give the functionality of generics.
Although one could argue that its also fantastically stupid by using a macro in such a way that isn't obvious on inspection and might necessitate reading the header.
I do quite like it however...
I'd imagine that Objective-C prevents any of the performance benefits gained by the compiler knowing the types with its heavyweight super dynamic late binding golden sledgehammer of an architecture. I'd be curious to measure it when I get some time...
- chrisdevereux 13y agoIt won't. If the compiler attempted to inline, it'd break runtime method replacement and all sorts of other stuff. One problem with this approach is that using protocols to emulate C++/Java generic syntax will cause name collisions if a class already has the same name as a protocol. NSArray<NSObject> won't work for example, because NSObject is already a protocol.
- jheriko 13y ago> it'd break runtime method replacement and all sorts of other stuff. yeah, i thought as much. thanks for saving me the effort. :)
- fleitz 13y agoThat's actually what I really like about ObjC, either it's ok to be kinda slow, or you're writing it in C/C++. ObjC is like a super fast ruby with a C/C++ compiler embedded. Most of the core types are toll-free bridged so you can drop the ObjC overhead pretty quick.