Remix.run Logo
socalgal2 4 days ago

some settings have advantages. For example, trailing commas on tables

    [
      'apple',
      'banana',
      'orange',
    ]
has an advantage over

    [
      'apple',
      'banana',
      'orange'
    ]
Because adding a new line at the end of the table (1) requires editing 1 line, instead of 2 (2) makes the diffs in code review smaller and easier to read and review. So a bad choice makes my life harder. The same applies to local variable declarations.

Sorted lists (or sorted includes) is also something that makes my life easier. If they're not sorted then everyone adds their new things to the end, which means there are many times more merge conflicts. sorted doesn't mean there are zero but does mean there are less than "append to the end". So, just like an auto-formatter is there to save time, don't waste my time by not sorting where possible.

Also, my OCD hates inconsistency. So

    [1, 2, 3]
    {a, b, c}
Is ok and

    [ 1, 2, 3 ]
    [ a, b, c ]
Is ok but

    [1, 2, 3]
    { a, b, c }
Is not. I don't care which but pick ONE style, not two styles!
austin-cheney 4 days ago | parent | next [-]

Yes, everyone has personal opinions about code vanity. When this becomes a holy war I really start to question the maturity of people on the project. I find that people worry about trivial nonsense to mask their inability to address more valid concerns.

All that really matters is consistency. Let a team make some decisions and then just move forward.

2muchcoffeeman 4 days ago | parent | next [-]

Don’t bother making decisions. Steal a standard. Vote on it once if you want to be democratic. Done forever.

gorgoiler 3 days ago | parent [-]

Democracy, strictly speaking, would be to periodically elect the most popular formatting policy once every sensible-time-period.

I’ve seen companies with such a large amount of developer churn that literally one person was left defending the status quo saying “we do X here, we voted on it once in 2019 and we’re not changing it just for new people”. 90% of the team were newcomers.

(The better teams I’ve worked on maintain a core set of leaders who are capable of building consensus through being very agreeable and smart. Gregarious Technocracy >> Popular Democracy!)

plusplusungood 3 days ago | parent [-]

Ah, the infamous, but fictional, Monkey Ladder Experiment.

socalgal2 3 days ago | parent | prev | next [-]

> All that really matters is consistency

And this is my problem. My last example, the 2 styles are inconsistent. So when the guideline is "all that matters in consistency" then I take that at face value. You though apparently pull back and believe something more messy. Effectively "All that really matters is a consistently applied style even if that style itself is full of inconsistency"

The same applies to the trailing commas. With them, every line is consistent. Without, the last line is inconsistent with the other lines. So are we applying this rule "All that really matters is consistency" or only applying it sometimes? I would argue whatever heuristic made you say "All that really matters is consistency" should apply to both cases. Consistently apply a style guide and, the style guide itself should be consistent.

godshatter 2 days ago | parent [-]

> Without, the last line is inconsistent with the other lines.

The last line without a comma imparts the information that this line is expected to be the last line in the list which is something you don't get from it with that trailing comma. It's a small thing, but I don't like putting in that last comma because I'm effectively misrepresenting things for "syntactic sugar".

ParetoOptimal 3 days ago | parent | prev | next [-]

> All that really matters is consistency. Let a team make some decisions and then just move forward.

Not so! Amount of tokens correlates to perceived code complexity to some. One example is how some people can't unsee or look past lisps parenthesis.

Another example is how some people get used to longDescriptiveVariableNames but others find that overwhelming (me for instance) when you have something like:

    userSignup = do
        let fullName = userFirstNameInput + userLastNameInput
            userName = take 1 userFirstNameInput + take 10 userLastNameInput
        saveToDB userName
Above isn't bad, but imagine variables named that verbosely used over and over, esp in same line.

Compare it to:

    userSignup = do
        let fullName = firstName + lastName
            userName = take 1 firstName + take 10 lastName
        saveToDB userName
The second example loses some information, but I'd argue it doesn't matter too much given the context one would typically have in a function named `userSignup`.

I've had codebases where consistency required naming all variables like `firstNameInputField` rather than just `firstName` and it made functions unreadable because it made the unimportant parts seem more important than they were simply by taking up more space.

parthdesai 3 days ago | parent | prev [-]

It's one of my pet peeves when some senior engineers are bothered more by these coding semantics in a PR when there are bigger data model/code architectural issues, and don't call that out.

yes_man 4 days ago | parent | prev | next [-]

The problem is when 2 people with same level of enthusiasm for linter rules but opposing views collide. If there’s nothing more impactful you could be solving and spending energy and time on than arguing those linter rules, then it’s time to question where the project is at and where is it going.

And if there is something more important, then instead of of micro-optimizing the rules when there is strong disagreement it’s probably best if one of the parties takes the high road and lives with it so you can all focus on what matters.

vbezhenar 4 days ago | parent | next [-]

I guess that's one reason why opinionated tools like prettier or gofmt are popular. They made all the choices for you, they don't have configurable knobs, so you just learn to live with it.

lsaferite 3 days ago | parent | next [-]

FWIW, there are formatting decisions that gofmt doesn't make for you, so it's not as simple as just using gofmt.

megamalloc 3 days ago | parent | prev [-]

The bad thing about these sort of tools is when you work in a shop where multiple platforms are used for development and one of the platforms doesn't support the tool, or the tool fights with other tooling on that platform. You should for example never use pre-commit to enforce line ending style because git has brain dead defaults (which is to say, unless you have a .gitsettings file in your repo to prevent it, it will change line endings itself, fighting pre-commit). This just creates confusion and wasted time. In aid of what? So some anal so-and-so can get their way about code formatting as though it makes everyone else more productive to format code THEIR way. When in fact it makes others LESS productive as they fight "computer says no" format-nazi jobs in CI that don't even report what is "wrong" with the formatting and rely on tooling that they don't have installed to run locally.

Not to mention the overhead of running these worthless inefficient tools on every commit (even locally).

Tools like this just raise the debate from different opinions about formatting to different opinions about workflows. Workflows impact productivity a lot more than formatting.

3 days ago | parent [-]
[deleted]
bluGill 3 days ago | parent | prev [-]

You should force them to choose from someone else's style. Don't let them tweak individual settings, choose a complete standard and apply it with both the thing they like and things they don't. A style is useful, the details do not matter that much.

rapind 4 days ago | parent | prev | next [-]

Let this sink in though:

    [ 'apple'
    , 'banana'
    , 'orange'
    ]
maest 4 days ago | parent | next [-]

That makes prepending an element a special case.

ParetoOptimal 3 days ago | parent [-]

It makes it easier to read though because the least important parts are most easily ignored. The reader can focus on the contents of the list.

3pt14159 3 days ago | parent | next [-]

I don't really know why we even need commas for lists of things. Just use the white space.

bogomog 3 days ago | parent | prev [-]

I find it jarring compared to commas after the words, making the commas unnecessarily prominent.

JBiserkov 4 days ago | parent | prev | next [-]

In Clojure, commas are treated as whitespace and are thus completely optional.

Nevermark 4 days ago | parent | prev [-]

This is so clearly superior. Delimiters are prefixes.

But the scale of technical debt this insight has revealed is depressing.

citizenkeen 4 days ago | parent [-]

Saying this is clearly superior means you don’t keep your lists sorted. A sorted list is as likely to add something to the beginning as the end, where this solution has the same problem.

Nevermark 4 days ago | parent | next [-]

I just reverse the sort order when that case happens.

setr 4 days ago | parent | prev [-]

The only correct syntax/format

    [
      , a
      , b
      , c
    ]
If only there existed a language designer intelligent enough to support it
maccard 4 days ago | parent | next [-]

You want yaml

    key:
      - a
      - b
      - c
MonkeyClub 3 days ago | parent | prev | next [-]

Lisp:

  (
    a
    b
    c
  )
crazygringo 3 days ago | parent | prev [-]

Thank you for the humor!

I'm just suddenly slightly terrified someone's going to see this and think it's genuinely a good idea and make it part of the next popular scripting language, where lists are defined by starting commas or something :S

jrochkind1 3 days ago | parent | prev | next [-]

You'll be annoyed to know that your last "not okay" style is what's considered standard in ruby (although the curly braces have different semantics, they are, well, either a hash or a code block (which is kind of annoying to me that they're used for two entirely different things) never a list/array).

zahlman 3 days ago | parent | prev | next [-]

> Also, my OCD hates inconsistency

Mine hates trailing commas :)

More seriously, I don't like having lists like that in the code in the first place. I don't want multiple lines taken up for just constant values, and if it turns out to require maintenance then the data should be in a config file instead anyway.

whizzter 3 days ago | parent | next [-]

Rule of 3, write/change it once or twice (or seldomly enough with no possible negative impact) and it doesn't need any complexity. More than so.. yeah probably goes into a config.

Revisional_Sin 3 days ago | parent | prev [-]

Constants in the code are easier to navigate to than config files.

muzani 4 days ago | parent | prev | next [-]

I agree with you on all these points. If you were to argue the opposite point, I'd agree as well.

aleph_minus_one 4 days ago | parent | prev | next [-]

> Because adding a new line at the end of the table (1) requires editing 1 line, instead of 2 (2) makes the diffs in code review smaller and easier to read and review.

This judgement is rather based on a strong personal opinion (which I don't claim to be wrong, but also not as god-given) on what is one, and what are two changes in the code:

- If you consider adding an additional item to the end of the list to be one code change, I agree that a trailing comma makes sense

- On the other hand, it is also a sensible judgment to consider this to be a code change of two lines:

1. an item (say 'peach') is added to the end of the list

2. 'orange' has been turned from the last element of the list to a non-last element of the list

If you are a proponent of the second interpretation, the version that you consider to be non-advantageous is the one that does make sense.

dghf 4 days ago | parent | next [-]

> 2. 'orange' has been turned from the last element of the list to a non-last element of the list

Then why not consider it four changes?

3. 'banana' has been turned from the last-but-one element of the list to the last-but-two element of the list

4. 'apple' has been turned from the last-but-two element of the list to the last-but-three element of the list

justincredible 3 days ago | parent [-]

[dead]

Skeime 4 days ago | parent | prev | next [-]

But the second interpretation only makes sense if the last item somehow deserves special treatment (over, say, the second-to-last item). Otherwise, you should similarly argue that the previous second-to-last item should also show up in the changes as it has now turned into the third-to-last item. (So maybe every item in the list should be preceded by as many spaces as are items before it and succeeded by as many commas as are items following it. Then, every change to the list will be a diff of the entire list.)

    first item,,,
     second item,,
      third item,
       fourth item
In my experience, special treatment for the last item is rarely warranted, so a trailing comma is a good default. If you want the last item to be special, put a comment on that line, saying that it should remain last. (Or better yet, find a better representation of your data that does not require this at all.)
aleph_minus_one 3 days ago | parent [-]

> But the second interpretation only makes sense if the last item somehow deserves special treatment (over, say, the second-to-last item).

There do exist reasons why this can make sense:

- In an Algebraic Data Type implementation of a non-empty list, the last symbol is a different type constructor than the one to append an item to the front of an existing non-empty list (similarly how for an Algebraic Data Type implementation of an arbitrary list, the type constructor for an initial empty list is "special").

- In a single-linked list implementation, sometimes (depending on the implementation) the terminal element of the list is handled differently.

---

By the way: at work, because adding parameters at the beginning of a (parameter) list of a function is "special" (because in the code for many functions the first parameters serve a very special purpose), but adding some additional parameter at the end is not, we commonly use parameter lists formatted like

    'foo'
  , 'bar1'
  , 'bar2'
  , 'blub'
4 days ago | parent | prev [-]
[deleted]
hananova 4 days ago | parent | prev | next [-]

Meanwhile, I know and understand the reasons for trailing commas, but I find them incredibly ugly so I always strip them out.

sarchertech 4 days ago | parent [-]

Can’t strip them out if the compiler requires them.

huflungdung 4 days ago | parent | prev [-]

That isn’t ocd.