Repository navigation
Named arguments #57
stvowi
started this conversation in
Ideas / Feature requests
Replies: 2 comments 1 reply
|
That is my comment to the roadmap item: named arguments - set argument(s) by name, including the Nth one without the preceding args. Open question: must the skipped args have declared defaults, or are they zeroed? Needs discussion. I hope you meaned named argumends by functions/ procedures. |
0 replies
|
Named arguments are on the roadmap (#3), so this will land at some point. I am not giving a timeline. Yes, functions and procedures. Your open question is exactly the part I am still weighing. Two ways to go:
The first is more permissive, the second keeps a missing argument an error instead of silently handing the routine a zero. Not decided yet. The rest matches what I would expect for Pascal too: named arguments after positional ones, no duplicates. |
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
How about it to implement named paramerters for functions / procedures such like in PHP8?
Named parameters in PHP allow you to pass arguments to a function based on the parameter names rather than their positions. This feature was introduced in PHP 8.0 and helps make function calls more readable and less error-prone.
In this example, the create_anchor function creates an anchor () element. By using named parameters, you can specify only the arguments you want to change, making the code more readable.
Important Considerations
Skipping Default Arguments
Named parameters allow you to skip default arguments. For instance, if you only want to change the target parameter, you don't need to specify the default values for href and title.
Mixing Named and Positional Arguments
You can mix named and positional arguments in a function call. However, named arguments must come after positional arguments.
Error Handling
Passing the same parameter multiple times or placing named arguments before positional arguments will result in an error.
Named parameters enhance code readability and reduce the likelihood of errors by allowing you to specify only the necessary arguments.
@see also: Php Functions
All reactions