Colton Idle
06/10/2023, 7:01 PMclass SomeUtil {
fun findPercentage(x: Int, y: Int, z: Int)
but something like this
object SomeUtil {
fun findPercentage(x: Int, y: Int, z: Int)
is also convenient + less object allocation because I dont have to do SomeUtil() every time I want to use it.
I suppose another potential is creating an extension function, but in this case since I have three args... I don't think that'd work?
In this scenario would you do
1️⃣ Class
2️⃣ Object
3️⃣ Something elseJavier
06/10/2023, 7:20 PMPoisonedYouth
06/10/2023, 7:20 PMFrancesc
06/10/2023, 7:23 PMdata class MyClass(
val x: Int, /* consider better name */
val y: Int,
val z: Int,
)
then either create the percentage
as a property in the class if it's intrinsic to this object, or define an extension property on MyClass
otherwise
val MyClass.percentage: Int
get() = /* compute */
Youssef Shoaib [MOD]
06/10/2023, 7:31 PMephemient
06/10/2023, 9:11 PMColton Idle
06/11/2023, 2:08 PMMatteo Mirk
06/28/2023, 9:22 AMColton Idle
06/28/2023, 1:33 PMMatteo Mirk
06/28/2023, 1:34 PMPoisonedYouth
06/28/2023, 3:21 PMFrancesc
06/28/2023, 3:44 PMPoisonedYouth
06/28/2023, 3:51 PMephemient
06/28/2023, 5:39 PMFrancesc
06/28/2023, 5:43 PMephemient
06/28/2023, 5:49 PMnaturalOrder()
, etc. make more sense as a top-level function than belonging to Comparator
(to give an example from stdlib) and I think that can make sense for some of your own types tooFrancesc
06/28/2023, 5:52 PM