Mark M. | has entered the room |
Mark M. | turned on guest access |
Kai H. | has entered the room |
Kai H. |
Hello
|
Mark M. |
hello, Kai!
|
Mark M. |
how can I help you today?
|
Jun 2 | 8:30 AM |
Kai H. |
I have a question about the "diceware" example from "Exploring Jetpack"
|
Mark M. |
do you literally mean Diceware? or DiceLight? or DiceKoin?
|
Kai H. |
In that example, the Motor executes a "generate()" function in an exectutor
|
Mark M. |
(I have a few variations on the diceware sample)
|
Kai H. |
I think I mean Diceware
|
Mark M. |
so, you are referring to https://gitlab.com/commonsguy/cw-jetpack-java/-...
|
Kai H. |
Exactly
|
Mark M. |
we are doing I/O (either reading a document or reading an asset), so we want a background thread somewhere
|
Mark M. |
in this case, I put the background thread in the motor
|
Mark M. |
in other examples, I will use other approaches
|
Kai H. |
I wanted to know if that is good design. It feels like it should rather be done in the repository itself.
|
Mark M. |
all else being equal, I would put the threading in the repository
|
Mark M. |
however, my options for doing that in Java suck
|
Kai H. |
Why not just have the executor in the repository?
|
Jun 2 | 8:35 AM |
Mark M. |
how will the motor get the results?
|
Mark M. |
we'd need some form of callback
|
Mark M. |
which means the repository needs to track that callback, deal with cases where the motor gets cleared before the results are complete, etc.
|
Kai H. |
That would be something like RXJava I guess.
|
Mark M. |
right
|
Mark M. |
if I were in a pure Java project, and I needed to do this, I would use RxJava
|
Mark M. |
however, I desperately want to avoid RxJava in this book
|
Kai H. |
With good reason ;-)
|
Mark M. |
what I might do, perhaps for Version 1.1 of this book, is try something like a Future
|
Kai H. |
And I guess you didn't wanna use a LiveData at that point because using LiveData in the repository is bad for testability?
|
Mark M. |
I'm not a fan of LiveData in a repository, though I think I have an example of that in the book too
|
Mark M. |
LiveData is really for delivery of results to the main application thread
|
Mark M. |
and it is annoying to work beyond fairly simple scenarios
|
Mark M. |
so, using it for "last mile" delivery of results to the UI layer is fine
|
Mark M. |
but I'd rather steer clear of it until that point
|
Kai H. |
You do have an example in the book and I was wondering about that.
|
Mark M. |
on the whole, the Kotlin examples are far closer to "best practices", because I can use coroutines
|
Kai H. |
I mean an example where you have LiveData in the repository.
|
Kai H. |
Ook
|
Mark M. |
the Java examples are more like "how can I get the point across without a ton of extraneous crap?"
|
Kai H. |
That is good to know, as I follow them somewhat closely
|
Mark M. |
(even though that "crap" is not truly extraneous if you were doing this for real)
|
Jun 2 | 8:40 AM |
Mark M. |
on the whole, my book examples aim for "not horrible" with respect to architecture
|
Mark M. |
and the Kotlin ones tend to be "eh, not too shabby"
|
Mark M. |
but I will try a different approach for the Diceware sample in Version 1.1, later this year, to get the thread out of the motor
|
Jun 2 | 8:45 AM |
Kai H. |
How will you try to do it?
|
Kai H. |
(As I have literally that in my personal app atm)
|
Kai H. |
(The thread in the motor, I mean)
|
Mark M. |
I'll see about having the repository return a Future
|
Mark M. |
that at least is incrementally cleaner than a callback
|
Mark M. |
the repository would then use something like FutureTask with its own executor
|
Kai H. |
But if I wanted to do it best practice I should probably follow one of your examples that use RXJava, right?
|
Mark M. |
hopefully nothing in *Elements of Android Jetpack* is using RxJava, unless I have really screwed up
|
Mark M. |
I have RxJava examples in some first-generation books
|
Mark M. |
though they have their own issues with respect to age and architecture
|
Mark M. |
for a personal project... unless you are giving yourself some deadline, I'd focus on learning Kotlin and coroutines
|
Jun 2 | 8:50 AM |
Mark M. |
IIRC, the project at your job is a pure-Java project, but ideally your personal experiments are aiming to improve your career prospects -- right now, I'd put Kotlin higher on the importance list than RxJava, though both are good to learn
|
Mark M. |
Kotlin is on the upswing, while RxJava is not (mostly from people switching to coroutines with Kotlin work)
|
Mark M. |
or, as Wayne Gretzky put it, "skate to where the puck is going"
|
Mark M. |
but, if you're sure that you want to stick with Java, learning RxJava is a reasonable step
|
Mark M. |
it's just a fairly big step
|
Jun 2 | 9:00 AM |
Kai H. |
Yes, the example about RXJava is from "Architecture Components" iirc
|
Kai H. |
And the reason I am still using Java even in my personal project(s) is because I don't wanna do too much at the same time
|
Jun 2 | 9:05 AM |
Kai H. |
And I want the things I learn in my personal project(s) to be applicable to work as well, preferably.
|
Mark M. |
you will then need to decide if RxJava is "too much"
|
Kai H. |
My personal project is part "modern android", part trying things I could use at work to make things a bit better there.
|
Kai H. |
Is there no RXJava basics that are not THAT hard and that will carry you quite a bit?
|
Kai H. |
Like the amount of RXJava used in "Architecture Components"? (I haven't looked at the whole book, just some snippets of it)
|
Mark M. |
we often talk in terms of Pareto-style outcomes ("20% of the complexity solves 80% of the problems")
|
Mark M. |
RxJava is not that gentle
|
Mark M. |
ideally, when adopting a technology, trivial things are trivial and complex things are complex
|
Mark M. |
with RxJava, trivial things are not as trivial as they should be, and complex things are "OMG"
|
Mark M. |
though it is still better than most Java alternatives
|
Mark M. |
just because once you get into the framework and get things set up, incremental improvements often require just incremental changes
|
Jun 2 | 9:10 AM |
Mark M. |
I have a chapter on RxJava in *The Busy Coder's Guide to Android Development* that serves as an introduction
|
Jun 2 | 9:10 AM |
Mark M. |
that focuses on RxJava in isolation, not from an architecture standpoint, but it introduces the major concepts (schedulers, operators, subscriptions, disposables)
|
Mark M. |
so, I'm not saying "avoid RxJava" -- I am saying "bear in mind that RxJava isn't a walk in the park"
|
Kai H. |
So I'll really have to decide if I want to learn RXJava. It would be a shame to spend a considerable amount of time on it, just to never touch it again.
|
Mark M. |
if you think that your work project might adopt RxJava and you want to play with it in advance, great!
|
Mark M. |
right
|
Kai H. |
Even though I hope that the basic ideas will still be there in the future, maybe just in another form.
|
Mark M. |
agreed: the other way to look at your RxJava experiments is to consider them "getting your feet wet" with reactive programming
|
Kai H. |
How well can RXJava be debugged btw?
|
Mark M. |
that depends on the type of bug, I guess
|
Mark M. |
I rarely run into problems with RxJava itself
|
Kai H. |
Because that is one thing I like about "low level no magic" solutions: You can look into them.
|
Mark M. |
and breakpoints, Log.e(), etc. work normally
|
Kai H. |
I am thinking about trying to understand why something doesn't work the way I thought it should.
|
Mark M. |
if you mean stepping through the RxJava code in a debugger, oy
|
Kai H. |
Which should be fairly often with something as hard as RXJava
|
Jun 2 | 9:15 AM |
Mark M. |
yeah, that's a significant pain point
|
Kai H. |
Well, I can decide to have a go at it and see how far I'll come :D
|
Kai H. |
And I guess there is no good alternative if my workplace doesn't want to switch to Kotlin?
|
Mark M. |
to put it in some perspective, I'm not bad with RxJava, but complex RxJava "chains" might still take me a day to get working correctly
|
Mark M. |
there's nothing with the power or brand recognition of RxJava
|
Kai H. |
Right now we use Loaders and AsyncTask left right and center
|
Mark M. |
AsyncTask is officially deprecated, once you raise your compileSdkVersion to 30 (or 'android-R' for the next few weeks)
|
Mark M. |
I have never liked Loader outside of very narrow use cases (e.g., CursorLoader and a ContentProvider), and even that is largely toast given modern architecture patterns
|
Mark M. |
the Future framework (Future, FutureTask, ListenableFuture, etc.) is the lightweight reactive API baked into Java
|
Jun 2 | 9:20 AM |
Mark M. |
but that dumps the threading itself on your lap, handling only the reactive delivery of results
|
Mark M. |
LiveData is the next level up, handling part of the threading for you (getting results to the main application thread)
|
Mark M. |
(also: built-in lifecycle awareness)
|
Mark M. |
after that, in terms of things that you will see developers use, you're into RxJava or coroutines
|
Mark M. |
I'm sure that there are other options out there, but they aren't very widely used
|
Mark M. |
so, I recommend reading that RxJava chapter in *The Busy Coders' Guide to Android Development*, then making decisions after that
|
Mark M. |
in terms of résumé fodder, saying that you have some experience with RxJava beats *not* saying it :-)
|
Kai H. |
Hehe
|
Jun 2 | 9:25 AM |
Kai H. |
But you're right, in terms of résumé fodder it's best to know Kotlin and Coroutines.
|
Mark M. |
those have longer-term value
|
Kai H. |
I guess we'll have to move away from Java in the long run, if we want to stay "modern".
|
Mark M. |
in the end, it will become a matter of recruiting: will developers elect to not work for your firm if they feel that they will become stagnant?
|
Mark M. |
this does not mean that you have to adopt every new technology that comes down the pike
|
Mark M. |
but, once "the writing is on the wall", you need to have a plan to move forward
|
Mark M. |
I have a talk coming up on Jetpack Compose, where that is the theme: given that this is likely to be a "the writing is on the wall" technology in 3 years, what steps might you take today?
|
Kai H. |
What does "writing on the wall" mean?
|
Mark M. |
oh, sorry
|
Jun 2 | 9:30 AM |
Mark M. |
as I used it here, consider it to mean "it is clear to become dominant"
|
Kai H. |
Ok
|
Kai H. |
Thanks for your input today :D
|
Mark M. |
you're welcome!
|
Mark M. |
and, that's a wrap for today's chat
|
Mark M. |
next one is Thursday at 7:30pm US Eastern
|
Mark M. |
have a pleasant day, and stay healthy!
|
Kai H. |
Have a good time
|
Kai H. | has left the room |
Mark M. | turned off guest access |