-
-
Notifications
You must be signed in to change notification settings - Fork 99
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
Don't print struct fields with zero values by default #30
Don't print struct fields with zero values by default #30
Conversation
We're trying to reduce the configuration variables for simplicity. On the other hand, we do not want breaking changes if possible. First of all, you did not describe why. Could you describe on what kind of situations this behavior is beneficial? (I mean, please provide example outputs with "before" and "after" which are improved by this feature.) |
Sure. There are two cases, when it's helpful for us:
Yes, it silently introduces changed behaviour. Another good idea is that it should be convenient to configure the pp/printer in one line, e. g.: pp.Printer().Indent(4).Emitempty().Println(value) But it's topic for another discussion. ExampleBefore: // pp.PrintZeroStructFields(true)
OutDate: &customtime.CustomTime{
Time: pp.StrToTime("2019-05-06T00:00:00Z"),
XXX_NoUnkeyedLiteral: struct {}{},
XXX_unrecognized: []uint8{},
XXX_sizecache: 0,
},
InDate: &customtime.CustomTime{
Time: pp.StrToTime("0001-01-01T00:00:00Z"),
XXX_NoUnkeyedLiteral: struct {}{},
XXX_unrecognized: []uint8{},
XXX_sizecache: 0,
}, After: OutDate: &customtime.CustomTime{
Time: pp.StrToTime("2019-05-06T00:00:00Z"),
},
InDate: &customtime.CustomTime{
} Pay attention:
|
I'm okay for accepting https://github.com/k0kubun/pp/issues/22 as your example makes sense (thanks!). But,
This was not before, right? And I can see you're modifying at least 3 things (omitempty, indent, StrToTime). "It's valid go code", true, and a motivation to make it valid code is understandable, but at the same time |
I would like to have a separate issue for this too but in this case it's related to this feature as it requires a configuration. Maybe we need to solve that first to have this feature. I'm fine with the method chain but on the other hand I feel it's more Java-ish. How about this? // one line (maybe not possible with gofmt?)
pp.Printer{ Indent: 4, Emitempty: true }.Println(value)
// another use case
p := pp.Printer{ Indent: 4, Emitempty: true }
p.Println(value) Anyway both ideas do not affect things globally and I feel they're better than this PR's current strategy. |
5ca064b
to
ba880d8
Compare
Moved the code to https://github.com/k0kubun/pp/pull/31/files |
Well, it's a good idea, but it requires much more efforts than only Omitempty implementation: I suggest here to solve omitempty implementation. Then we can discuss the new interface. Better in chat. |
Thanks, appreciated.
Sorry, asynchronously responding to your comments is the maximum effort which I can take while I'm busy these days. Though thank you for your sincere attitude for making a good decision.
Completely understandable. But at the same time what I do not want here are:
Currently this PR satisfies 1 but violates 2 (it's my fault to leave such things now), and it can't be merged anyways. So, how about separating PR for indent as well and discuss interface of that there first? After having the interface, we can easily satisfy 1 and 2 at the same time easily for this. |
Closing due to inactivity and a conflict with #33. |
No description provided.