Feature #20914
closedConstructor Parameter Shortcuts
Description
Constructor Parameter Shortcuts¶
I propose adding a new syntax to simplify the constructor definition in the classes. Defining a constructor often involves repetitive assignments of parameters to instance variables. This pattern is verbose and can easily become cumbersome, especially in classes with many instance variables. The proposed syntax allows instance variables to be automatically assigned from constructor arguments, improving code clarity and brevity.
Basic Usage:
-
Current:
-
Proposed:
Named Parameters:
-
Current:
-
Proposed:
Mixing Named and Positional Parameters:
-
Current:
-
Proposed:
Updated by mame (Yusuke Endoh) over 1 year ago
- Related to Feature #5825: Sweet instance var assignment in the object initializer added
Updated by nobu (Nobuyoshi Nakada) over 1 year ago
Updated by artemb (Artem Borodkin) over 1 year ago
· Edited
You’re absolutely right; this part does seem ambiguous. I initially added it as an empty block, modeled after the short syntax, like this:
What do you think about this option:
The nil is also possible
Updated by mame (Yusuke Endoh) over 1 year ago
What do you think about this option:
Then this proposal is almost the same as #5825.
Updated by artemb (Artem Borodkin) over 1 year ago
Thank you! This appears to be literally the same proposal, so it can be closed.
I will review #5825 and follow for updates.
Updated by mame (Yusuke Endoh) over 1 year ago
- Status changed from Open to Closed