-
Notifications
You must be signed in to change notification settings - Fork 976
Added ConfigRenderOptions entry for value sorting in objects. #138
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
Conversation
Hi @fnuecke, Thank you for your contribution! We really value the time you've taken to put this together. Before we proceed with reviewing this pull request, please sign the Typesafe Contributors License Agreement: |
Signed. |
quick thoughts - 1) we should probably ensure the sort is locale-independent (Id have to research how) 2) sort can certainly change meaning in some cases; we will have to be careful about which those are. but since we don't preserve any defined order at all right now maybe we are good. 3) does this have to be a render option or maybe we just always do it? if we output in undefined order now then it doesn't seem to lose anything to always sort. there's some other old conversation maybe on a bug or PR about using LinkedHashMap to always preserve order and I might like to find that to refresh memory on whether it interacts with this. |
From the documentation of
Retaining the original order of the read config would be very much preferable to this approach, of course. I'll just be using this as a... workaround until that gets implemented :-) |
The complicated situation (that makes retaining order kind of hard) is when there are merges; but those don't happen for SimpleConfigObject, only for ConfigDelayedMerge I guess, so changing SimpleConfigObject is safe and easy. Reading the docs I agree that String.compareTo is good. If you're amenable I'd like to make this the hardcoded behavior and not a render option, because I don't see why someone would want random rather than sorted. Care to update the patch so it just adds the sorting and not an option? Preserving order might be nice (it just means switching to LinkedHashMap and then adding tests and ensuring we never reverse the list in our algorithms I guess), but it does seem like an empty gesture (and perhaps pointless extra cpu/memory) without also preserving comments and whitespace and generally "supporting" round trip load/save - which would be a lot of work. So I like your solution to just sort for now, at least it makes things a little more deterministic. Thanks for messing with this. |
Done! Just to clarify, |
Added ConfigRenderOptions entry for value sorting in objects.
Thanks! |
When enabled, this gives a more deterministic output by sorting the keys of config objects before writing them (handled in
SimpleConfigObject
, not sure if/how this might apply inConfigDelayedMerge
?).This is very useful in case the generated config file is intended to be hand-edited, since settings will always be at the same place in the config.