close

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:

SELECT
   FirstName
   , LastName
   , Phone
   , ZipCode
FROM Customers

etc.

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!

Brian

 

Brian Groover

The author Brian Groover

I spend my days as full-time programmer. In the evenings, I am an adjunct professor at a local college. In the remaining hours, I write fiction, songs, and poetry. In my copious free time (cough,) I sail on the Chesapeake Bay in my 30-foot Catalina Valinor Bound. I hope to see you at Balticon this year!

7 Comments

  1. I simply want to tell you that I’m all new to blogs and definitely savored your web site. Very likely I’m want to bookmark your site . You definitely come with beneficial stories. Bless you for revealing your web-site.

Leave a Reply to see this Cancel reply