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

Stabilize EmptySerializersModule #1921

Merged
merged 3 commits into from
May 31, 2022
Merged

Stabilize EmptySerializersModule #1921

merged 3 commits into from
May 31, 2022

Conversation

qwwdfsad
Copy link
Collaborator

Fixes #1765

@qwwdfsad
Copy link
Collaborator Author

See also #1765 (comment)

This is a legit concern that this decision is slightly out of line with our general design. We can discuss and decide whether we want to disrupt API a bit, deprecate EmptySerializersModule with replacement to EmptySerializersModule()

@olme04
Copy link

olme04 commented Apr 29, 2022

But why EmptySerializersModule() ? :) why not just SerializersModule() ?
From user perspective it looks reasonable to treat SerializersModule { } (so no configuration provided, what is possible now) and SerializersModule() the same.

@sandwwraith
Copy link
Member

sandwwraith commented Apr 29, 2022

@olme04 It's like List(10) { i -> ... } constructor vs emptyList(). It clarifies the purpose. However, such logic hints that we should rename it to emptySerializersModule(), with small letter. WDYT, @qwwdfsad ?

@olme04
Copy link

olme04 commented Apr 29, 2022

then also SerializersModule {} should be renamed to buildSerializersModule { } as it's more like a buildList { } as there is already similar functions like serializersModuleOf already available like listOf :)
It's up to you to decide what code style is better here, but now all those builder functions have really different code styles

@qwwdfsad
Copy link
Collaborator Author

qwwdfsad commented May 23, 2022

It seems like the most optimal way here is to be consistent within the library itself and name it EmptySerializersModule() like every other factory-that-looks-like-a-constructor in kotlinx.serialization and other kotlinx.* libraries.

The standard library is a different beast with different sets of tradeoffs. It still carries the heavy influence of Java since its earlier versions and tries to be consistent with itself, even though as time passes, we (Kotlin libraries developers) find better ways to design and express things. E.g. we could've decided that EmptyList() is the way to go, but changing emptyList at the current scale is just doesn't worth it

@@ -80,29 +80,39 @@ class SerializationMethodInvocationOrderTest {

override fun <T : Any?> encodeSerializableValue(serializer: SerializationStrategy<T>, value: T) {
when (step) {
0, 3 -> { step++; serializer.serialize(this, value); return }
0, 3 -> {
step++; serializer.serialize(this, value); return
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want to make it multi-line, also split statements instead of using ;

If it's autoformatting, better to revert it

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

"Rename signature" for some reason apply formatting all over the place

@@ -18,6 +19,9 @@ import kotlin.reflect.*
* To enable runtime serializers resolution, one of the special annotations must be used on target types
* ([Polymorphic] or [Contextual]), and a serial module with serializers should be used during construction of [SerialFormat].
*
* Serializers module can be built with `SerializersModule {}` builder function.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably we need to do one or two things:

  • Optimize SerializersModule {} so it would return EmptySerializersModule when appropriate
  • Make a diagnostic that suggest replacing SerializersModule {} with EmptySerializersModule() as we have with Json

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I honestly do not see reasons to do so, this optimization doesn't carry any real value as well as the diagnostic.
Json is a different beast as it has a non-trivial initialization cost and also prevents any format-level caching.

@sandwwraith
Copy link
Member

@qwwdfsad We already has the same problem with mapSerialDescriptor vs PrimitiveSerialDescriptor

@qwwdfsad qwwdfsad merged commit 9e2e16e into dev May 31, 2022
@qwwdfsad qwwdfsad deleted the stabilize-empty-module branch May 31, 2022 22:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants