Feature request: Named parameters for functions/user-defined functions
- Dominant language
- Bicep
- Stars
- 3.6k
- Forks
- 830
- Avg merge
- 1d 21m
- Merged PRs (30d)
- 79
Description
Hi Bicep team,
I would like to request an improvement/feature for functions/user-defined functions. Currently, it is not possible to use named parameters, which would significantly improve function readability.
Consider the example below. It defines a function that generates resource names based on the parameters provided:
```bicep
func funcGenerateResourceName(
BusinessUnit businessUnitType,
SystemName string,
Purpose string?,
EnvironmentName environmentType,
Abbreviation abbreviationType,
SequenceNumber string?
) string =>
```
Without named parameters, you must pass parameters in the exact order defined in the function parameter signature:
```bicep
funcGenerateResourceName(‘doe, ‘very’, 'important', 'dev', 'vnet', '01')
```
When reviewing code like this, it’s difficult to identify what each parameter represents. You can hover over the function to see the set of parameters, but this becomes chaotic especially when using user-defined types:
If named parameters were supported, the function call would be much more readable:
```bicep
funcGenerateResourceName(
BusinessUnit: ‘doe’,
SystemName: ‘very’,
Purpose: ‘important’,
EnvironmentName: ‘dev’,
Abbreviation: ‘vnet’,
SequenceNumber: ’01’
)
```
## Workaround
As a workaround, I use typed objects, which mimic named parameters:
```bicep
func funcGenerateResourceName(resourceInformation resourceNameType) string =>
type resourceNameType = {
BusinessUnit: businessUnitType
SystemName: string
Purpose: string?
EnvironmentName: environmentType
Abbreviation: abbreviationType
SequenceNumber: string?
}
```
The function can then be called like this:
```bicep
funcGenerateResourceName({
BusinessUnit: 'doe'
SystemName: 'very'
Purpose: 'important'
EnvironmentName: 'dev'
Abbreviation: 'vnet'
SequenceNumber: '01'
})
```
Contributor guide
Research direction
Start by comparing the current positional function-call behavior with the requested named-parameter examples and the typed-object workaround. Done means a settled syntax and semantics for named arguments in functions and user-defined functions, with corresponding validation and tests.
Written by the indexing model from the issue text.
Assessment
- Domain
- compilers
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100