Live data from Hacker News

Java Was Strongly Influenced by Objective-C

cs.gmu.edu

31–40 of 53 posts

Re: Java Was Strongly Influenced by Objective-C

#31
post #15
post #7

Don't Classes in Java get boiled off in the compiler? There are no "class objects" at runtime that I've ever seen.

There are. Think about classloaders and the whole dynamic code loading thing. Every single object has a class object associated with it.

But can you pass classes around as objects after they're loaded? Do they have a value beyond their identifier?

Re: Java Was Strongly Influenced by Objective-C

#32
post #4

Earlier quoted context omitted.

Too be fair, message forwarding is a pain in the ass in ObjC as well.

It's not really that hard, is it? You just have to implement methodSignatureForSelector and forwardInvocation. Compare to Java where it's not even possible to forward messages determined at runtime, you have to generate stubs before compiling. AFAIK.

You have to have a method to forward to that accepts the right number of arguments of the right type. It's a far cry from overriding methodNotFound. I tried to recreate the ActiveRecord find style in SimpleData (http://github.com/briancollins/SimpleData) and it is just so hackish.

Re: Java Was Strongly Influenced by Objective-C

#33
post #32

Earlier quoted context omitted.

It's not really that hard, is it? You just have to implement methodSignatureForSelector and forwardInvocation. Compare to Java where it's not even possible to forward messages determined at runtime, you have to generate stubs before compiling. AFAIK.

You have to have a method to forward to that accepts the right number of arguments of the right type. It's a far cry from overriding methodNotFound. I tried to recreate the ActiveRecord find style in SimpleData ( http://github.com/briancollins/SimpleData ) and it is just so hackish.

Or just a method which takes a NSInvocation object...

Re: Java Was Strongly Influenced by Objective-C

#34
post #27

Earlier quoted context omitted.

> some things that very clearly should be objects, such as classes, are not objects I don't get it. java.lang.Object.getClass() always returns an instance of java.lang.Class. What other behavior would you require before saying that Java classes are objects?

In Smalltalk, when you type the name of a class you are really referencing a global variable that refers to a class object. "Dictionary new" means send the message #new to Dictionary, and the Dictionary class object will respond by giving you a new instance of itself. "Dictionary compile: 'foo ^ 42' classified: #accessing" will add a method "foo" to Dictionary under the "accessing" category that will return 42 (an in…

Right yes of course that is vastly different. One way is to think of classes as immutable (which they are, in that sense). Of course adding a method to a class is possible - but being statically compiled makes that somewhat less useful ;)

Re: Java Was Strongly Influenced by Objective-C

#35
post #9
post #7

Don't Classes in Java get boiled off in the compiler? There are no "class objects" at runtime that I've ever seen.

// unseen? if (foo.getClass() instanceof someClassObject) ...

In this case isn't someClassObject just a literal that's resolved at compile-time and erased into a simple identifier symbol?

You can't pass someClassObject as an argument to anything but an operator like new or instanceof, and you can't assign to or from it, it doesn't itself belong to a class. It isn't an object.

Re: Java Was Strongly Influenced by Objective-C

#36
post #32

Earlier quoted context omitted.

You have to have a method to forward to that accepts the right number of arguments of the right type. It's a far cry from overriding methodNotFound. I tried to recreate the ActiveRecord find style in SimpleData ( http://github.com/briancollins/SimpleData ) and it is just so hackish.

Or just a method which takes a NSInvocation object...

Interesting revelation, thanks!

Re: Java Was Strongly Influenced by Objective-C

#37
post #28
post #26

Earlier quoted context omitted.

They cited Obj-C, not Smalltalk. Specific people and specific aspects of the design are mentioned, you haven't actually described how it isn't influenced by Obj-C. Which, incidentally, has primitive types, the plain C part can do static type-checking, etc. In any event the claim is the design is influenced by Obj-C not that it is actually just like Obj-C, a distinction you seem to have trouble making.

"They cited Obj-C, not Smalltalk." The author also cites Goslings "lots of experience" with Smalltalk. "In any event the claim is the design is influenced by Obj-C not that it is actually just like Obj-C, a distinction you seem to have trouble making." The influence is not sufficient to justify that claim any more than Java's garbage collection would justify its designers in describing Java as "Lispy" or "Lisp-like."

"We were after the C++ programmers. We managed to drag a lot of them about halfway to Lisp." - Guy Steele, co-author of the Java spec

Re: Java Was Strongly Influenced by Objective-C

#38
post #31
post #15

Earlier quoted context omitted.

There are. Think about classloaders and the whole dynamic code loading thing. Every single object has a class object associated with it.

But can you pass classes around as objects after they're loaded? Do they have a value beyond their identifier?

Yes, although Java's reflection is somewhat of a pain in the ass and limited in many ways. But you can take a Class object and call newInstance(), and it will invoke the class's no-arg constructor.

Re: Java Was Strongly Influenced by Objective-C

#39

Earlier quoted context omitted.

It's not really that hard, is it? You just have to implement methodSignatureForSelector and forwardInvocation. Compare to Java where it's not even possible to forward messages determined at runtime, you have to generate stubs before compiling. AFAIK.

Sure you can ... object.sendMessage(messageName) ;) Or for already built classes ... see java.lang.reflect.Method Personally if I were to choose, I'd trade some syntactic sugar for a decent garbage-collector. But that's just me :)

Objective C 2.0's garbage collector works just fine tyvm

Re: Java Was Strongly Influenced by Objective-C

#40
post #38
post #31

Earlier quoted context omitted.

But can you pass classes around as objects after they're loaded? Do they have a value beyond their identifier?

Yes, although Java's reflection is somewhat of a pain in the ass and limited in many ways. But you can take a Class object and call newInstance(), and it will invoke the class's no-arg constructor.

Moreover, reflection is less of a language feature and more of a very low-level library feature. In ObjC, one can write

    Class c = [SomeRandomClass class];
    id thingy = [[c alloc] init];
but Java won't let you do the equivalent:

    Class c = SomeRandomClass;
    Object x = new c;
Post reply on HN