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: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]