Name: Anonymous 2009-11-22 11:45
So this faggot iPhone developer has been bitching to me about how C++ is a shitty language and how Objective-C is the greatest thing on the planet. How can I get back at him?
objectAtIndex, isEqualToString, etc. all over the place to deal with things that should be intrinsic. Why the hell does ObjC not allow any way to overload an operator? Smalltalk could do that (and quite cleanly I might add, in comparison with most other languages that allow it), so why can't its bastard child?id is supposed to be a pointer type, shouldn't it be id* instead? It's incongruous with the rest of language.
if (someshit = othershit) {
// do stuff
}[object methodForSelector:@selector(dostuff)]) -- or give up and just write a wrapper function. No wonder Apple added closures, it's the only half-sane way to do this (and it still sucks).
id would be just like void, and that would make even less sense.if (self = [super init]) {
// do stuff
}&foo::bar (which works much the same way as passing around any other pointer) -- and you're also conveniently ignoring the fact that it takes more than that line to properly call a member function. Of course in either language the only sane and portable way to call a member function if from a wrapper, but it's certainly convenient to be able to cast to a function type with void * as the first arg (i.e. this) on supporting systems.
- (void)initWithFrame:(CGRect)frame style:(SomeEnum)style;@implementation blah
+(int): (int) w: (int) x: (int) y: (int) z { return w + x + y + z; }
@end
int main() { return [blah: 1: 2: 3: 4]; }nil does nothing" thing really makes no sense.@interface of an ObjC class, you know. Anyway, if you define an empty @interface, the warnings will go away -- you can even define a macro to define the empty interface @interface and begin an @implementation at the same time, so that you don't have to write the class name twice.doStuff:with:and: is really pointless.id has properties that void * doesn't (and shouldn't) have. But you're right, they should have named it any, or Any, or whatever.id as an "enhanced" version of void *, and since void is actually a non-type, I thought replacing it with id would make it a non-type also, which would make no sense. I stand corrected. // call target selector with a, b, c
assert(target);
assert(sel);
NSMethodSignature* signature = [[target class] instanceMethodSignatureForSelector:sel];
assert([signature numberOfArguments] == 3);
NSInvocation* invocation = [NSInvocation invocationWithMethodSignature:signature];
[invocation setTarget:target];
[invocation setArgument:&a atIndex:2];
[invocation setArgument:&b atIndex:3];
[invocation setArgument:&c atIndex:4];
[invocation invoke];
}sel(target, a, b, c);#include <stdio.h>
class Durr {
public:
Durr() {}
void show(int a, int b) { printf("%p %d %d\n", this, a, b); }
};
extern "C" {
typedef int cb(void *, int, int);
void run_cb(cb *f, void *arg, int n1, int n2) { f(arg, n1, n2); }
}
int main(int argc, char **argv) {
Durr obj;
obj.show(456, 789);
run_cb((cb *) &Durr::show, (void *) &obj, 456, 789);
return 0;
}