Date: prev next · Thread: first prev next last
2012 Archives by date, by thread · List index


On Sunday 08 of July 2012, Christophe JAILLET wrote:
Hi,

Sometimes some methods are declared with some default value(s)
As an example, here is the definition of matchAsciiL for OUString

     sal_Bool matchAsciiL( const sal_Char* asciiStr, sal_Int32
asciiStrLength, sal_Int32 fromIndex = 0 ) const SAL_THROW(())



When these functions are called, the optional parameters are sometimes
passed with the default values.
As an example, at line 60 of
/framework/source/lomenubar/MenuItemStatusListener.cxx, we can find :

     if ((Event.State >>= oULabel) &&
         !oULabel.matchAsciiL ("private:", 8, 0) &&
         !oULabel.matchAsciiL (".uno:", 5, 0)    &&
         !oULabel.matchAsciiL ("slot:", 5, 0)    &&
         !oULabel.matchAsciiL ("service:", 8, 0) &&
         !oULabel.matchAsciiL (".cmd:", 5, 0)    &&
         !oULabel.matchAsciiL ("macro:///", 5, 0))


Would it be interesting to lightweight the code by removing these
useless parameters ?

 In general yes, but in this specific case this it would probably rather make 
things worse, because changing

 oULabel.match("private:", 0)

 to

 oULabel.match("private:")

 gives the wrong idea about what it does. The latter looks a lot like

 oULabel == "private:"

 which is not what it is. The first case is also not exactly intuitive, but at 
least the 0 there is a hint.

 IMO the proper fix would be to remove the default value (which we can't do 
until 4.0 because that'd break backwards compatibility) and introduce 
OUString::startsWith() (which would complement the already existing 
endsWith() ).

-- 
 Lubos Lunak
 l.lunak@suse.cz

Context


Privacy Policy | Impressum (Legal Info) | Copyright information: Unless otherwise specified, all text and images on this website are licensed under the Creative Commons Attribution-Share Alike 3.0 License. This does not include the source code of LibreOffice, which is licensed under the Mozilla Public License (MPLv2). "LibreOffice" and "The Document Foundation" are registered trademarks of their corresponding registered owners or are in actual use as trademarks in one or more countries. Their respective logos and icons are also subject to international copyright laws. Use thereof is explained in our trademark policy.