ursus
06/23/2026, 9:30 PMclass ImageRecognizerImpl : ImageRecognizer {
override suspend fun recognize(image: Image): RecogniseResult {
val byte = image.data[0].toInt()
return RecogniseResult { <------------------
category = if (byte == 0) 0 else 1
}
}
}
Why not the usual constructor shape?Manuel Lilienberg
06/24/2026, 6:45 AMAlexander Sysoev
06/24/2026, 9:07 PMursus
06/24/2026, 9:17 PMAlexander Sysoev
06/24/2026, 9:30 PMint32 a = 1 and int32 b = 2, and then decided to add int32 c = 3 in between first two for any reason - your existing code will have a silent logic error without named parameter enforcement ( call like MyMessage(1,2) will treat 2 as b fir the old version and as c for the new one without compilation or runtime error.
Other reason for dsl, and that protobuf has a notion of explicit presence, which is different from default values. You can't express this with a Kotlin constructor, default value 1 is not distinguishable from the explicitly set value 1 without a custom setter in a DSLursus
06/24/2026, 9:37 PMAlexander Sysoev
06/24/2026, 9:39 PMursus
06/24/2026, 9:45 PM@SerialName("1") a: Int in json deserialization
Wire seems to have ctors WhiteboardUpdate(update_points = UpdatePoints(points)
https://github.com/square/wire/blob/master/samples/wire-grpc-sample/server/src/main/java/com/squareup/wire/whiteboard/WhiteboardGrpcAction.ktAlexander Sysoev
06/25/2026, 4:54 AMursus
06/25/2026, 1:01 PMAlexander Sysoev
06/25/2026, 1:05 PMursus
06/25/2026, 1:23 PMAlexander Sysoev
06/25/2026, 2:04 PMclass MyMessage(val a: Int = 0)
// In protobuf this
MyMessage(a = 0)
// is not the same as this
MyMessage()
// but Kotlin constructors can't express this, DSLs can using custom settersCLOVIS
06/25/2026, 3:21 PMnull and an empty list.CLOVIS
06/25/2026, 3:23 PMAlexander Sysoev
06/25/2026, 3:25 PMAlexander Sysoev
06/25/2026, 3:26 PMAlexander Sysoev
06/25/2026, 3:28 PMIt's a pain point that proto3 doesn't differentiate betweenThat's because they don't have nulls, and they think explicit presense is a better notion than nullsand an empty list.null
Alexander Sysoev
06/25/2026, 3:29 PMCLOVIS
06/25/2026, 3:30 PMrepository.findUsers(
ids = request.ids.takeIf { request.hasIds() }
)
because we constantly forget it and it leads to bugs. I haven't tested krpc yet though so maybe that's less of an issue here
(because in the DB, null means 'no criteria, return all data' vs emptyList() which means 'one of none, return no data', which leads to security issues where users have access to information they shouldn't)Alexander Sysoev
06/25/2026, 3:32 PMorEmpty() then?CLOVIS
06/25/2026, 3:33 PMAlexander Sysoev
06/25/2026, 3:33 PMAlexander Sysoev
06/25/2026, 3:35 PMAlexander Sysoev
06/25/2026, 3:35 PMCLOVIS
06/25/2026, 3:35 PMAlexander Sysoev
06/25/2026, 3:35 PMAlexander Sysoev
06/25/2026, 3:36 PMCLOVIS
06/25/2026, 3:37 PMnull or emptyList() , because we can't have a value that could be either.Alexander Sysoev
06/25/2026, 3:38 PMAlexander Sysoev
06/25/2026, 3:39 PMCLOVIS
06/25/2026, 3:39 PMnullCLOVIS
06/25/2026, 3:41 PMAlexander Sysoev
06/25/2026, 3:42 PM