I have a java program which has long argument list:
public class MyTool {
public static void main(String[] args) {
String aaa = args[0];
String bbb = args[1];
String ccc = args[2];
String ddd = args[3];
String eee = args[4];
String fff = args[5];
String ggg = args[6];
}
}
When my colleague use it, he complains that the argument list is too long, that he have to pass the arguments this way:
java MyTool someArg someArg someArg someArg someArg someArg someArg
that he is confused what the meaning of each argument without checking the source code again and again.
He suggest me to use -Daaa=bbb
style to pass argument, that means my code should be:
public class MyTool {
public static void main(String[] args) {
String aaa = System.getProperty("aaa");
String bbb = System.getProperty("bbb");
String ccc = System.getProperty("ccc");
String ddd = System.getProperty("ddd");
String eee = System.getProperty("eee");
String fff = System.getProperty("fff");
String ggg = System.getProperty("ggg");
}
}
So he can invoke it as:
java -Daaa=someArg -Dbbb=someArg -Dccc=someArg \
-Dddd=someArg -Deee=someArg -Dfff=someArg -Dggg=someArg \
MyTool
Which is much better for him to know the meanings of each argument without checking the source code.
I'm confused which way is better, and when I should use one against another?