Forum: JRuby naming confusion

Posted by 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-
Posted by 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
Posted by 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
Posted by 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.
Posted by 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 (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.