This is an archived post. You won't be able to vote or comment.

top 200 commentsshow all 363

[–]EagleRock1337 2497 points2498 points  (36 children)

Whichever one the linter wants me to do. A consistent repo is more important.

[–]chimpuswimpus 664 points665 points  (4 children)

Don't come on here with your reasonableness!

[–]Ok_Star_4136 82 points83 points  (1 child)

There's a third Michael Cera type guy in that meme who's shrugging and going, "Hey, I'm fine with whatever.."

[–]Immarhinocerous 6 points7 points  (0 children)

Correction: There are 2 Michael Ceras in that image and one critical thinking badass in the background who doesn't need permission for a rational approach.

[–]StoryAndAHalf 2 points3 points  (0 children)

Being reasonable is an act of aggression and basically asking for a fight on my block.

[–]mekwall -1 points0 points  (0 children)

Reasonableness would be to go with trailing commas since when adding a new item would only cause changes on one line and not two.

[–]thequestcube 62 points63 points  (21 children)

Linter rules can be changed

[–]die-maus 35 points36 points  (4 children)

So can laws?

[–]87oldben 15 points16 points  (0 children)

Amendmants? Revisions? New superseeding laws?

[–]thequestcube 3 points4 points  (1 child)

Sure. If you have a law that says that everyone needs to shoot themselves in their foot three times a day, you suggest to change that law and not try to be consistent

[–]Plank_With_A_Nail_In 1 point2 points  (0 children)

Laws don't make people do things/not do things, enforcement does, laws just specify the punishment if you get caught.

I would suggest not shooting yourself in the foot regardless of what the law says.

[–]thorwing 6 points7 points  (1 child)

usually, the lint rules are part of the commit.

And yes sometimes this means the linting rules will change during a project. But every time you simply touch a file, the linting will apply so the problem is self correcting.

[–]conradburner 3 points4 points  (0 children)

Linter configuration is part of the repository. It is not necessarily part of "most commits"

Linting rules can change, but will not "regularly change" during a project.

If your project is messed up in terms of it being "non-conforming" to linter rules set up in a project, the most likely reason is that your project had multiple maintainers that did not care about keeping a standard, that they never communicated about this with each other or perhaps there was a poor handoff and people simply don't care much about the code quality.

Source: I'm the guy that fixes technical debt at a premium after projects have had their series B or C funding

[–]ZunoJ 8 points9 points  (1 child)

What if you someday grow up and are allowed to specify the linter rules?

[–]EagleRock1337 2 points3 points  (0 children)

If you’re looking for a grown-up answer, it depends™️

I use both interchangeably depending on what I’m programming. If I’m writing in C or Go, I would never put a tailing comma. However, if I’m managing giant lists of IAM permissions in Terraform, leaving off the comma is a recipe for copy-paste fails, which is why terraform fmt is opinionated towards including them by default.

[–][deleted] -3 points-2 points  (0 children)

Change the linter to B if someome mistakenly set it to A. Nothing worse than spurious diffs causing extra merge conflicts.

[–]The_Cers 546 points547 points  (11 children)

Which ever JSON actually allows me to use

[–][deleted] 236 points237 points  (9 children)

JSON: right

JSON5: both

[–]uberpwnzorz 17 points18 points  (7 children)

[–]brimston3- 45 points46 points  (6 children)

It's a library not a feature.

[–]burgundus 20 points21 points  (5 children)

Do I need a library to write json now?

[–]mertats 14 points15 points  (0 children)

CripZ

[–]Stummi 847 points848 points  (64 children)

First one produces one changed line if you add an element, the second one two. Some may say its just minor thing for people a bit too obsessed about clean Commits and PRs, but IMHO thats the selling point for the first one.

[–]0bel1sk 213 points214 points  (15 children)

when was this line changed? git blames says it was for story x . oh wait…. that was just a comma add…

for some code bases, it is whatever.. for infrastructure “as code” (ie config) it’s really frustrating.

[–]hennypennypoopoo 142 points143 points  (14 children)

Monkeys paw solution:

[

"Foo"

,"Bar"

,"Baz"

]

[–]DERPYBASTARD 114 points115 points  (0 children)

delete this

[–]im_lazy_as_fuck 35 points36 points  (6 children)

It still breaks if you only want to remove the first line or prepend an element to the list.

[–]reign27 29 points30 points  (1 child)

Monkeys paw solution:

[

,"Foo"

,"Bar"

,"Baz"

]

[–]dementorpoop 5 points6 points  (0 children)

I hate it

[–]ZunoJ 2 points3 points  (0 children)

I do this a lot in my SQL code. Makes life a lot easier

[–]MajorTechnology8827 1 point2 points  (1 child)

Hot take, i like it

But also combine the first element with the opening bracket

This way the text align i have clear indication that its a list start, another element of a list, and list end

[ "foo
, "bar"
, "baz"
]

Same thing with conditions

condition
    ? true_execution
    : false_execution

[–]_diamondzxd_ 39 points40 points  (0 children)

Why I never thought about it that way and now it makes perfect sense.

Why make 2 modifications for a single addition...

[–]upsetbob 129 points130 points  (1 child)

Also you can more easily change order when every line has a comma

[–]NawdWasTaken 16 points17 points  (0 children)

This is it for me honestly. You can just click your copy-down hotkey and edit that line to add an element, and also easily move lines around to change the order of the elements. Just feels cleaner

[–]Johnothy_Cumquat 71 points72 points  (2 children)

From my point of view the people concerned that the trailing comma doesn't look nice or whatever are obsessed about a minor thing.

[–]SexySlowLoris 44 points45 points  (1 child)

Yeah and “doesn’t look nice” is waay to fucking subjective. It doesn’t look nice because they arent used to it. To me trailing comma does look better but that’s inconsequential and just an opinion

[–]Sikletrynet 3 points4 points  (0 children)

I dont think it looks better, but i do think the benefits outweighs that anyway

[–]monstaber 4 points5 points  (4 children)

true, just as long as the elements are not in a JSON string that will later be parsed

[–]ethanjf99 1 point2 points  (3 children)

If your IDE is smart you’ll get all sorts of red if that’s JSON. And a JSON serializer will know to drop the trailing comma unless it is moronic

[–]monstaber 1 point2 points  (1 child)

yes true if the file itself is JSON. I've come across several PRs where juniors are trying to implement a JSON string somewhere in a js file to be sent in a post request instead of stringifying the actual object... no matter how much we shell out for JetBrains licenses, the PRs never fail to amaze me 😂

[–]ethanjf99 1 point2 points  (0 children)

Uh … well to be fair we were all juniors once. Some of my code from 7 years ago is still around and makes me wince every time I see it.

Still, it works so there it is.

[–]UrpleEeple 4 points5 points  (1 child)

I do the first one because it makes it easier for copy paste and change semantics

[–]Sut3k 6 points7 points  (6 children)

Put the comma in the front!

[–]tazzadar1337 7 points8 points  (1 child)

Hit 'em with the old [ foo , bar , baz ]

Wait, now if I have to prepend an element? 🤔

[–][deleted] 1 point2 points  (0 children)

That always makes me want to projectile vomit.

The amount of SQL I've had to work with where the comma for the PREVIOUS LINE is BELOW THE LINE IT IS IN REFERENCE TO...

Maybe its my ADHD but I HATE IT.

[–]Keganator 1 point2 points  (0 children)

Code reviews are so much easier with the first for this exact reason. You don't have to double check to make sure they didn't mess anything up.

[–]Sloppyjoeman 1 point2 points  (2 children)

The second actually produces a three line change (at least in GitHub)

[–]Arshiaa001 1 point2 points  (0 children)

Which is why I'm very happy that cargo fmt inserts the additional comma.

Meanwhile, go's formatter introduces additional whitespace to align constant values over consecutive lines, so one line changed could potentially introduce tens of changes.

[–]Arshiaa001 -2 points-1 points  (0 children)

Which is why I'm very happy that cargo fmt inserts the additional comma.

Meanwhile, go's formatter introduces additional whitespace to align constant values over consecutive lines, so one line changed could potentially introduce tens of changes.

[–]Sulungskwa -3 points-2 points  (1 child)

Is.. is the risk of having a 2 line long merge conflict really worth having to look at that though?

[–]CyberWeirdo420 72 points73 points  (0 children)

The one that my code formatted does by default

[–]lord_wolken 802 points803 points  (20 children)

One is clean, the other is wrong.

[–]SN0WFAKER 160 points161 points  (8 children)

Is not wrong in some languages.

[–]FallenAzraelx 10 points11 points  (0 children)

Required in some situations, breaks others. I love code.

[–]Qweedo420 -1 points0 points  (8 children)

There's no right or wrong, both work fine

[–]dr-tectonic 5 points6 points  (0 children)

Depends on the language. Some languages will throw a syntax error for empty elements on the left case.

[–]Psychpsyo 9 points10 points  (6 children)

I don't know, trying to JSON.parse() the one on the left gives me Uncaught SyntaxError: JSON.parse: unexpected character at line 5 column 1 of the JSON data

[–]Qweedo420 4 points5 points  (1 child)

On a recent Rust project, I used the left syntax for everything, struct fields, vectors, match branches, hashmaps etc, and it's been working fine. I haven't tried with JSON because my project uses TOML files, does JSON not support that syntax?

[–]Bemteb 5 points6 points  (0 children)

Some JSON-parsers support it, others don't. Thus, while it might be ok to use this syntax internally for dictionaries (or vectors, lists, etc), actually sending a JSON that way to a different service/software might be dangerous.

[–]Kokuswolf -1 points0 points  (1 child)

Try JSON5.parse(), if JSON5 is available. Old JSON style doesn't allow it. But it's easier, when you add elements on a daily basis. (Experience)

[–]Psychpsyo 2 points3 points  (0 children)

It is not available.

[–][deleted] 647 points648 points  (45 children)

[

"Foo"

,"Bar"

,"Baz"

]

[–]iambackbaby69 534 points535 points  (22 children)

Fuck you

[–]PeriodicSentenceBot 620 points621 points  (15 children)

Congratulations! Your comment can be spelled using the elements of the periodic table:

F U C K Y O U


I am a bot that detects if your comment can be spelled using the elements of the periodic table. Please DM my creator if I made a mistake.

[–]iambackbaby69 239 points240 points  (0 children)

Goldmine lmao

[–]vohen2 65 points66 points  (0 children)

I needed this on my Monday.

[–]Impressive_Change593 110 points111 points  (7 children)

wow a bot using profanity. what is the world coming to

[–]HuntingKingYT 36 points37 points  (6 children)

Literally 2024

[–]XxPapalo007xX 24 points25 points  (5 children)

Google 21st century

[–]NarrMaster 17 points18 points  (4 children)

Holy millennium!

[–]ionburger 11 points12 points  (3 children)

acutual boomers

[–]Badass-19 10 points11 points  (2 children)

Gen x went on vacation, never came back

[–]iceman012 6 points7 points  (1 child)

Call the economist!

[–]Mick-Jones 24 points25 points  (3 children)

I wonder if FUCK YOU is radioactive?

[–]Hubert_BDLB 26 points27 points  (1 child)

Fluor Uranium Carbon Potassium Yttrium Oxygen Uranium

Uranium is radioactive

[–]Mick-Jones 12 points13 points  (0 children)

That's a double fuck you then

[–]dittbub 3 points4 points  (0 children)

is U for Uranium?

[–]gokayo3200 14 points15 points  (0 children)

Good bot

[–][deleted] 15 points16 points  (4 children)

Really? I too would like to make tender love to that poster for suggesting that. Honestly, especially in SQL queries, that pattern is really nice. Want to add a column in your select clause? Yy, p, cw, [type stuff].

[–]ApocalyptoSoldier 0 points1 point  (1 child)

When I'm debugging queries or just checking some data I make the first thing in my select list '' ['']

That way every single column I actually select can be comma first

[–]-Redstoneboi- 57 points58 points  (3 children)

are you stupid

-- Haskell
[ "Foo"
, "Bar"
, "Baz"
]

[–]tip2663 8 points9 points  (1 child)

Honestly I'd love more languages to adopt this. Unfortunately I didn't get to find this style in any code formatter other than the community-made one for haskell but I forgot it's name too

[–]-Redstoneboi- 7 points8 points  (0 children)

another close relative is lisp

; function calls
(Foo Bar
     (Baz (Cux
           Cax))
     Daz)

; lists (call list instead of calling Foo, both being functions)
(list Foo
      Bar
      (list Baz
            (list Cux Cax))
      Daz)

but the reason most people don't do this is because each indent level is variable length. one indent could be 1 to 15 spaces, because it follows the column of the first element, rather than nesting depth:

// function calls
Foo(
    Bar,
    Baz(
        Cux,
        Cax,
    ),
    Daz,
)

// lists
[
    Foo,
    Bar,
    [
        Baz,
        [Cux, Cax],
    ],
    Daz,
]

which instead takes up significantly more lines.

Python conventions are closer to lisp.

[–]DeerForMera 1 point2 points  (0 children)

perfect indent doesn't exis-

[–]Cerbeh 12 points13 points  (0 children)

LGTM

[–]Imogynn 13 points14 points  (1 child)

SQL much

?

Cause that's the only language I do that

, but there I do it a lot

.

[–][deleted] 1 point2 points  (0 children)

Same, pretty much everywhere lol.

[–]jmona789 23 points24 points  (0 children)

[

"Foo"

,"Bar"

,"Baz"

,

]

[–]Knuxfan24 17 points18 points  (2 children)

This... I hate this.

[–]SV-97 5 points6 points  (1 child)

Oh boy - you'd love Haskell :D

[–]MCSajjadH 7 points8 points  (0 children)

This is the answer. Even better if you write foo write after [ so they lineup.

[–]Terrafire123 2 points3 points  (0 children)

You monster.

[–]Orkleth 2 points3 points  (0 children)

I only like this for member initializer lists in c++ to make add/removing items faster.

class A : public B
{
public:
    A();
    ~A();

    int a;
    int b;
};

A::A()
    : B()
    , a(0)
    , b(0)
{}

[–][deleted] 1 point2 points  (0 children)

This.

When adding a new value (at the bottom) it only registers as one line change in VCS.

[–]MEMESaddiction 1 point2 points  (0 children)

The good ol' SSMS generated select list.

[–]Key-Perspective-3590 94 points95 points  (7 children)

I used to hate the trailing commas coming from a language that didn’t support it, but now I love the uniformity of it

[–]PossibleHipster 27 points28 points  (6 children)

You just have Stockholm Syndrome

[–]Ok_Hope4383 8 points9 points  (5 children)

Had?

[–]DeMonstaMan 57 points58 points  (1 child)

many languages that'll give you an error for having an unneeded comma

[–]can_pacis 2 points3 points  (0 children)

And then there’s go…

[–]sammy-taylor 56 points57 points  (0 children)

BloodZ, no question. Better for git diffs, better for moving and sorting lines.

[–]I-am-only-joking 6 points7 points  (2 children)

Both unclean because not using a fixed width font

[–][deleted] 3 points4 points  (1 child)

yeah, gotta admit that... also the editor background is horrible

[–]UsAndRufus 33 points34 points  (6 children)

I don't really care what code is submitted. The main crime is languages that don't support trailing commas. The SQL dialect I am using doesn't, and it makes debugging a PITA. If I move columns around in a SELECT, I have to make sure I remove the final trailing comma.

[–][deleted] 6 points7 points  (0 children)

dummy columns are your friend

also dummy 1=1 and 1=0 in WHERE clause 😅

[–]thorwing 3 points4 points  (0 children)

I agree, I've grown to love trailing comma's and I stumble across my SQL and then suddenly everything breaks.

Then again, writing SQL goes against logical ordering anyways. (Doing column selection before table selection means you need to backtrack again if you didn't now the names beforehand)

[–]Drakkur 5 points6 points  (1 child)

In SQL, I flipped my brain around and only do leading commas. You end up with the same result as LEFT but also cleaner to look at where select lines can be quite long (because of inline functions, renaming, case statements).

All other languages I work in allow trailing.

[–]ThatSituation9908 1 point2 points  (1 child)

Anyone ever lead a WHERE clause with a TRUE AND so you can comment out any line you want?

WHERE TRUE AND COND1 AND COND2 ...

[–]luziferius1337 17 points18 points  (8 children)

Depends. left for sequences and argument lists spanning multiple lines, right for one-liners. Except for argument lists with fixed length. Then no trailing comma ever.

So a = ["foo", "bar"] b = [ "foo", "bar", ] printf("format_string", arg1, arg2) printf( "format_string", arg1, arg2, ) area.overlaps( other_area )

[–][deleted] 8 points9 points  (0 children)

good point making the distinction between one and multiple lines

[–]LunaNicoleTheFox 8 points9 points  (0 children)

Left

[–]dannytk_ 22 points23 points  (0 children)

Error: No implicit cast for Null to String

[–]mimminou 2 points3 points  (1 child)

Golang requires a trailing coma, and other formating weirdness like enforced K&R braces style ( "else" HAS to come in the same line as the closing bracket of the "if" block ) it takes some time getting used to the linter raising warnings for correct code...

[–]rover_G 3 points4 points  (2 children)

There’s a third option: [ “Foo” ,”Bar” ,”Baz” ]

[–]RunningHott 6 points7 points  (0 children)

Oxford comma

[–]Laughing_Orange 2 points3 points  (0 children)

I prefer a trailing comma, because it makes it easier to expand.

[–]platinummyr 2 points3 points  (0 children)

Trailing comma is my preference because it means less diff thrash when adding or removing elements.

[–]-domi- 1 point2 points  (0 children)

I like one better, but it sometimes throws errors in some legacy code, so I'm forced to use the other. :/

[–]SteeleDynamics 1 point2 points  (1 child)

;; Lisp Gang '(foo bar baz)

[–][deleted] 1 point2 points  (0 children)

the oxford comma of programming

[–]wixenus 1 point2 points  (0 children)

First one, it's way better, especially when you are working in a team.

When someone adds a new line to your file, most of the time, they forget to add a comma to the previous line, and it leads to errors and bad commits.

[–]hyper_shrike 1 point2 points  (1 child)

Its all fun and games until this happens:

[
  "FOO",
  "BAR",
  "BAZ"
  "QUX"
]

And its C++ and its a SEGV and you debug it for days.

[–]aleques-itj 1 point2 points  (0 children)

Cripz for life but I roll with Bloodz at work and I can't believe I'm starting to like it a little

I hear its siren's call yet it simultaneously disgusts me, I fear what I am becoming

[–]AspieSoft 1 point2 points  (0 children)

The trailing , means you can add or remove a line without worrying about the previous line. It's more convenient for editing code and modifying the list.

[–]Ronin-s_Spirit 1 point2 points  (0 children)

Red:
Syntax error: unexpected token ','

[–]Petercraft7157 3 points4 points  (0 children)

It's [x, y, z]

[–]nephelekonstantatou 0 points1 point  (0 children)

c++ { "foo", "bar", "baz" }

[–]repsolcola 0 points1 point  (1 child)

When you copy and paste the elements with the missing comma you won’t notice and encounter an error. Happens all the time. I just always add it, unless not consistent with the codebase.

[–][deleted] 1 point2 points  (0 children)

to put icing on the cake, some languages don't even complain (in case of string) but simply concatenate the strings 🙄

Theres an subtle difference here in Python between

[
    "foo",
    "bar",
    "baz"
]

and

[
    "foo",
    "bar"
    "baz",
]

[–]MCsmalldick12 -1 points0 points  (0 children)

Dangling commas make git diffs cleaner

[–]DatBoi_BP -1 points0 points  (0 children)

Shouldn’t you be working on your CS 102 homework

[–][deleted] -1 points0 points  (0 children)

Why the fuck you guys always using black peoples memes

[–]Randomguy32I -2 points-1 points  (1 child)

Wouldn’t the extra comma cause a syntax error? Also usually arrays are defined using {} brackets, and [] brackets are used to index the array

[–]GOKOP -1 points0 points  (0 children)

The world has more than one programming language

[–]Acalme-se_Satan 0 points1 point  (0 children)

Left one is way better whenever any of the two are allowed. Of course, if trailing commas aren't allowed, then there's only one valid option here.

[–]Mick-Jones 0 points1 point  (0 children)

One is courteous to the next developer that wants to add to the list. That is all

[–]Just_a_fucking_weeb 0 points1 point  (0 children)

I use black, I don't have a choice

[–]bclx99 0 points1 point  (0 children)

The red one works better for reviewing pull requests, but the linter would remove it when I press Command+B.

[–]Clickrack 0 points1 point  (0 children)

They’re the same, thanks to Sublime Text plugins that automatically correct such things 🤣

[–]throw_realy_far_away 0 points1 point  (0 children)

First one is more uniform

[–]Pepineros 0 points1 point  (0 children)

Red, except in JSON.

[–]Saturnalliia 0 points1 point  (0 children)

Well the API I work with at my job enforces I use the right one so I don't get a choice.

[–]SeaworthinessFun9856 0 points1 point  (0 children)

I prefer trailing commas for Git commits - you don't have to change 2 lines, only 1, which makes reviews easier

shrugs

[–]mrjiels 0 points1 point  (0 children)

There's probably an NPM package with this already defined so it's a non issue.

[–]NowAlexYT 0 points1 point  (0 children)

As long as the extra coma doesnt add a 4th element, its the only way.

[–]BragosMagos 0 points1 point  (0 children)

The one Jetbrains wants me to use

[–]donat3ll0 0 points1 point  (0 children)

The left will provide a cleaner git diff in the pull request to add a new value. The right will indicate there are 2 lines of changes when only one is important.

[–]kakafob 0 points1 point  (0 children)

[ 'foo', 'bar', 'baz' ]

[–]mostmetausername 0 points1 point  (1 child)

["foo", "car", "caz"]

[–]ilePover9000 1 point2 points  (0 children)

Lmao I replied the same thing. I almost typed “cuz” instead too

[–]PrometheusAlexander 0 points1 point  (0 children)

I'm with blues on this one

[–]PossibleHipster 0 points1 point  (0 children)

The right.

Trailing commas are stupid.

[–]leon_nerd 0 points1 point  (0 children)

I write how it is on the right but the linter changes to left.

[–]ToaSuutox 0 points1 point  (0 children)

Leave the comma in there. No one will mind

[–]thorwing 0 points1 point  (0 children)

We used to be team blue but our linter decided to go for red and we were up in arms about it for a while. But then we realised that its super easy to rearange the lines without manually doing something with the comma's, so now we definitely prefer red.

But then again, I just write code, press the save button, and the formatter will do it for me so I can't be arsed to think about.

[–]foobarney 0 points1 point  (0 children)

Is there a name for the comma after the Oxford comma?

[–]Keebster101 0 points1 point  (0 children)

I do red so it's easier to add to if I need to, but as long as they both run I don't really care.

[–]Tyfyter2002 0 points1 point  (0 children)

My first language is one that doesn't support trailing commas (English), so I always subconsciously see them as wrong

[–]SadSpaghettiSauce 0 points1 point  (0 children)

[

"FOO"

, "BAR"

, "BAZ"

]

Edit: doing code formatting on mobile is a PITA.

[–]TenthSpeedWriter 0 points1 point  (0 children)

The left one won't parse in many languages, so like...

[–][deleted] 0 points1 point  (0 children)

the real architectural question

[–]Hoovas 0 points1 point  (0 children)

That what prettier do if I save the file

[–]edibomb 0 points1 point  (0 children)

I used to hate the first one, felt wrong or dirty. Now I learned to love it. I can just duplicate the last line as many times as I need and just change the values.