Skip to content
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

RFC Generate a prettyprinter for structs #203

Open
dantswain opened this issue Jan 27, 2017 · 1 comment
Open

RFC Generate a prettyprinter for structs #203

dantswain opened this issue Jan 27, 2017 · 1 comment

Comments

@dantswain
Copy link
Collaborator

This is a little off-the-walll, but in the Ruby thrift lib, enum values get printed out as their name, which can be pretty nice for debugging purposes. We could theoretically generate a defimpl Inspect for structs and have it do this. For the most part I think this would just hijack the normal struct implementation but it could replace the enum entries with something like user_status: 1 (UserStatus.active).

OTOH it could be not worth the complexity. Something opt-in might be a compromise? I.e., the generated module could include a prettyprint function or something and then we provide docs showing how you could roll your own defimpl around that.

@jparise
Copy link
Collaborator

jparise commented Sep 11, 2017

I like this idea and spent a little time looking into a possible implementation. It unfortunately doesn't appear to be an easy thing to build, however. Because structs are just maps, the only want to determine which fields contain enums is based on matching against their names, and hooking into the Inspect protocol at that level appears to involve re-implementing the full struct/map Inspect.inspect/2 code path.

I think that could be done somewhat generically and reused for each of our generated structs, but it's still a good amount of complexity.

I think that work is roughly equivalent to rolling our own pretty printing function, so I'm not sure there's a benefit to not using Inspect here, unless the algebraic nature of Inspect gets in our way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants