Are trailing commas in Perl a bad practice?

arrays, hash, perl

Solution

It's a great practice to have the trailing comma. Larry added it because he saw programmers add elements to a list (or whatever their language called it) but forget the separator character. Perl allows the trailing comma to make that less common. It's not a quirk or side effect of something else. That's what Perl wants you to do.

What is bad practice, however, is distracting a meeting full of people with something your boss could have corrected later. Unless the meeting was specifically a code review, your boss wasted a bunch of time. I've always wished that to join a video conference, you had to enter your per-minute compensation so a counter would show on everyone's screen to show how much money was being wasted. Spending a couple hundred dollars watching you remove commas on a working program would tamp down that nonsense.

Problem

Today I was in a Webex meeting showing my screen with some Perl code I wrote. My boss suddenly told me while everyone else was looking and hearing that I had to remove trailing commas from my hash and array structures because it is a bad practice. I said I didn't think that was a bad practice in Perl, but he insisted and made me delete those commas just to show my script running in the meeting. I still think it's not a bad practice in Perl, but I can be wrong. I actually find them pretty convenient and a good practice because they prevent me from adding new elements and forgetting to add the corresponding comma in the process. But, I'd really like to know if it's a good or bad practice and be able to show it my boss (if he's wrong) with good arguments and even good sources for my arguments. So, is it a bad practice to leave trailing commas? This is an example: ``` my $hash_ref = { key1 => 'a', key2 => 'b', key3 => 'c', }; my $array_ref = [ 1, 2, 3, ]; ```

Original source