commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Thorbjørn Ravn Andersen <>
Subject Re: svn commit: r628395 - in /commons/proper/configuration/branches/configuration2_experimental/src/main/java/org/apache/commons/configuration2: beanutils/ interpol/
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("", 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 = "";
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.


To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message