Whatever programming language you use, it will involve lists. Some languages, such as SQL in its various flavors, are so list-heavy that it is almost impossible to write anything in the language without using lists.
It has been my experience that programmers don’t tend to think about things like making their code look good. When I started programming in 1969, every line was self-contained, and lists were awkward and difficult to manage. With modern programming languages, we can make the code look as clean and pretty as we want to make it, and it will run just as fast. I’ve seen many programmers who seem to pride themselves on jamming their code into the smallest
This is foolishness. How much time do you waste by making the code smaller? I know, I’ve heard the “but it’s more efficient” argument, too. And then I watch as the “more efficient” coders have to rewrite each line a half dozen times.
Here is one simple way to make your lists simpler and easier to manage, not only for you, but for the coder who comes after you. (And if you aren’t thinking about that poor sap who has to unravel your code, then shame on you!)
Put the commas on the trailing lines, like this:
It’s a simple thing, and it makes your management of lists, no matter what language in which you are using them, easier. Much easier. Want to add a new item to the list? Just copy that last line, and enter the new name. Want to delete a line? Just delete it (or comment it out.) All those silly syntax bugs that come from not spacing out your lists and putting the commas before the next line go away.
There are about a thousand simple things like this which make your life much easier as a programmer. There are also many ways of formatting lists, and lots of other tips just in this tiny area of coding. If this one was new to you, please drop me a comment and let me know!