Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [eclipse-dev] NLS.bind(...) vs MessageFormat.format(...)

As Jeff mentioned: the main reason for the NLS class is performance when
loading the externalized messages and saving space.

Now, whenever we need to fill in an argument into such a message it is
normally either a number or a string. When it is a number (or date) it is
obvious not to use NLS bind (see Markus's words on that) and to simplify
the code pattern and to prevent problems when using NLS.bind when
inappropriate we (JDT and Text) always use MessageFormat.

Regarding performance it depends whether you are using the "normal"
MessageFormat class or the one from ICU which can handle more locales. The
normal class is 1-2 times slower than NLS.bind when it comes to strings.
The ICU class is about 2-3 times slower than NLS.bind (again for strings)
and in absolute values about 2.5s slower for 1 million strings, which is
negligible since we use MessageFormat to compute UI messages.

Dani


                                                                           
             Tod Creasey                                                   
             <Tod_Creasey@ca.i                                             
             bm.com>                                                    To 
             Sent by:                  "General development mailing list   
             eclipse-dev-bounc         of the Eclipse project."            
             es@xxxxxxxxxxx            <eclipse-dev@xxxxxxxxxxx>           
                                                                        cc 
                                                                           
             08.04.2008 15:00                                      Subject 
                                       RE: [eclipse-dev] NLS.bind(...) vs  
                                       MessageFormat.format(...)           
             Please respond to                                             
                 "General                                                  
                development                                                
              mailing list of                                              
                the Eclipse                                                
                 project."                                                 
             <eclipse-dev@ecli                                             
                 pse.org>                                                  
                                                                           
                                                                           





The Platform Text team can speak to the JFace usage as it is in the Text
portion of JFace. The Platform UI team were one of the early adopters of
the NLS class for the performance reasons that Jeff outlines below. The
places we use it now are those more complex cases where the NLS class does
not cover what we need to do which as expected is a small percentage of our
externalizations.

Tod



                                                                           
 "Jeff McAffer" <jeff@xxxxxxxxx>                                           
 Sent by:                                                                  
 eclipse-dev-bounces@xxxxxxxxxxx                                        To 
                                              "'General development        
                                              mailing list of the Eclipse  
 04/08/2008 08:51 AM                          project.'"                   
                                              <eclipse-dev@xxxxxxxxxxx>    
                                                                        cc 
          Please respond to                                                
  "General development mailing list                                Subject 
       of the Eclipse project."               RE: [eclipse-dev] NLS.bind   
      <eclipse-dev@xxxxxxxxxxx>               (...) vs                     
                                              MessageFormat.format(...)    
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           





The idea of the whole NLS infrastructure is to be fast and small.  If I
recall the number correctly it is something like half the size as using
resource bundles and twice as fast.  That is for the message management.
Similarly, the bind() infrastructure was a recognition that most cases are
very simple and so need only very simple support (read small and fast).  So
the guideline would be: use NLS unless you need to do something harder.
And AFAIK you should always use the NLS style message catalog classes.

I’d be interested to know if the JFace use of MessageFormat was required or
just crept in.

Jeff

From: eclipse-dev-bounces@xxxxxxxxxxx
[mailto:eclipse-dev-bounces@xxxxxxxxxxx] On Behalf Of John Arthorne
Sent: Monday, April 07, 2008 3:53 PM
To: General development mailing list of the Eclipse project.
Subject: Re: [eclipse-dev] NLS.bind(...) vs MessageFormat.format(...)


NLS#bind just substitutes values for {0}, {1}, etc, in a message string.
That's all it does. If you read the class comment for MessageFormat, you
will see the "pattern" argument can actually specify a number of things,
such as locale-specific representation of currencies, dates, etc.  If you
just want to substitute values into a string, I suggest using NLS (simpler,
faster). If you want to do anything else such as locale-specific
representation of numbers, use MessageFormat. I've never come across a need
for MessageFormat myself, but I believe there is some usage in JFace that
you could look at.

John




                                                                           
 Olivier Thomann/Ottawa/IBM@IBMCA                                          
 Sent by: eclipse-dev-bounces@xxxxxxxxxxx                                  
                                                                           
                                                                        To 
 04/07/2008 01:56 PM                                   eclipse-dev@eclipse 
                                                       .org                
                                                                        cc 
                                                                           
                                                                   Subject 
                                                       [eclipse-dev]       
              Please respond to                        NLS.bind(...) vs    
  "General development mailing list of the             MessageFormat.forma 
              Eclipse project."                        t(...)              
          <eclipse-dev@xxxxxxxxxxx>                                        
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           
                                                                           






Hi,

I'd like to get some clarification when one method should be used instead
of the other one.
In API Tools, we are trying to use MessageFormat.format(...), but I didn't
know and I ended up using NLS.bind(...).

When I was about to "fix" and go with MessageFormat.format from the ICU
bundle, I made a search for NLS.bind(...) usage and I found many hits. So
I'd like to know when each method should be used.The documentation inside
the NLS class mentioned that this is not a replacement for the
MessageFormat method, but it doesn't really say what kind of limitations
the NLS method has.

Can someone put some light on this, please?

Thanks,

Olivier
_______________________________________________
eclipse-dev mailing list
eclipse-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe
from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipse-dev
_______________________________________________
eclipse-dev mailing list
eclipse-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe
from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipse-dev
_______________________________________________
eclipse-dev mailing list
eclipse-dev@xxxxxxxxxxx
To change your delivery options, retrieve your password, or unsubscribe
from this list, visit
https://dev.eclipse.org/mailman/listinfo/eclipse-dev

Back to the top