Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are trailing commas in Perl a bad practice? [closed]

Tags:

arrays

hash

perl

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, ]; 
like image 213
Francisco Zarabozo Avatar asked May 19 '14 23:05

Francisco Zarabozo


People also ask

Are trailing commas allowed in JavaScript?

As it's been already said, JSON spec (based on ECMAScript 3) doesn't allow trailing comma. ES >= 5 allows it, so you can actually use that notation in pure JS.

Are trailing commas good practice?

In general, you should make use of trailing commas when you frequently copy/paste properties or add new items to the end of a list. You can also take advantage of them to produce cleaner diff outputs.


1 Answers

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.

like image 137
brian d foy Avatar answered Sep 28 '22 14:09

brian d foy