A question for anyone who has read "Thinking in Java" by Bruce Eckel:
On page 197 (in the 4th edition), he has a class called "ArrayInit". In this class, he creates two Integer arrays to demonstrate the different ways of instantiating an array. I found it interesting that arrays can be initialized with a final comma in the list of initializers. He mentions as an exaplanation: "The final comma in the list of initializers is optional. (This feature makes for easier maintenance of long lists.)"
It's never used in the book again (unless I missed it) and I've never seen it used anywhere else in code/java tutorials/etc. It obviously works, and I've used it since. My question is, is this actually useful in any way? Can anyone give an example? And also, does anyone know _why_ this feature would make for easier maintenance of long lists?
I find they make editing easier when working with lists where I keep each item on a separate line, e.g.:
String[] names = {
"joe",
"bob",
"bill",
};
If I want to transpose the names "bob" and "bill", I just have to cut the entire bob line and paste it below the bill line. No messing with removing the comma from bob and adding it to bill.
I do not think it helps a programmer in any way by making his coding effort easier. I also do not think that it was an intensional feature added by the designer for any reason. Sometimes you get some features that are by-production of the way something is implemented. I am of the opinion that it does help tools that generate code. For example, if a tool is reading some text from a file and trying to build the array initialization then it can just keep grabing the values, add a comma at the end and then push it to the list. If the comma at the end is not allowed then tool has to check if it s the first item in the list or subsequent (it is your logic how you do it, but the truth is that you need some condiitonal logic here) and then add the comma or not. Except that I cannot think of allowing a comma at the end of list helps a programming in any way.