News for hackers. Stuff that matters.
Re:Java 9 with GPU processing, Java 10 will be all-OOP witho... by c4n4rd on Friday March 30, 2012 @08:14AM (#3775547)
This is a very good point. If functions become objects, interfaces would become literally useless. Somehow it seems that it would not be the case since this would be a drastic change (even thought getting rid of primitives are as well.)
Re:Java 9 with GPU processing, Java 10 will be all-OOP witho... by CodeMage on Friday March 30, 2012 @08:19AM (#3775563)
Literally useless? Would you like to elaborate on how specifying a contract that has to be implemented is suddenly useless because you have function types?
Re:Java 9 with GPU processing, Java 10 will be all-OOP witho... by yummyfajitas on Friday March 30, 2012 @08:23AM (#3775583)
I think the experience of Haskell is relevant here. Once Haskell introduced first class functions, everyone stopped using typeclasses.

[edit: apparently my sarcasm was too subtle. HOF and typeclasses are both vitally important pieces of Haskell, which are orthogonal to each other. I'm pretty sure both were in Haskell from day 1. Some code for which both are essential:

    class Monad m where
      (>>=) :: m a -> (a -> m b) -> m b
      (>>) :: m a -> m b -> m b
      return :: a -> m a
      fail :: String -> m a

]
Re:Java 9 with GPU processing, Java 10 will be all-OOP witho... by CodeMage on Friday March 30, 2012 @08:35AM (#3775621)
I'm genuinely curious: is this because Haskell is generally hard to learn[] or because of some inherent property of Haskell that makes type classes unnecessary when you have first class functions?

[] This statement is based purely on my own experience. I find the Haskell documentation a bit unfriendly with its "academic" style. The content is great, but the form makes it a bit hard to assimilate. Monads were especially painful.

Re:Java 9 with GPU processing, Java 10 will be all-OOP witho... by calpaterson on Friday March 30, 2012 @10:03AM (#3775948)
I don't think typeclasses were in from day one, they were added quite late in the development of the language (but some years before H98). I don't think they're in Miranda, for example.

Here's a paper introducing them.

http://dl.acm.org/citation.cfm?id=227700

Re:Java 9 with GPU processing, Java 10 will be all-OOP witho... by SamReidHughes on Saturday March 31, 2012 @11:55PM (#3782596)
Re:Java 9 with GPU processing, Java 10 will be all-OOP witho... by yummyfajitas on Friday March 30, 2012 @10:37AM (#3776104)
I stand corrected. I guess Haskell before H98 was a very different language than it is today.
Re:Java 9 with GPU processing, Java 10 will be all-OOP witho... by xyzzyz on Friday March 30, 2012 @08:45AM (#3775657)
Once Haskell introduced first class functions, everyone stopped using typeclasses.

What do you mean? From what I've seen, everyone uses typeclasses in Haskell.

Re:Java 9 with GPU processing, Java 10 will be all-OOP witho... by hythloday on Friday March 30, 2012 @09:06AM (#3775721)
Not sure I agree with the GP's point, but I believe he's arguing that when fulfilling the contract of a fictional MouseClickListener:

  interface MouseClickListener {
    void mouseClicked(MouseEvent e);
  }
one often uses an anonymous class to do so:

  void init() {
    mouse.setClickListener(new MouseClickListener() {
      void mouseClicked(MouseEvent e) {
        println(e);
      }
    });
  }
the exact effect could be achieved with a reference to a named function (if Java supported them, which presumably it will once "everything is an object"):

  void init() {
    void mouseClick(MouseEvent e) { println(e); }
    mouse.setClickListener(mouseClick);
  }
given that interfaces are simply syntax for function routing, when you have the ability to reference functions by first-class types (i.e. you have the ability to determine function routing yourself), the set of things that you can only sensibly do with interfaces is a lot smaller.

This is how C# delegates work, right? Any Java -> C# programmer want to comment on whether they rely less on interfaces now and what they use them for?

Re:Java 9 with GPU processing, Java 10 will be all-OOP witho... by bermanoid on Friday March 30, 2012 @10:18AM (#3776027)
First class functions pretty much have no bearing on whether or not interfaces are useful. Sure, one use case for inner classes is to implement interfaces in-place in situations where what you really want to do is just pass a function, and in those cases it's probably better to use a function instead, but the equivalence doesn't go the other way.

There are plenty of cases where you really need to pass an object to a function and know that the object supports multiple operations, for instance take a look at Map<K,V>: http://docs.oracle.com/javase/6/docs/api/java/util/Map.html

There are 14 methods there, and when I write code that takes a Map object, I really mean it - I'm not just using the interface as a hack because I want a function pointer, I need an object that supports all of those methods, and I'm probably going to be using several of them.

Re:Java 9 with GPU processing, Java 10 will be all-OOP witho... by eropple on Friday March 30, 2012 @09:20AM (#3775777)
I bounce between Java and C#. I'm not sure at all what he's talking about. I use interfaces all the time in C#. I even specify delegate properties (as distinct from events, when I don't want them to be multicast) in interfaces.

I think both concepts are probably independent of one another.

Re:Java 9 with GPU processing, Java 10 will be all-OOP witho... by cynicalkane on Friday March 30, 2012 @08:21AM (#3775574)
Clojure has both function objects and interfaces (called 'protocols'). In fact, it encourages the use of interfaces while strongly discouraging the traditional object inheritance model. Most people who've tried it AFIAK consider Clojure a well-designed language.
Re:Java 9 with GPU processing, Java 10 will be all-OOP witho... by jemeshsu on Friday March 30, 2012 @09:05AM (#3775714)
Clojure, Golang, Scala and Rust all implement similar interface.
Re:Java 9 with GPU processing, Java 10 will be all-OOP witho... by Roboprog on Friday March 30, 2012 @12:13PM (#3776678)
While I agree that I hate interfaces with one method, what about interfaces that actually define several methods (e.g. - perhaps a driver for something that needs to do operations like "open", "close", "get", "put")?

Interfaces still serve a purpose bundling together related operations with replaceable implementations. They're just a nuisance for single-purpose functions/functors (e.g. - "run").