3 ms·
The equivalent ObjC code is: ... MonoTouch appears to support Interface Builder as well. Also, your example isn't quite accurate. With the iPhone runtime, you
by antonovka 17y ago
The equivalent ObjC code is: ...
MonoTouch appears to support Interface Builder as well.
Also, your example isn't quite accurate. With the iPhone runtime, you only have to make the @property declaration in your interface and then @synthesize the variable in your implementation. However, the Mac runtime doesn't support this ...
The reduction of three duplicate entries to two is admirable, but still ridiculous. Moreover, "However, the Mac runtime doesn't support this ..." is the key point here. You can't use them on the simulator or the Mac 32-bit runtime (which are the same).
Additionally, prior to being corrected in 10.6, you couldn't access the synthesized ivars directly.
@synthesize is useful to have because, well, what if you want @dynamic?
Set an attribute on the @property declaration.
Or is there another example of its verbosity that you don't like? I don't find myself writing code that repeats itself very often. If I do, I'll refactor the code out to its own method. Just like I would with any other language.
I've never had trouble reading my Java, OCaml, or F# code years after I wrote it, but YMMV. In addition to the syntax, which stands on its own as a testament to monstrous verbosity, here are a few more off the top of my head:
1) Delegate/target pattern -- alerts, timers, etc. Your classes become a morass of delegate methods and hinky hijinks to pass what should be closure-captured state across disparate method calls. I don't want to make a mess of my classes by refactoring code to a distinct method if it doesn't belong in a distinct method.
2) Initializers. You wind up writing 3-6 different init methods, and then have to write 3-6 different class method short-cuts so you don't have to write '[[[Class alloc] initWithEverything: everything] autorelease]' everywhere.
3) Repeating myself. All the time. Why do I have to write header files? Java, C#, F#, OCaml, Python, Ruby -- none of them require me to duplicate my interface and implementation in two places. I understand that this is Objective-C, but in 2009, perhaps Apple should reconsider the C part?