# android

Hadi Tok

01/30/2019, 8:12 AM
I saw this on reddit. I didn’t know kotlinx synthetic is no longer recommended practice. Does anyone know why it is no longer recomended?
🤔 4
👎 1
🧐 1


01/30/2019, 8:28 AM
That was a selling point for jumping to Kotlin a few months ago. Is this official? FindviewById was never actually used anyway,.. usually libraries did the job
Probably it’s just a coding practice for the sample code I guess


01/30/2019, 8:43 AM
Ok this is actually a relief, I was thinking I was the only one having issue with that
when i started with kotlin and synthetics I have bunch of issues with that. Problem is you can only use them AFTER
, and the references you get are actually nullable (escaping the type system of kotlin). This happened to me especially when you need a ref to one view in a onScrollChange-listener of some sort (that you set up in onCreateView() ). Depending on device and use case, you may have a nullpointer or not (not even deterministic 😕 )


01/30/2019, 8:50 AM
you scared the shit out of me, guys) Maybe they need different requirements for their libs, but "not recommend practice" is a bit of a stretch for this PR. @Hadi Tok Why would you word your question like they officially against it? Seems like a clickbait.
P.S. never had issues with synthetics. They are awesome. Plus
👍 1

Hadi Tok

01/30/2019, 8:54 AM
sorry I was being sarcastic.
👍 1


01/30/2019, 8:55 AM
I had issues with it too but they were minor and once you get how to work with them, It is great.


01/30/2019, 9:04 AM
I don’t think they can stay as they are. Synthetic return non nullable types while actually, in some cases they are nullable.


01/30/2019, 9:15 AM
Are those issues tackled with findviewbyid or butterknife, dagger etc?
I tend to use lateinit with non nullable type for view elements anyway. I’m not sure if its
the best practice, but it makes the code cleaner


01/30/2019, 2:30 PM
The conversation around this PR on reddit mentioned that they don’t cache when used in viewholderes unless you do a little extra work and it’s not beginner-friendly.

Allan Wang

01/30/2019, 5:33 PM
Link to the reddit post for those who are interested: Modularity seemed to be a big topic as well since you can’t use synthetics for view in a separate module
👍 1


01/31/2019, 12:17 AM
This is just an internal note for Google’s project where they are most likely to use their own horrible stuff, like LiveData, DataBinding etc.
It doesn’t really tell the community not to use synthetics, they are pretty much beware of saying thinks like recommended practice out loud.