how can I fix this? :smile: <https://pastebin.com/...
# codereview
o
how can I fix this? 😄 https://pastebin.com/9iLG5E6B
a
@oday what do you mean by fix? make it more idiomatic?
o
One minute
Ok @Andreas Sinz well yes I know there's no glaring issue in the code and it isn't wrong to do this, but it seems so exhaustive, and imagine like this method there are many others, each handling tracking
And it just looks ugly
For example is there a way that I can look for an object's properties and find a property by a string?
If this property's name is "country_code"
Im not sure really how to improve on this but it's definitely too exhaustive looking and ugly
a
you could look for properties based by their name with reflection, but it looks like you aren't even using any properties of lets say
mpProperties
o
it’s the issue that the name of the property matches the name of the field i will send to mixpanel
yea…not much value added if there’s no loop, and you can’t loop if you’re only selecting a limited number of properties from the object
i’ll come back with a clearer problem
a
you can make the code cleaner with
with(mpProperties) { ... }
g
For example is there a way that I can look for an object’s properties and find a property by a string?
Only using reflection or code generation. Also kotlin.serialization can do this for you
So this is only for fully automatic solution
but you can improve your code just using apply on
mpProperties
or even writing some dsl like:
Copy code
mpProperties.putAll {
   "car_id" to listing.id
}
o
I see
ok, yea either full automatic or not, i noticed
i will ask more about this DSL if you dont mind, later 🙂
I actually asked this in #getting-started but I don’t think it falls into what they can help with how can I print the name of any variable?
var1.javaClass.getFieldByName(String)
is what im using right now but im not sure what to feed
getFieldByName
im in the process of fixing what you suggested the other day
g
Do you want to use reflections for that?
Not sure what exactly do.ypu want to achive, because there are many different ways to implement such mapping with reflections