News for hackers. Stuff that matters.
Re:Java Was Strongly Influenced by Objective-C by nikster on Wednesday December 26, 2012 @09:09PM (#4971990)
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!

Re:Java Was Strongly Influenced by Objective-C by cageface on Wednesday December 26, 2012 @09:55PM (#4972127)
A 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.
Re:Java Was Strongly Influenced by Objective-C by mpweiher on Thursday December 27, 2012 @04:56AM (#4972914)
Objective-C categories nowadays can include instance variables :-)
Re:Java Was Strongly Influenced by Objective-C by cageface on Thursday December 27, 2012 @01:12PM (#4974332)
Really? 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.
Re:Java Was Strongly Influenced by Objective-C by mpweiher on Friday December 28, 2012 @05:23AM (#4977203)
My 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+m...

Alas, those tricks break on bridged CF classes that have incorrect metadata:

http://markmail.org/message/yourm4nkghaf3bak#query:+page:1+m...

(Checked on 10.8, instance-size for CF objects still incorrect)

Re:Java Was Strongly Influenced by Objective-C by mikeash on Wednesday December 26, 2012 @09:10PM (#4971994)
Just 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.
Re:Java Was Strongly Influenced by Objective-C by MaxGabriel on Thursday December 27, 2012 @12:05AM (#4972406)
I 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.

Re:Java Was Strongly Influenced by Objective-C by hboon on Thursday December 27, 2012 @05:06AM (#4972927)
They 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.
Re:Java Was Strongly Influenced by Objective-C by mikeash on Thursday December 27, 2012 @07:49AM (#4973141)
The new method could be public.
Re:Java Was Strongly Influenced by Objective-C by pretoriusB on Thursday December 27, 2012 @01:54AM (#4972642)
>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.