https://kotlinlang.org logo
c

caelum19

03/20/2020, 7:36 PM
Hey guys. Perhaps less so with Kotlin, but it seems most projects end up having some sort of "utils" file. Here are some I have for Compose. Are these useful? Or do they reflect solutions to anti-patterns elsewhere in my code? What utils do you have that others may find useful?
z

Zach Klippenstein (he/him) [MOD]

03/20/2020, 8:28 PM
I wrote something like
spacingArrangement
once, but it didn't seem to affect the size of the parent so stuff got clipped. Not sure if I was doing something else wrong too though. Your
toPx
seems like it could potentially have negative performance impact since it encourages making lots of subscriptions to the ambient, but I'd be curious to hear what the googlers think of it. Does seem like it would be handy
l

Leland Richardson [G]

03/20/2020, 8:31 PM
all of the subscriptions will end up on the same scope, but it does incur a bigger cost since you’re doing it once per call
i actually like the
toPx()
helper
the arrangement thing IMO is something that should be much easier to accomplish than it is
(or is it already and none of is in this thread know what it is yet?)
c

caelum19

03/20/2020, 8:35 PM
I haven't tried getting the parent resized with spacingArrangement actually, right now I'm using it to replicate Figma's auto-layout distancing. I have been thinking about making a Figma plugin to export designs as Compose because it seems like it wouldn't actually be that hard
a

Adam Powell

03/20/2020, 9:27 PM
The
toPx()
helper is the one I was going to discourage 😛 usually you should be in terms of Dp during composition, if you need Px there often enough to justify that extension we probably have bugs to file
c

caelum19

03/20/2020, 9:33 PM
That's a good point because the reason I made it was to fix a compilation error when I add the @Composable() annotation to the overriden arrange, though I would still at least make it a private function for its usage in spacingArrangement, unless there's a better way? 😄
l

Leland Richardson [G]

03/20/2020, 9:46 PM
yeah i guess we might want to avoid making toPx() easier because people shouldn’t need it… and if they do, it’s a signal that a different API should maybe change to use DP
c

caelum19

03/20/2020, 9:55 PM
Yeah. I'm curious about how you guys make the decisions about deciding what is healthy for the ecosystem longterm vs. what is useful now
I guess that choice is a lot easier before mainstream usage 😄
l

Leland Richardson [G]

03/20/2020, 9:58 PM
it’s easier to change things, it’s harder to know what the right change is
a

Adam Powell

03/20/2020, 10:07 PM
there's a lot of looking for x-y problems
c

caelum19

03/20/2020, 10:08 PM
x-y problems?
a

Adam Powell

03/20/2020, 10:08 PM
that site is a little terse/snarky about it, but the idea holds 🙂
c

caelum19

03/20/2020, 10:09 PM
haha yeah like mine 😄
a

Adam Powell

03/20/2020, 10:12 PM
there's also whole frameworks about how to evaluate API usability that are quite useful, things that talk about how many concepts you need to combine to accomplish a task, how directly the solution corresponds to the problem, consistent abstraction layering, things of that sort
l

Leland Richardson [G]

03/20/2020, 10:12 PM
hence my first response to many questions on here is “What are you trying to do?”
💯 1
c

caelum19

03/20/2020, 10:12 PM
very interesting
a

Adam Powell

03/20/2020, 10:13 PM
I have a doc that I maintain that is meant to explain compose to someone with about 2nd semester computer science proficiency just as an exercise; if the explanations in that doc start getting too muddled it usually means we have work to do
c

caelum19

03/20/2020, 10:14 PM
that's a really cool idea
a

Adam Powell

03/20/2020, 10:14 PM
if I don't like an answer in there I try to rewrite the doc with an answer I like better and then see if we can make the system actually work that way 🙂
same with writing slide decks for conference talks over the years
a lot of android Fragment API improvements over the years came about because I was embarrassed at the slides I had to write for a talk
💯 1
c

caelum19

03/20/2020, 10:16 PM
Imagine if you had a similar document for android pre-x
a

Adam Powell

03/20/2020, 10:16 PM
"pre-x?"
c

caelum19

03/20/2020, 10:18 PM
the old support library
a

Adam Powell

03/20/2020, 10:20 PM
we were really targeting a different problem then, it was more about bridging the gap between android platform releases for a long time
prior to adopting kotlin the prospect of someone learning programming by learning android was pretty far out there
c

caelum19

03/20/2020, 10:23 PM
interesting
I am curious why Kotlin got on so well in Android but other adopters are so far behind
at work I have finally broken from using Java and my teammates will be surprised by the next PR that contains this language Caelum keeps raving on about
a

Adam Powell

03/20/2020, 10:33 PM
imo it's a great fit for android because it matches android's constraints well. Very smooth interop story for interacting with a large existing API surface while keeping the native feel, cheap abstractions like extension functions and inline lambda support for higher-order functions, crossinline for helping to implement large callback object surfaces, small stdlib that behaves very well with code shrinkers
more recently, everything about coroutines since android heavily relies on async and concurrent code
c

caelum19

03/20/2020, 10:38 PM
ooo yeah the coroutines are so nice
somehow I missed when flows became a thing
a

Adam Powell

03/20/2020, 10:39 PM
RxJava caught on like wildfire in the android community
and a huge portion of its usage on android tends to be for the scheduling rather than reactive streams
c

caelum19

03/20/2020, 10:40 PM
I really want to learn rx sometime but it's hard to find the motivation as coroutines seems better for most scenarios
a

Adam Powell

03/20/2020, 10:41 PM
if you know flow you know rx
c

caelum19

03/20/2020, 10:41 PM
TIL
OH
streams felt so much more confusing
Is it just me or does Kotlin have really really good naming
2 Views