You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Make the syntax for creating event instances more clear, readable, and consistent with the syntax for struct creation by leveraging keyword arguments.
Motivation
Structs have been updated to be constructed by kwargs ( #2381 ). This new syntax makes struct construction more convenient than the previous implementation.
Event creation could benefit from this same syntax change, not only improving the existing event syntax, but also making it consistent with struct creation, which lowers the mental overhead programmers need to work with when writing Vyper.
Right now, users have to remember the two different, but similar syntaxes for creating events and for creating structs. The syntax for creating structs is more readable, clear, and explicit. So we should update events to use the same syntax as structs.
Specification
There are no semantic changes involved in this VIP.
Curent Syntax
The current syntax around events uses positional arguments as follows
# event definitionevent EntryCreated:
id: indexed(uint256)
round_id: indexed(uint256)
owner: indexed(address)
amount: uint256# event construction
log EntryCreated(foo, bar, msg.sender, 1000)
Proposed Syntax
We propose changing this to the following syntax which uses keyword arguments
# Creating a Struct
entry: Entry =Entry(id=foo, round_id=bar, owner=msg.sender, amount=10000)
# Logging an Event
log EntryCreated(foo, bar, msg.sender, 10000)
Proposed Syntax
# Creating a Struct
entry: Entry =Entry(id=foo, round_id=bar, owner=msg.sender, amount=10000)
# Logging an Event
log EntryCreated(id=foo, round_id=bar, owner=msg.sender, amount=10000)
Backwards Compatibility
Similarly to the Struct Kwarg VIP, we can support both syntax options via an AST transformation and warn the user about the change. After a few releases, the previous syntax can be dropped, as it is better to have one syntax for this in the long run.
Simple Summary
Make the syntax for creating event instances more clear, readable, and consistent with the syntax for struct creation by leveraging keyword arguments.
Motivation
Structs have been updated to be constructed by kwargs ( #2381 ). This new syntax makes struct construction more convenient than the previous implementation.
Event creation could benefit from this same syntax change, not only improving the existing event syntax, but also making it consistent with struct creation, which lowers the mental overhead programmers need to work with when writing Vyper.
Right now, users have to remember the two different, but similar syntaxes for creating events and for creating structs. The syntax for creating structs is more readable, clear, and explicit. So we should update events to use the same syntax as structs.
Specification
There are no semantic changes involved in this VIP.
Curent Syntax
The current syntax around events uses positional arguments as follows
Proposed Syntax
We propose changing this to the following syntax which uses keyword arguments
Comparison with Struct Syntax
The proposed kwarg is more consistent with the current syntax around structs, and the benefits of the change are very apparent when seen side by side
Given the following struct and event definitions:
We construct these as follows:
Existing Syntax
Proposed Syntax
Backwards Compatibility
Similarly to the Struct Kwarg VIP, we can support both syntax options via an AST transformation and warn the user about the change. After a few releases, the previous syntax can be dropped, as it is better to have one syntax for this in the long run.
Dependencies
N/A
References
#2381
#3777
Copyright
Copyright and related rights waived via CC0
The text was updated successfully, but these errors were encountered: