MR3Y
11/08/2022, 1:32 PMreturn try {
// ...
} catch (e: Exception) {
handleError(e)
}
in some classes that have similar purposes. so, I decided to extract that block into a separate function called something like runCatching
return runCatching { ... }
but the problem is that it would be easily confused with the standard kotlin.runCatching
, and I'm not using kotlin.Result
either. so, I want a good name for that function but I can't think of any name other than runCatching
. Any better ideas?Kevin Del Castillo
11/08/2022, 1:33 PMrunHandlingError
?Rob Elliot
11/08/2022, 1:36 PMreturn withErrorHandling { ... }
MR3Y
11/08/2022, 1:37 PMrunCatching
because it would eliminate confusion.MR3Y
11/08/2022, 1:39 PMrun
MR3Y
11/08/2022, 1:40 PMrun
prefixed one because it has more of a semantic meaning of what I'm doing inside those lambdasRob Elliot
11/08/2022, 1:40 PMrun
prefixed methods, but perhaps because of the semantics of java.lang.Runnable
I always expect run
to mean something that returns Unit
.Klitos Kyriacou
11/08/2022, 2:32 PMrun
that returns Unit
is one that takes no parameters. In contrast to Runnable.run()
, Kotlin has two commonly used versions of run
in its own stdlib, both of which return the result of a given block. So I think it's idiomatic to expect run
to return something. On the other hand, I would prefer your withErrorHandling
suggestion. In Kotlin, with
is also a function that returns the result of a given block. Just like run
. So there's no reason for the OP to prefer a function prefixed with run
instead of with
.Rob Elliot
11/08/2022, 2:33 PMKevin Del Castillo
11/08/2022, 2:33 PMrunWithErrorHandling
then (?) 😆 KRuckus
11/08/2022, 3:13 PMhandleError
, I would use the same name.
return handleError { ... }
Not sure if that's particularly idiomatic, but it's what makes sense to me.MR3Y
11/08/2022, 3:36 PMMR3Y
11/08/2022, 3:40 PMwith
would also align with kotlin.with
that shares (to some extent) the same purpose of the function I'm trying to create, so, I think this is the best option hereEl Anthony
11/09/2022, 11:24 AMrocketraman
11/09/2022, 1:51 PMsafe
for this pattern.