5 ms·
That might explain its complicated syntax. Better than obj-c but worse than nice languages like Ruby or Python. Also, if they were influenced by Obj-C then why
by nikster 14y ago
That might explain its complicated syntax. Better than obj-c but worse than nice languages like Ruby or Python.
Also, if they were influenced by Obj-C then why on earth didn't they bring over the by far most useful feature of the language, caegories?! Or maybe categories were a later addition?
I have been developing Java for 15 years and ObjC only for two but categories are seriously the best thing since sliced bread. Anything missing in the libraries? Just add it!
- mikeash 14y agoJust make sure you prefix your category methods. Somebody at Apple might have the same idea you have, and if the two implementations aren't perfectly compatible, you're in a world of hurt.
- MaxGabriel 14y agoI wouldn't know how much the convention is enforced, but doesn't Apple prefix private API with an underscore? Edit: this is from the Apple naming guidelines, but it doesn't clarify that they always follow that convention for private methods: Avoid the use of the underscore character as a prefix meaning private in method names (using an underscore character as a prefix for an instance variable name is allowed). Apple reserves the use of this convention. Use by third parties could result in name-space collisions; they might unwittingly override an existing private method with one of their own, with disastrous consequences. See “Private Methods” for suggestions on conventions to follow for private API.
- hboon 14y agoThey most definitely have private functions that do not have prefix. The iOS Three20 framework used to have a bug where you tap on a tab bar button a second time and it crashed because a cateogry method had the same name as an existing private method.
- mikeash 14y agoThe new method could be public.
- cageface 14y agoA lot of the newer JVM languages provide better equivalents to Obj-C categories. Most of them also let you mix in instance variables along with methods. Check out Scala or Kotlin for specific examples.
- mpweiher 14y agoObjective-C categories nowadays can include instance variables :-)
- cageface 14y agoReally? Since when? Do you have a link to docs? I've seen some hacks involving associated references but it was my understanding that categories were not allowed to add instance variables because Apple would have to make member access much slower to allow that kind of extension.
- mpweiher 14y agoMy bad: they are allowed in class extensions, which are similar to but not the same as categories. Given how the new non-fragile ivars are implemented, it should be possible to add ivars anytime before the first instance is created (so load time should be OK), but that has apparently not been implemented, class extensions only work for code compiled together. So I guess no dice, apart from associated objects or the old indexed-instance-variable tricks: http://markmail.org/message/b5aqssv3iowcsw2i#query:+page:1+mid:b5aqssv3iowcsw2i+state:results http://markmail.org/message/b5aqssv3iowcsw2i#query:+page:1+m... Alas, those tricks break on bridged CF classes that have incorrect metadata: http://markmail.org/message/yourm4nkghaf3bak#query:+page:1+mid:pb57oyiiyp3vfomn+state:results http://markmail.org/message/yourm4nkghaf3bak#query:+page:1+m... (Checked on 10.8, instance-size for CF objects still incorrect)
- pretoriusB 14y ago>That might explain its complicated syntax. Not at all. The syntax was modelled after C++ which was what SUN wanted Java to replace at the time (generally it is a C-family style syntax). Smalltalk itself has better syntax than any of the bunch. >Better than obj-c but worse than nice languages like Ruby or Python. Ruby and Python are not statically typed languages, which covers a lot of the simplicity in their syntaxes. And while they did exist at the time, they were far from anybody's attention at the time Java emerged. It took 3-5 years after that for Python to make a strong appearance in some circles, and another 3-5 years for Ruby to emerge.