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

Change multiple value parameter recommendation #177

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

runejuhl
Copy link
Contributor

This changes the recommendation for how to handle multiple value parameters to the following:

If you can supply multiple values for an attribute it's common practice to
enforce the datatype as an array of values, even if the default is a single
item. This cuts down on code and remove some edge cases. An example for string
is Array[String[1]] instead of Variant[String[1],Array[String[1]]].

Note that previously the recommendation was to have a Variant type, but this
causes problems with values that contain Arrays, e.g. Variant[Tuple[String, Array], Array[Tuple[String, Array]]] (which would unintentionally flatten the
array inside the tuple).

I know this is a personal preference, and I wouldn't be surprised if I'm a small minority, but I'm open to any arguments for/against this.

@alexjfisher alexjfisher changed the title Change multiple valure parameter recommendation Change multiple value parameter recommendation Mar 12, 2019
@runejuhl runejuhl force-pushed the array-default-values branch 2 times, most recently from 340b63b to 7e4662d Compare March 12, 2019 12:17
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.

I agree with this recommendation. I never liked the x or list of x convention that appears to be common in Ruby. The code (either Puppet or its templates) also becomes easier when you only allow arrays.

I'm not so sure about the 80 column change. With markdown I'm also fine with long lines, but I'd say at least 100 characters is a lot more flexible, especially when you have URLs in there.

@alexjfisher
Copy link
Member

@ekohl It's often to preserve backwards compatibility when adding data types to an existing module.

At the very least we need to warn about using flatten with more complicated examples.

@runejuhl
Copy link
Contributor Author

I'm not so sure about the 80 column change. With markdown I'm also fine with long lines, but I'd say at least 100 characters is a lot more flexible, especially when you have URLs in there.

I'm fine with whatever, I just picked 80 chars because parts of the document was already wrapped to 80 chars.

@baurmatt
Copy link
Contributor

Actually I like the existing recommendation as its easier for Hiera users, though I don't like that fact that a parameter can be two (or even more oO) data types.

module::parameter: foo

vs.

module::parameter:
  - foo

Regarding the column length change: I think 80 is way to short, 200 might be better. Personally I prefer to ignore this linting warning. However we decide, can we please do that change in a separate PR? It's basically impossible to read the current git diff.

@runejuhl
Copy link
Contributor Author

@baurmatt that's why I made two commits 😉
Here's the diff for the meat of the PR: 7e4662d

@ekohl
Copy link
Member

ekohl commented Mar 12, 2019

@ekohl It's often to preserve backwards compatibility when adding data types to an existing module.

That's a fair distinction.

@baurmatt
Copy link
Contributor

@runejuhl Ups, missed that 🙈 Sorry!

@runejuhl
Copy link
Contributor Author

@ekohl It's often to preserve backwards compatibility when adding data types to an existing module.

That's a fair distinction.

I wouldn't see this recommendation as changing that; that's still possible and likely the easiest way to add types to old modules. I still think the recommendation is worthy, though.

As long as these guidelines aren't strictly enforced anyway I don't see a problem in changing the recommendation, and I don't imagine the guidelines will be strictly enforced anytime soon... (which I personally wouldn't want anyway)

@bastelfreak
Copy link
Member

@binford2k what do you think about this / is there an official recommendation?

@juniorsysadmin
Copy link
Member

My preference is for one datatype, not a Variant, and making it a breaking change.

Copy link
Member

@binford2k binford2k left a comment

Choose a reason for hiding this comment

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

I don't know that there's an actual recommendation one way or the other. I personally like the one or many ability, but I dislike having to do the casting myself. Since Puppet does not have a way to automatically cast the parameter, and since this is a recommendation, not a requirement then I'm ok with it.

I do suggest simplifying the wording that I noted though.

is `Array[String[1]]` instead of `Variant[String[1],Array[String[1]]]`.

Note that previously the recommendation was to have a `Variant` type, but this
causes problems with values that contain Arrays, e.g. `Variant[Tuple[String,
Copy link
Member

Choose a reason for hiding this comment

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

imo, the complexity of this example takes away from its readability. I think I'd word it more like this and leave the rest as a thought exercise for the reader if they care to do so.

Note that previously the recommendation was to use a Variant type, but this added excessive complexity.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

...forgot about this one. I've updated the PR with your text.

@runejuhl runejuhl force-pushed the array-default-values branch from 7e4662d to 4adff96 Compare July 9, 2019 10:22
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.

7 participants