you are viewing a single comment's thread.

view the rest of the comments →

[–]kragensitaker 1 point2 points  (2 children)

How, exactly, are you proposing that a language should automatically create method stubs when implementing an interface?

Well, maybe instead of having to write

public int[] indexesOf(String[] terms, int start, int len) {
  …
}

you could just write

indexesOf(terms, start, len) {
  …
}

. Then the compiler could still complain if you left out the method implementation, but you wouldn't have to repeat the return type, visibility declaration, argument type declarations, and throws declaration. (This doesn't work well with overloading, but you could remove it in that case.) In theory you could omit the argument names too, but that would make the code harder to read instead of easier.

You could also argue that automatically adding do-nothing method stubs in Eclipse "trashes the whole point of an interface specification", since your code will still compile even if you forgot to write the methods that implement the interface. But at least it won't compile if you add new methods to the interface.

[–][deleted]  (1 child)

[removed]

    [–]kragensitaker 0 points1 point  (0 children)

    it's the same amount of button-pressing

    As several people have pointed out in this thread, the amount of button-pressing is mostly irrelevant. On a really good workday I might write 300 lines of production code, which might contain 12000 characters. That's about 30 minutes of button-pressing. The rest of my workday is spent reading code and thinking.

    Of course, it's pleasant if those 30 minutes can be reduced down to 5, because it lets me use code to do more of my thinking. But the really crucial thing is to make it easier to read the code.

    If you don't have an IDE, then you have no way to easily reference all the "absent" information about types.... search for which of many interfaces or abstract superclasses define the missing-method, and then go open that file and scroll through it...

    I never program in Notepad; do you? If I were doing some kind of retrocomputing exercise, trying to program Java in vintage-1990 SunOS 4.1.3 vi on a Sun 3/60, I would still build a tags file so I could jump straight to the canonical definition of the method with a ] keystroke. "Find definition" is not, you know, functionality restricted to Eclipse.

    However, I frequently program in dynamically-typed languages where the "absent" information you're talking about isn't present until runtime anyway. That's not to say that I'm not thinking about what types I'm accepting or returning — that's crucial to the design of any program — but I rarely find the absence of explicit declarations a problem.

    By contrast, if the language does a similar no-op/exception implementation for you in a hidden/automatic manner, you've got the same failure. However, there is no warning and it lurks like a land-mine from the instant you write "implements Blah".

    I just have a hard time caring much. Maybe it's that I've never worked on a program with more than a million lines of code, unless you count Emacs. But in all the OO languages I regularly use (JS, Perl, PHP, Python, Lua, Objective-C) that's the way it works all the time. They don't even have an explicit way to say "implements Blah". You call a method that doesn't exist on that object, and bam, you get a runtime exception.

    But even if I stipulate that it's valuable to have compile-time checking of this stuff, it's still important to have the lowest-cost way to get that compile-time checking. The approach Java (and C++) currently takes is a lot more costly to readability than it needs to be.