5 ms·
I wonder is this is due to lack of generics in objc.
by adamnemecek 9y ago
I wonder is this is due to lack of generics in objc.
- miguelrochefort 9y agoI know this affects Xamarin apps.
- chc 9y agoObjective-C has fully dynamic dispatch. In a context like that, generics are just a type safety thing to ensure that you aren't sending messages to the wrong type — they don't make the executable any smaller.
- adamnemecek 9y agoThey make code reuse possible. Watch this Sean Parent video https://www.youtube.com/watch?v=4moyKUHApq4 https://www.youtube.com/watch?v=4moyKUHApq4 where he estimates that if Photoshop was rewritten using generics, the code size would go from 3,000,000 LOC to 30,000 LOC. You are right, during compilation, generics are specialized so you end up with code, however going all in on generics removes a lot of accidental complexity.
- chc 9y agoI think you've misunderstood my point. What code reuse is possible with generics that is not not possible in Objective-C without generics? I don't think there is very much, because Objective-C fundamentally doesn't care the types of objects.
- adamnemecek 9y agoThe full answer would be kinda long but this is a rehash of the debate that has been had many times over. You cannot just compare obj-c vs generics, you need to also account for the fact that when you are obj-c development, you might need some fast code and as a result drop to c. And code reuse is hard to impossible in C. The fact that code reuse can be done without a performance hit is enough of a difference difference on it's own as it pushes down the level at which code reuse can be done. E.g. you can use generics for Graphics or Audio or general low level stuff.
- millstone 9y agoErr, why not just drop to C++? Objective-C++ is real and works great. That's how Mac Chrome does things for example.
- prewett 9y agoInteresting talk. If he's right, then a Photoshop clone ought to be doable. 30k LOC is doable for a single person or a small team. I'm guessing that even with generics, it wouldn't help that much. Also, I think there are probably a lot more algorithm LOC in Photoshop than he thinks...
- outworlder 9y agoThat has nothing to do with code size. You'll either get some sort of type erasure, which will create the types are compilation time anyway, or you'll have some sort of dynamic dispatch. Neither approach will make the generated code any smaller and may even make it bigger.
- swolchok 9y agoObjective-C has had generics for years. Here's mention of how they are imported into Swift: https://developer.apple.com/library/content/documentation/Swift/Conceptual/BuildingCocoaApps/InteractingWithObjective-CAPIs.html#//apple_ref/doc/uid/TP40014216-CH4-ID173 https://developer.apple.com/library/content/documentation/Sw...
- adamnemecek 9y agoI'm aware, they are nowhere near comparable.
- deleted 9y ago[deleted]
- millstone 9y agoOther way around. Generics make apps bigger, not smaller, because the code gets duplicated as it is specialized for different types.