5 ms·
Java Was Strongly Influenced by Objective-C
- tedunangst 17y agoExcept it seems to be missing all the features that make Objective-C "Objective-C" in my mind. How do you implement method missing/message forwarding in Java? Oh, that's right, your code doesn't even compile.
- naz 17y agoToo be fair, message forwarding is a pain in the ass in ObjC as well.
- tlrobinson 17y agoIt'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.
- bad_user 17y agoSure 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 :)
- ryanpetrich 17y agoMessage forwarding is not syntactic sugar!
- ekiru 17y agoIt is. In Objective C: [obj doFoo] would be analogous to this in a Java-like language: MethodSpec s = new MethodSpec("doFoo"); (obj.hasMethod(ms) ? obj.performMethod(ms) : obj.handleMissingMethod(ms) However, people associate "syntactic sugar" with a connotation of not being a significant difference. Many very useful tools in programming are merely syntactic sugar. For, while, and similar control flow structures are just syntactic sugar over either continuations or gotos. Message passing OO is syntactic sugar. As evidence, look at the object system the Gtk folks made for themselves in C, or the various object systems Perl programmers have made for themselves. The example of object systems in Perl illustrates another point about syntactic sugar: having a language which makes it possible for programmers to add their own syntactic sugar within the language is incredibly powerful. Moose is a great system, and Perl's flexible syntax is what makes it possible(although I don't really know Perl well enough to know how it's implemented, its syntax is very pleasant). CLOS is another example of the power of languages which allow programmers to add their own syntactic sugar. Syntactic sugar can be very good. Message forwarding not only is a very useful piece of syntactic sugar, but also allows the creation of certain types of very convenient syntactic sugar to a language.
- glhaynes 17y agoObjective C 2.0's garbage collector works just fine tyvm
- allenbrunson 17y ago... but not on the iphone, sadly.
- naz 17y agoYou 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 http://github.com/briancollins/SimpleData) and it is just so hackish.
- tlrobinson 17y agoOr just a method which takes a NSInvocation object...
- naz 17y agoInteresting revelation, thanks!
- deleted 17y ago[deleted]
- hrabago 17y agoGoes to show that just because you model something after another, it doesn't mean they'll look or feel similar. The underlying design of Java might have been influenced by Objective C, but the use of the two languages feel very different.
- inferno0069 17y agoPerhaps learning Objective-C would make me a better Java coder. Alternately, maybe all the ObjC practices that would translate have already been written up as standard Java patterns or included in the standard Java books and all I'd get from it would be frustration because I can't apply anything neat I see.
- warwick 17y agoLearning another programming language will almost always make you a better coder. It gives you perspective on the language you spend most of your time in, and lets you see patterns that are non-obvious is your 'main' language. To really benefit from learning another programming language, make sure that you actually learn the language, not just hack around in it for the weekend and say you know it.
- DougBTX 17y agoI'm playing with some Objective-C at the moment. For me the most interesting thing is how blurred the line between ObjC/OOP/message passing and straight C is. It's the first language I've used where you can treat the high level part as not much more than a library with custom syntax. I'm sure the lispers live in this world all the time ;)
- zaphar 17y agoYes we do.
- martingordon 17y agoOne of my favorite things Objective-C has over Java is no NullPointerExceptions (it's legal to send a message to nil). One of my least favorite things Objective-C has is EXC_BAD_ACCESS (usually caused by memory mismanagement).
- blasdel 17y agoDon't Classes in Java get boiled off in the compiler? There are no "class objects" at runtime that I've ever seen.
- lucifer 17y ago// unseen? if (foo.getClass() instanceof someClassObject) ...
- blasdel 17y agoIn 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.
- lucifer 17y ago> In this case isn't someClassObject just a literal that's resolved at compile-time and erased into a simple identifier symbol? No. Its a variable assigned in runtime. public void yesYouCan (Object foo, Class<?> someClassObject) { // compile time? if(foo.getClass() instanceof someClassObject) { ... } } Regardless, class and symbolic resolution occur at both compilation (to create the binary clsss files) and in runtime in the JVM (to load and execute the binary generated by the compiler): http://java.sun.com/docs/books/jls/second_edition/html/execution.doc.html#44487 http://java.sun.com/docs/books/jls/second_edition/html/execu... > 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. No, its quite possible/common to write methods that take class objects as parameters.
- vlisivka 17y agoif(foo instanceof SomeClassObject) ... or if(SomeClassObject.isInstance(foo)) ...
- pvg 17y ago
- alexk7 17y agoI just want to remember everyone that Objective-C is nothing more than Smalltalk with C backward compatibility. Also, the static type checking in early Java is pretty much the same thing as in early C++ (when both were without templates/generics).
- deleted 17y ago[deleted]
- oopd 17y agoThe use of the word "influenced" to describe the effect had on Java's design process by Smalltalk, Objective-C and other languages of good repute is really somewhat misleading. Certainly, there is some identifiable influence. For example, the concept of a JIT-ing virtual machine comes straight from Smalltalk (Deutsch & Schiffman, 1984), and it would also not surprise me if the APIs of Smalltalk and NeXTSTEP influenced the design of Java's somewhat. But that is largely where the influence ends: on the implementation of the language rather than on the language itself. Java the language belongs on the same branch of the OO family tree with C++, C# and other strong statically-typed OO languages--not on the branch with Smalltalk and company. Yes, Java's object model is class-based, single-inheritance and single-dispatch, but its model has little else in common with Smalltalk's. If it was designed with Smalltalk in mind, then it constitutes a dangerous misunderstanding of it. I do not mean the fact that "everything" in Java is not an object, but rather that some things that very clearly should be objects, such as classes, are not objects is alone enough to disqualify it as one of Smalltalk's legitimate offspring. The people who assert over and over again that Java was influenced by this language or that language do so because this language or that language has a better reputation among programmers than Java, and it is hoped that by doing so perhaps some of that reputation might rub-off on the hapless language.
- pvg 17y agoThe people who assert over and over again that Java was influenced by this language or that language do so because this language or that language has a better reputation among programmers than Java The post was written by one of the people who worked on Java, not somebody trying to impress you by associating Java with some language you like better. Are you trying to say Patrick Naughton is just making this up?
- oopd 17y agoAs pointed out in my post, the alleged influence simply isn't there, or isn't there enough to justify the claim. Someone who cites Smalltalk as their inspiration before going off and creating a statically-typed OO language with primitive types and classes that aren't real objects either didn't understand Smalltalk or deliberately chose to distort the concepts imbued in it enough that they no longer have a right to claim it as an antecedent. Gosling and others have been making claims of this sort for years, and yes, I do believe that they do so with the hope of improving their language's reputation, and further, to give their users the impression that they aren't missing out on anything by sticking with Java; that Gosing et al. studied the cream of the language crop when designing Java, took the good parts and left the cruft behind, so why bother trying anything else?
- pkaler 17y agoMost languages are influenced by languages they proceed. Simula, C++, C#, and Java are clearly method calling languages. Smalltalk and Objective-C are clearly message passing languages. That is the biggest distinction. You will always be able to find a particular feature in a particular language that is influenced by languages that have preceded it.
- qw 17y agoInterview from http://www.gotw.ca/publications/c_family_interview.htm http://www.gotw.ca/publications/c_family_interview.htm (I'm including Stoustrup, since C++ was probably one of the influences of the choice of syntax familiy) Q: What languages, or features of languages, inspired you? Stroustrup: In addition to Simula67, my favorite language at the time was Algol68. I think that "Algol68 with Classes" would have been a better language than "C with Classes." However, it would have been stillborn. Gosling: They're all over the map. Using Lisp, the thing that influenced me the most was the incredible difference garbage collection made. Using Simula and being a local maintainer of the Simula compiler was really what introduced me to objects and got me thinking about objects. Using languages like Pascal got me really thinking about modeling. Languages like Modula-3 really pushed things like exception mechanisms. I've used a lot of languages, and a lot of them have been influential. You can go through everything in Java and say, "this came from there, and this came from there."
- duncanj 17y agoI always felt that Java's design resembled Modula-3.