-
Notifications
You must be signed in to change notification settings - Fork 23
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
FLIP 293: StructStringer interface #294
Conversation
[Just cross-referencing] There were some concerns raised before, over having a user-defined |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice! Adding a built-in interface, implementing it for built-in types that support it, and allowing Cadence developers to implement the interface for their types, makes a lot of sense 👍
|
||
### Alternatives Considered | ||
|
||
An alternative is to have `AnyStruct` itself implement a `toString` function. As a native function there is no longer any risk of malicious code and it still solves the first goal. Additionally, it still allows for more powerful string formatting. The downside of this approach is in limiting customizability for developers. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This might be infeasible, given that not all values of AnyStruct
are stringable.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍 from me
I had some concerns in the beginning but after thinking a bit more on it, this is great 👍
|
Co-authored-by: Bastian Müller <bastian@turbolent.com>
Yes it would be, this is the case in Swift with their CustomStringConvertible. |
That should not be necessary and would just complicate and slow down the functions, because they would all have to first call This is also uncommon in the standard library or in "user code" of other languages. For example, Go's standard library functions work with |
One thing I realized in the discussion above is that we should probably clarify what the result of the For example
It might be good to clarify this in the proposal and note that the purpose of the proposed stringer interface is the former, providing a "human-readable representation". I'm noting this, because currently we actually have the latter, the "debug representation", which makes sense for the When we're implementing this proposal we need to make sure to implement a new set of string functions and use it for the built-in types. Concretely, e.g. |
Co-authored-by: Bastian Müller <bastian@turbolent.com>
We discussed this FLIP in yesterdays working group call. Attendees liked the proposal and there were no concerns, so this FLIP is accepted 🎉 As always, thank you everyone for reviewing proposals and providing valuable feedback 🙏 |
Flip #293 working towards onflow/cadence#3579.