Forum: JRuby naming confusion

Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2012-06-19 19:44
Hello all.
Noticed this today:


>> require 'java'
>> textArea =  javax.swing.JTextArea.new
>> textArea.preferred_size
=> nil
>> textArea.getPreferredSize
=> java.awt.Dimension[width=0,height=16]

Shouldn't these two methods be the same?
Thanks.
-roger-
13313ac2ec7ba7c43b1b952db034ff3b?d=identicon&s=25 Thomas E Enebo (Guest)
on 2012-06-19 19:54
(Received via mailing list)
Good question.  Component does in fact have a mangy old
preferredSize() method on it.  That short cut probably points at that
instead of getPreferredSize().

-Tom

On Tue, Jun 19, 2012 at 12:44 PM, Roger Pack <lists@ruby-forum.com>
wrote:
>
>  http://xircles.codehaus.org/manage_email
>
>



--
blog: http://blog.enebo.com   twitter: tom_enebo
mail: tom.enebo@gmail.com
Bec38d63650c8912b6ba9b557fb953b9?d=identicon&s=25 Roger Pack (rogerdpack)
on 2012-06-19 22:08
yikes.  That method should have been deprecated and removed years ago if
it doesn't even call out to getPreferredSize.
But that probably explains it. Thanks!
-r
Abdb670e1c130f96f947a94d03c02efa?d=identicon&s=25 Eric Christopherson (echristopherson)
on 2012-06-20 02:41
(Received via mailing list)
On Tue, Jun 19, 2012 at 12:48 PM, Thomas E Enebo <tom.enebo@gmail.com>
wrote:
> Good question.  Component does in fact have a mangy old
> preferredSize() method on it.  That short cut probably points at that
> instead of getPreferredSize().
>
> -Tom

Can we anticipate a change to the effect of JRuby always trying the
get* version first? I would imagine that sort of error would take a
long time to track down; and maybe it's just me, but when that sort of
thing bites me a few times, I start being extra defensive, e.g. adding
get_ in the 99% of cases where it's not necessary.
F1d37642fdaa1662ff46e4c65731e9ab?d=identicon&s=25 Charles Nutter (headius)
on 2012-06-20 16:33
(Received via mailing list)
On Tue, Jun 19, 2012 at 7:40 PM, Eric Christopherson
<echristopherson@gmail.com> wrote:
> Can we anticipate a change to the effect of JRuby always trying the
> get* version first? I would imagine that sort of error would take a
> long time to track down; and maybe it's just me, but when that sort of
> thing bites me a few times, I start being extra defensive, e.g. adding
> get_ in the 99% of cases where it's not necessary.

The problem with that is all the other cases where you *do* want the
non-get method to be bound to the shortcut name. It's not a good
practice in API design to mix both bean-style and "bare" getters like
this, but it does happen.

Our policy has always been this:

* Bind all standard Java names
* Bind underscore names for all methods
* Bind more complex renames like get/set

At each stage, we only bind the name if it has not already been bound,
so preferredSize wins preferred_size because it's the earliest,
simplest alias.

Probably just have to chalk this up to a bad API in Java. Our aliasing
is done mostly as a convenience and it usually works fine. Using get_
defensively isn't a *bad* idea, but it's only necessary in cases like
this.

- Charlie
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.