micrometer icon indicating copy to clipboard operation
micrometer copied to clipboard

Add KeyValue.of() variants for none values

Open izeye opened this issue 2 years ago • 1 comments

This PR adds KeyValue.of() variants for "none" values for convenience.

See gh-3458

izeye avatar Oct 18 '22 15:10 izeye

:warning: 10 God Classes were detected by Lift in this project. Visit the Lift web console for more details.

sonatype-lift[bot] avatar Oct 18 '22 15:10 sonatype-lift[bot]

We discussed this internally some time ago. My feeling is that it is a bit too context-dependent for us to provide something in the API like this. For example, when it comes to an exception tag, the absent value makes sense as none if we know there was no exception, but in other cases the absent value is better represented as unknown. For that reason, I would rather we don't add these methods. Also we haven't seen a request from a user related to this yet. @jonatan-ivanov @marcingrzejszczak thoughts?

shakuzen avatar Jan 25 '23 06:01 shakuzen

I think if somebody does something like this, there will be a check if a none or non-none 😃 value is needed. I think in these cases it is better to use the NONE constant (more explicit/readable). e.g.:

.lowCardinalityKeyvalue(KeyValue.of("something", something != null ? something : NONE));

or

String value = something != null ? something : NONE;
.lowCardinalityKeyvalue(KeyValue.of("something", value));

vs.

.lowCardinalityKeyvalue(something != null ? KeyValue.of("something", something) : KeyValue.of("something"));

or

KeyValue keyValue = something != null ? KeyValue.of("something", something) : KeyValue.of("something");
.lowCardinalityKeyvalue(keyValue);

jonatan-ivanov avatar Jan 26 '23 22:01 jonatan-ivanov

I think that makes sense. Though if we wanted to take it a step further, we could accept null values and convert to the none constant. I think that's a bigger change and not everyone would be happy with the behavior either. I'll close this for now and we can reopen or reconsider this kind of API if we get additional feedback.

shakuzen avatar Jan 27 '23 02:01 shakuzen