commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thorbjørn Ravn Andersen <thunderax...@gmail.com>
Subject Re: svn commit: r628395 - in /commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2: beanutils/BeanHelper.java interpol/ConfigurationInterpolator.java
Date Sun, 17 Feb 2008 23:00:54 GMT
Emmanuel Bourg skrev  den 17-02-2008 23:36:
>
> it's less annoying after a comma :
>
>     foo.doSomething(param1,
>                     param2,
>                     param2);
I have found it convenient to introduce explanatory variables, named 
according to the parameter they are to be assigned (which should also be 
named well).

For instance this method

 public static void send(String smtpHost, int smtpPort,
                                String from, String to,
                                String subject, String content)


could be called with
    send("mailhost.com", 25, "me", "you", "hello world", "lots of text");

which may break given real life constants.  By extracting the parameters 
into variables you can explain each one.  By reusing the parameter names 
you copy the signature of the method which may make it easier to 
remember the purpose.   Also this usually requires less line breaks than 
having the parameter expression in the function calls.   For modern 
JVM's the performance is identical (as the variables will be inlined).

smtpHost = "mailhost.com";
smtpPort = 25;
from = "me";
to = "you";
subject = "hello world";
content = "....";
send(smtpHost, smtpPort, from, to, subject, content)

This works especially well for booleans where you generally never can 
remember what ", true, true)" versus ", true, false)" means.


-- 
  Thorbjørn

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@commons.apache.org
For additional commands, e-mail: dev-help@commons.apache.org


Mime
View raw message