Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style guide: Stop aligning parameters at = and/or $ #322

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

bastelfreak
Copy link
Member

I think the 'old' style of aligning parameter is quite bad and we should stop doing this.

@bastelfreak bastelfreak self-assigned this Aug 31, 2023
Copy link
Member

@ekohl ekohl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 for this, though I will note that we shouldn't make it mandatory to refactor a whole module for this when a single parameter is added. Consistency within the file is probably more important.

@bastelfreak
Copy link
Member Author

Adding a new paramter should not cause a refactor. But I think we should enforce the new style for new parameters and ignore the existing style in a file. What do you think about that?

@jstraw
Copy link
Contributor

jstraw commented Aug 31, 2023

If we are changing this for a class/define variable list, are we planning to change this for a resource definition's => which has the same "feature." I agree with the change, but I might agree less with the resource definition change (because the => alignment makes it easier to read)

@bastelfreak
Copy link
Member Author

this is only about the parameter list in classes/defined resources. not about resource declaration. We've a puppet-lint plugin that enforces the alignment there and I think we should keep it. The diff for resources is usually way way smaller.

@jms1voalte
Copy link

Personally, I find it easier to read code when things are all vertically aligned. Also git diff does have a -w option to not show lines where the only change is whitespace, and some git web interfaces have a checkbox to do the same thing. (For me this is true of almost every language, not just Puppet/Ruby.)

As long as there's a way to tell the linter to accept the old format (or to ignore whitespace between tokens entirely), I have no objections.

@spotter-puppet
Copy link

There's a slight typo... "Sometimes were was an additional alignment". I believe this should be "Sometimes there was an additional alignment".

@zilchms
Copy link

zilchms commented Aug 31, 2023

I would agree that the downside of having to refactor when adding a parameter is not good. However I am not so sure about the longterm readability.
For long parameter lists I think the old style makes it a lot easier to search for a specific one (when ordered alphanummerically).
On short parameter lists the old style is very cumbersome and makes them less readable.
I think currently we dont order alphanummerically first, instead we order by required parameters and optional parameters (I think)?
In that case the old one doesnt really add much value in my opinion, so we could drop it.

@smortex
Copy link
Member

smortex commented Sep 1, 2023

Just like other people here, my preference go to aligned types / names / default value because it is ways more comfortable for me to work with these lines when items are vertically aligned.

For sure, rebasing commits that change types can be a PITA, but only when we change the column where alignment take place. When using a syntax that use tabs, it's easy to use say "2 tabs" in general and if a line overflow, just put a single space and not align this line; but because puppet files don't use tabs (and 2 spaces soft-tabs), when I have a little overflow I trend to "fix" it by re-aligning all members… leading to these conflicts. But I am ready to pay this rebase conflict risk when dealing with such changes 🤷.

Having a rule that says that we should align fields is probably an annoyance. Maybe we can just remove this line? If people have to deal with aligned fields and it's annoying, they can remove the extra spacing and be happy. If people have to deal with unaligned fields and it's annoying, they can add extra spacing and be happy. I don't think that happen so often that we will have to deal with issues where a module go back and forth from a form to the other; and since people trend to contribute to some modules and not all, the module they contribute to the most are likely to use the alignment that fit them best in the end?

@davidsandilands
Copy link
Member

I would still bias to the alignment of = making it easier to read for me but I feel the frustration it creates when a new parameter knocks everything about.

@bastelfreak
Copy link
Member Author

I would still bias to the alignment of = making it easier to read

I understand that. But should the parameters be readable? That's the whole purpose of the REFERENCE.md. Provide the readable list of all parameters, their datatypes and the default values.

@rwaffen
Copy link
Member

rwaffen commented Sep 4, 2023

I find it easier to read if I have some space between things, for syntax and code for itself it is not required i know, but to get an overview and read and compare things I very much like this alignment. It is not nice to rebase, but I think it is worth the work to keep things aligned to better understand/read/view them.

@tuxmea
Copy link
Member

tuxmea commented Sep 5, 2023

My preference:

  1. Ordering

First we have paramaters without defaults, odered alphabetical.
Next we have all parameters with defaults, ordered alphabetical.
If the module has more than one entry point (e.g. server and client) the parameters should be grouped and then ordered alphabetical.

  1. Alignment

All parameter groups (see above) should align at $ and =

@bugfood
Copy link

bugfood commented Sep 6, 2023

I do agree that alignment increases readability, but personally, I don't think it's worthwhile, given the documented annoyances for modification.

I stopped aligning parameter sections shortly after I started declaring the data types, since the lines were getting way too long.

The use of should indicates to me that this is a recommendation, not a requirement, so this doesn't seem like such a big deal either way.

@ekohl
Copy link
Member

ekohl commented Sep 6, 2023

Couldn't agree more with what @bugfood wrote. Data types made alignment impractical. For complex data types (or just long names) it breaks readability by making the lines so long that you can no longer easily see what the lines are. So you may mistake the data type from the line below with the default value from the line you're reading.

@rwaffen
Copy link
Member

rwaffen commented Sep 7, 2023

if data-types get to long, it breaks everything, right. but this is a sign for me to shorten this thing again by writing my own data-type. not really related, but a thing i do often when i stumble upon long data-types 😄

@ekohl
Copy link
Member

ekohl commented Sep 7, 2023

Also a fair point about custom data types, though if you introduce a custom data type and only use it once that's not a good experience for the module consumers. Perhaps a separate discussion.

I think @bugfood said it best: we have the word should. So that gives flexibility to who's making changes. What is important to me is that we're consistent. I guess there are 3 levels we can be consistent (and not at all):

  • organization (our entire GH namespace)
  • module
  • file
  • not at all

My suggestion is to keep it consistent at the file level. I love consistency, but I usually don't care beyond a single file.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.