Lisa Luo: Functional reactive programming + MVVM, Swift + Kotlin
Articles Blog

Lisa Luo: Functional reactive programming + MVVM, Swift + Kotlin

August 17, 2019

Hey welcome to Android Dialogs where we have bite-sized conversations with people in the Android community
I’m Huyen Tue Dao and I’m speaking with Lisa Luo Lisa thank you so much for
joining us today yeah it’s great to be here well where are you based and how
did you get started in Android So I’m currently based in Brooklyn New York and
I got my start with Android I’d say in college I took a smartphone programming
class and it was literally just a smartphone programming and it was the
first time it was offered so we didn’t know if it was Android or iOS and it
turned out to be Android which I think a lot of people were disappointed with I
don’t know why I was running a different scene I think our professors were just
more old school and into Java and it was just easier to like get started with
Android because they didn’t want to deal deal with licenses um he says so that
was actually my favorite computer science course and then when I was an
intern at Kickstarter I was actually working on the backend and rails before
a hack day I realized that well my real skills like I don’t really feel that
good about them because I was still learning but I really did like Android
and Kickstarter at that time did not have an Android app so for my hack day I
just hacked together like it was basically just a webview that like sent
some headers to cut off like certain parts of the webview and render the
Kickstarter website like in a webview in like a different format and that was
exciting it’s written for people I’m so happy to hear that you were excited by
webview because usually that’s not the reaction my people get but yeah I just
had a few hours so I was like what what can like I just want this to like render
native natively on a device right so that’s what I ended up doing and yeah
people people we were all excited about the win theatres are you doing a
hackathon our hack day then you know it’s just whatever works whatever works
yeah yeah so that was like the MVP for hack day which was not MVP like most
value player not not the other side I was like my brain was architected for a
second but no you had a Minimum Viable Product Oh minimum
yeah that sort of thing about model-view-presenter and like oh yes
valuable players I guess you were the MVP with the MVP yes I was unfortunately
you didn’t use MVP I guess at the time system would not using MVP that would
have been an achievement unlocked I think where are you working out so I’m
currently still at Kickstarter but I will be starting soon at HQ trivia
helping get Android out the door which I’m very excited about so I know we kind
of you were talking about in your class how your professors were into Android
and the rest of class didn’t and I think that’s interesting because right now
you’re actually doing both Android and iOS right yeah so when I returned full
time to Kickstarter this is like story time we my first project was just to
ship Android 1.0 with our native team and we did that in and we released our
app in 2016 which was really exciting as kick servers first official Android app
and we built it using our X Java and mvvm when he’s not a video view model
it’s like alphabet soup yeah but it was really interesting because when I joined
like Eric’s Java like the team was already like leaning towards that and
mvvm and that’s not really something you learned in school especially like a few
years ago no absolutely yeah um so when I heard the news I was actually pretty
excited because like I I asked a few questions it’s like what like sort of
what is what is rx Java like like it’s just something so new to me and when I
learned that basically the principles we’re taking most from it was that we
like the mathematical principle of functions like input-output relation
functions that limited mutability and side effects you don’t like hearing that
it was just like whoa like I don’t know what this is it looks really scary but
like honestly anything is better than the Android development standard right
now or at least how I learned it in school and at least from projects I’ve
seen that if just like her just like huge view holders it’s like async tasks
my keys he’d switch cases just like handle all the state of like how he was
our vendor and um so that was pretty cool like I’d say for our team like we
were to Android engineers and to iOS engineers and it was mostly we worked
very collaboratively together so and we were this framework was new to all of us
and we it took us like so many tries to get it right like a view model basically
what a view model is is it’s a class that holds all the business logic that
handles things also like API requests and just like processing data the models
we used were just like a little parcel parcel of all models for mirror API and
then our views were included activities when we began it just included
activities we didn’t have any fragments yet we had one fragment at the end and
it was great we like fragments that’s that’s that’s refreshing to hear and
it’s like to hear both sides you know always I hear yeah yeah both sides make
sense honestly like it’s just like more life cycle things to handle but I think
with our architecture it really worked well with our architecture just like we
have like base classes oh what a fun thing too is um Kickstarter both of our
apps are actually open sourced so if you want to ever pause and take a look at
them it’s Android OS s like slash Kickstarter / Android OSS on github and
that’s pretty cool they can look at like how everything is architected mm-hmm but
what I was saying is we had a base activity and we just modeled a base for
ending with after it but I won’t get in too deep with fragments because that’ll
start a little bit of worse I’m honestly pretty indifferent so that’s also why
I’m like yeah that’s I think it’s a good way to be like trying to be like just
kind of more even keel than just see if it actually works for your situation if
it doesn’t and it totally makes sense if it does yeah makes sense and there’s
definitely like a need for them right like there are we use a view pager with
like a tab layout and that’s just like a use case that makes total sense like we
want that container to be a fragment container to be replaced and like to
have a parent so there are some cases where it’s just like I don’t know how
how I would even go about fighting this and it works pretty well like pretty
yeah so yes that’s our one fragment it’s our discovery so do you actually
have like I guess the parallel do you parallel that market sector which we
don’t Android and iOS yes okay so back to the story is once we released our
Android 1.0 we looked at our iOS app which at that time was still totally
written in objective-c by one person who was sort of the tech lead on our native
team and at that point that was the biggest kick servers native team had
been it was four people we looked back at the objective-c up and realized that
like learning this was 2016 like having us learn Objective C seems kind of
pointless or it just seemed like not to be like was this of like right sort of
the functional programming that we were embracing like Swift is just very first
class with a lot of functional concepts mm-hmm and yeah so and we it was also
like a one-person codebase so we just decided then like it was a pretty easy
decision for us to just sort of scorched-earth like do a complete
rewrite of the iOS app and we did do that and it was totally inspired by the
way we architected Android because we liked using Eric’s Java so much and we
really liked mvvm but mostly like the main reason why is because all the
business logic was extracted into these like very pretty agnostic classes like
they only know about their view once we like tell them right and they had inputs
and outputs that were very clearly defined so like an input would be like
on a screen I user touches a button so then a Nana put would be button clicked
and then output B maybe we start an activity maybe we do something and then
that output which is just tell of you to start an activity so it was this very
cool flow architecture and we remodeled Swift the exact same way we used
reactive cocoa and like a lot of people ask why we went now it’s reactive Swift
reactive Swift rather than rx Swift and it’s because we found that rx Java is
great but it’s only it’s pretty much now there’s rx Kotlin but that was
pretty much the only like reactive framework for java or for
android at that time right that we liked but it’s also pretty heavy like there
are a lot of operators and things we didn’t use and then when we looked at
reactive cocoa an ORAC swift we made the decision that we liked what reactive
swift had to offer um yeah so that’s just like a caveat when you’re
developing a feature for for instance how closely like I mean do you actually
try to almost make exactly same structure yeah and it’s like the
analogous like constructors on the exact C so when we were building so it’s like
then the we our whole team likes whichever we wanted to build us up
pretty quickly and we all were pretty fresh off of building Android it wasn’t
uncommon for my workflow to literally have Xcode up in Android studio which I
know is blasphemous but I guess for an agent the view model class is like
there’s it’s a class in Android but then it’s just like protocols and Swift’s
right I think yeah so sometimes I would just literally have them open side by
side and because like the models were the same it was the same codebase and
the views basically just swap out like a view controller or self or like activity
right view holder and then within the two like reactive frameworks like
instead of observables and Android it would be signals in Swift so aside from
those little differences like line by line like it was very similar it was
really easy to use our Android as a blueprint to build Swift that’s really
cool cuz you have that kind of abstraction and then the expression can
be very very similar because the languages are similar enough and then
the implementation you tell that platform you can kind of push off to
exactly like the other thing Google and even with Java 6 it was like cool to
build that I mean like the transition now obviously is like Kotlin we like we
had actually known about Colin when we were building Android but it was already
hard enough to like figure out our extraña that we didn’t want to like do
our Java and compound like yeah well we had a deadline till it’s just like ship
our Android app so but it was something that we’d always been thinking about
because because we like like functional reactive programming
principles of just like mapping and like immutability and like cleaning upstate
we did look into Colin and that was always in the back of her minds and I
think only after like the Android developers on our team went into working
it on Swift did it really click like wow like if we can already build up two apps
very similarly just like by keeping our business logic in like there’s certain
classes and writing tests on them in Java and Swift like looking at Colin
it’s just like even more similar like you could almost like copy and paste
like I honestly kind of did for some of you models like I would copy Swift
comment it out and then just like change I say that and people are like why
didn’t you write a script for them it’s like I should probably should have just
literally swap out like subscribe for like observe on or yeah we’re like
signal for observable so that was a really cool work that is so cool I mean
I and I’ve actually very recently been doing a lot of research into kind of
like more theoretical stuff with functional programming I know like you
know a lot for a lot of it is just by pushing side effects as far away as you
can and you know usually when you hear about that people talk about you know
easier tasks easier to maintain conciseness readability but the idea
that part of the advantage is that it makes it easier for you to do a platform
development it’s fascinating because yeah your core logic is so similar
that’s sort of our mantra it’s like we like like the whole right once we use
everywhere principle is like a very good principle of just like good software
development standards and for us it was just like write your business logic once
like we use it everywhere why restrict that to one platform I mean a lot of
this was driven from like our team being really into like these haskell like old
school I mean not old school but like mathematical principles but like for us
like it was important for us as a small team to it just speeds everything up if
you can read each other’s pull requests if you cannot understand both code bases
even for onboarding like we had an int we had some interns like it was just
really cool to see that like all that we had invested because it is an investment
like it’s a learning curve there you’re dealing with frameworks that are very
mature like it’s just a very different way of thinking about programming and
then you’re also working with like the need of AP
like like yeah you can use a Dubuque pager in Android but how do you do that
like with a view model and then like how can you test it like those are
definitely huge challenges but in the end now we have like very solid code
bases we’re developing a feature now is very straightforward also in terms of
bug fixes like yesterday we had bug fix where something was returning null and
we realized that we were like not filtering for the right thing yeah we
had no crashes no we had missed something in like a big refactor and our
workflow for that was ok like let’s think what’s wrong let think about what
might be wrong what might be returning null let’s go to the test file right and
test and we wrote a failing test because right ok this is probably wrong
let’s script that out you can like scaffold and like have mocking like
outputs and subscribers basically that hit the actual view model the test
failed and then we fix it and the test succeeded and then like you just feel
that much more confident pushing stuff out and also when you do big reef actors
like if you already have a very solid test file for every one of your classes
that holds very important business logic like it’s just like very ANA for a team
of like two people it’s like ok like maybe that took us like 20 minutes
longer to like push but like now we are very confident that the future will be
fine and it’s been 2 years and like our crash rate is still like crazy low it’s
like below 0.01 percent that is awesome but just like nuts but it’s also like
yeah like it was worth it like and now it’s like such a part of our workflow
that it doesn’t even take up that much time because our tests are very they’re
lightweight like robolectric unit tests and they run very quickly they’re fun to
write and yeah I guess to ping back actually and I think that’s really
really cool that you have exposure with both Kotlin and Swift and I’ve always
kind of wondered how similar are they and you know I guess what is your view
on on on both languages compared yeah people might kill me for saying this but
like they’re pretty much the same they’re not they’re not they’re just so
similar like Kotlin and Swift that the differences there are trade-offs to each
that’s sort of even them out like in general the syntax is the same like you
have let and Swift for a final value you have a vowel and kahlan like three
letters and then you still have VARs the way you do mark optionals is the same
way yeah I think the biggest fundamental difference or one of the biggest
fundamental differences is enums I’ve heard many good things about 15 ohms
yeah younam’s are just pretty pretty magical on swiftly help with so many
things like routing or just defining types and they just make types like
super useful and they help they help just make your app more strongly-typed
how different are they from say Java enums and what we have in color just not
they’re just not real in Java and enum is basically I mean I think of them as
just like like classes that hold like a bunch of like static hints or something
that just take up way more memory for some reason like I just can do less to I
don’t know and Collin enums you know classes still exist and they’re kind of
cool they can use but if you want to really like represent a Swift you know
mini Kotlin like we’ve done some cool stuff representing enums using silk
classes right I think that’s what the docs suggest to Colin has so many cool
features like tail recursion that Swift doesn’t have you probably used a little
less but oh really yeah yeah you can just annotate a function I think as tail
rec and and even in the IDE like on Android studio if you write a tail
recursive function a little thing pops up ends like this is tail recursion and
like when I was working on that with like my fellow iOS developer we were
like Swift does a lot of things really right playgrounds are amazing it’d be cool if there was like a live Kotlin playground I’m not sure if that’s we
actually yeah yeah I’ve heard this from a couple different people that yeah love
love a playground for yeah playgrounds just make Swift us so so easy to learn
which is awesome like if anyone’s getting started like it’s like if you
have a mac book like swift Xcode has already built in like opening a
playground just being able to do that it’s just amazing for Swift for Kotlin
like it’d be awesome to have the same thing
like the website has pretty good like : cones and like little snippets where you
can just run code but that’s yeah but Polly I’m just like a sandbox where you
can just like yeah ever yes yeah yeah so you can just try out but you can also
like reach into like the Android API so like try and do stuff that’s sort of
what Swift playgrounds do like you know access to the entire like oh wow iOS
yeah so if you wanted to like make a little graphic we’re like mega love you
and like animate it like you can’t so you don’t have to like say like have a
whole test project or anything it’s just you just go in and grab a not API and do
something with work yeah so that’s pretty cool that would be pretty cool of
Colin like work towards that yes please if anyone’s out there is listening and
has any ability to to help us bring these things that we can awesome yeah
well if you are interested in things colony or swifty or Android or iOS you
should definitely come find Lisa on the internet and where can I do that where
they find you on the Internet Lisa you can find me on Twitter and my handle is
at loser Lu OSE are awesome well thank you so
much for talking with me today yeah it’s been great chatting with you and thank
you all and we’ll see you next time bye I can’t believe a curtain fell did you
do that I was like your brother like we’re just talking stuff yeah it’s like
okay we recall we recall I just think of course right in the middle that’s okay

Only registered users can comment.

  1. Thanks for the code base Lisa, a great resource! These talks are pure gold Huyen, please keep them coming <3

Leave a Reply

Your email address will not be published. Required fields are marked *