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

Named argument support #6969

Open
jeskew opened this issue May 27, 2022 · 1 comment
Open

Named argument support #6969

jeskew opened this issue May 27, 2022 · 1 comment
Labels
enhancement New feature or request Needs: Upvote This issue requires more votes to be considered

Comments

@jeskew
Copy link
Contributor

jeskew commented May 27, 2022

Is your feature request related to a problem? Please describe.
Based on a comment from the newline sensitivity issue:

When passing a number of arguments to a function, it can be unclear which argument corresponds to which parameter. Readability hurdles are compounded when all function arguments appear on the same line and/or when complex expressions are used for one or more arguments.

Due to line size concerns, this feature should not be implemented until newlines are allowed as syntax trivia in function expressions.

Describe the solution you'd like
Readability for long function expressions may be improved by allowing callers to label their arguments (i.e., something like C#'s named arguments or Python's keyword arguments). I expect that Bicep functions' frequent use of overloads and varargs would make this feature fairly complex to implement.

Strawman syntax
An initial implementation could be closely patterned on C#'s named arguments.

  • Arguments MAY be prefixed with optional label of the parameter name to which the argument corresponds.
  • All unnamed arguments MUST precede named arguments in the function expression.
  • Named arguments MAY be provided in any order.

For a function with a fixed number of parameters, such as endsWith, named arguments would allow callers to provide arguments out of order. The following three expressions would be equivalent:

endsWith('abcdef', 'ef')
endsWith(
   stringToSearch: 'abcdef',
   stringToFind: 'ef'
)
endsWith(
   stringToFind: 'ef',
   stringToSearch: 'abcdef'
)

Named arguments may improve readability when a less-often used optional parameter is supplied, e.g.:

var utf16BEText = loadTextContent(encoding: 'utf-16BE',
    filePath: '/path/to/file.ext')

Like in C#, named variable length arguments would need to be supplied as an array:

var otherRgBlobContainer = resourceId(
    resourceType: 'Microsoft.Storage/storageAccounts/blobServices/containers',
    resourceName: ['<account name>', 'default', '<container name>'],
    resourceGroupName: 'myOtherResourceGroup'
)

ARM JSON compiled from Bicep with named arguments would use unnamed, positional arguments in the correct order. No changes would be required in the ARM deployment engine.

@jeskew jeskew added the enhancement New feature or request label May 27, 2022
@ghost ghost added the Needs: Triage 🔍 label May 27, 2022
@alex-frankel alex-frankel added Needs: Author Feedback Awaiting feedback from the author of the issue Needs: Upvote This issue requires more votes to be considered and removed Needs: Triage 🔍 labels Jun 1, 2022
@ghost
Copy link

ghost commented May 19, 2023

Hi jeskew, this issue has been marked as stale because it was labeled as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment. Thanks for contributing to bicep! 😄 🦾

@ghost ghost closed this as completed May 22, 2023
@jeskew jeskew reopened this May 29, 2023
@jeskew jeskew removed the Needs: Author Feedback Awaiting feedback from the author of the issue label May 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request Needs: Upvote This issue requires more votes to be considered
Projects
Status: Todo
Development

No branches or pull requests

2 participants