Mark M. | has entered the room |
Mark M. | turned on guest access |
Aug 20 | 9:05 AM |
Urban | has entered the room |
Mark M. |
hello, Urban!
|
Mark M. |
how can I help you today?
|
Urban |
Hey Mark, it's your fellow sub Urban (again) with bunch of questions (same old)
|
Mark M. |
darn -- I was hoping for new and exciting questions! :-)
|
Urban |
Thank you for being here today
|
Urban |
Hopefully you will find them exciting enough
|
Mark M. |
who-hoo!
|
Urban |
Once again sorry to ask you that much but you are one of the best
|
Mark M. |
I try to be useful -- so, what's your first question?
|
Urban |
And as I am looking to become one, I am disturbing poor you
|
Urban |
First question is about data sync (online database with internal one): I have looked into SyncAdapter which is supposedly optimised for such scenarios. However, I have found it to be (overely) complicated while many ppl report problems when using it. Therefore, my question is if you would recomend synching data using SyncA or should I opt for other forms of data synchronisation?
|
Mark M. |
"overly complicated" is a nice, polite description of SyncAdapter
|
Mark M. |
and so I have avoided it
|
Mark M. |
in addition to the complexity, you do not have any control over the timing of the sync operations, and usually The Boss wants some amount of control
|
Mark M. |
so, I do not think that SyncAdapter is popular
|
Mark M. |
most projects use something else, such as WorkManager
|
Aug 20 | 9:10 AM |
Urban |
So, how did you usually perform sync operations? Manually or using a special mechanism?
|
Mark M. |
in terms of a trigger for the timing, I would recommend WorkManager
|
Mark M. |
in terms of the actual sync itself, that depends a lot on the local and remote data sources
|
Mark M. |
unless you have a specific environment set up for automatic synchronization (e.g., git, Couchbase Mobile), synchronization is a complex problem
|
Urban |
Okay, thank you for that answer
|
Urban |
So, doing it manually (such as inserting rows into some table) is an accepted way of doing this?
|
Mark M. |
again, unless you have an environment that handles those details for you (e.g., git, Couchbase Mobile), you have no choice
|
Urban |
okay, thank you very much for such detailed answer
|
Urban |
Next question is regarding the real-time messages: I know that many people use FCM. Would you suggest using this for message deliveries or should I look into other alternative? Also, is PHP a good back-end for sending messages or should I learn to do it with JavaScrips, such as Node.js?
|
Mark M. |
"Would you suggest using this for message deliveries or should I look into other alternative?" -- well, that depends
|
Mark M. |
FCM is only available on Google Play devices
|
Mark M. |
if you are distributing to other devices, such as to users in China, you will need at least to have some alternative that will work for those users
|
Aug 20 | 9:15 AM |
Mark M. |
on the other hand, due to Android's power restrictions, creating an alternative to FCM would be difficult
|
Urban |
What would be alternatives for "other users"?
|
Mark M. |
MQTT, or some solution based off of WebSockets, would be the two that I would look at first
|
Mark M. |
I have not researched this space recently and so there may be some new options that I am unaware of
|
Mark M. |
the challenge is that for any non-FCM solution, you somehow need a process to be listening for messages all the time (e.g., listening on the client side of the WebSocket)
|
Mark M. |
that would require a foreground service (to avoid Android 8.0's limitation on background service lifetime)
|
Mark M. |
and it would require the user to opt out of all battery optimization for that app
|
Urban |
With "WebSocket" you mean like implementing a Server such as AsyncHttpServer?
|
Mark M. |
no, I mean WebSockets: https://en.wikipedia.org/wiki/WebSocket
|
Urban |
Oh okay, my bad.
|
Urban |
Thank you for this. What about "s PHP a good back-end for sending messages or should I learn to do it with JavaScrips, such as Node.js?"
|
Mark M. |
that depends on how you send the messagess
|
Mark M. |
er, messages
|
Mark M. |
if you are using FCM, by now, I imagine that there are server-side libraries for all major frameworks
|
Mark M. |
I would be rather surprised if there is no solution for PHP -> FCM communications
|
Mark M. |
that being said, I have never used PHP
|
Mark M. |
if you are using MQTT or WebSockets, your options may be more limited, and you may need a richer server-side option (NodeJS, Kotlin, etc.)
|
Aug 20 | 9:20 AM |
Urban |
So in general there is no much difference right? I am only asking as I have seen implementatons of both and many ppl in general these days migrate from PHP to Node.js solutioins
|
Mark M. |
PHP is rather old, and AFAIK you can "hit the wall" on technical limitations rather quickly
|
Mark M. |
NodeJS is more capable, but it does require some amount of JavaScript experience
|
Urban |
So would you suggest for me to learn how to do "server-sided" operations in Node.JS in general?
|
Mark M. |
I can't answer that
|
Mark M. |
I can provide guidance on Android app development
|
Mark M. |
I cannot tell you what is best for you for server-side development
|
Mark M. |
personally, nowadays I use Kotlin, and before that I used Ruby
|
Urban |
Aha, okay. I was going to ask you whether I should replace my Retrofit -> PHP -> MySQL with something connected to Node.JS but I guess you cannot answer that aswell
|
Mark M. |
NodeJS is popular, and that has advantages
|
Mark M. |
the Retrofit side is fine!
|
Mark M. |
if your PHP works and you are happy with it, there may not be any reason to change
|
Urban |
Hmm, it certainly works but for some reason I am obsessed with doing "things optimally". Which is also the reason why I am asking you this
|
Mark M. |
you may be familiar with the expression: "beauty lies in the eyes of the beholder"
|
Urban |
And if there would be adventage to use Node.JS, I would certainly learn it
|
Mark M. |
what you consider "optimal" is your choice, based on your criteria and your opinions
|
Aug 20 | 9:25 AM |
Mark M. |
I can't tell you want you will find to be optimal
|
Urban |
I see. Thank you for that answer, I probably should get rid of "black and white" optimisations in programming
|
Urban |
As, like you've said, there is no such thing
|
Mark M. |
it's more that personal opinions are personal
|
Mark M. |
my opinions are my own and may not resemble yours
|
Urban |
Thank you for this answer
|
Urban |
In addition to everything, I would like to add chat functionality to my app. After a bit of research, I have found that Firebase is supposed to be the best for real-time messages. However, many users advised againts using it due to it's costs when scalled to many users. So, what is your thought on this topic? Should I opt for Firebase or go for an alternative?
|
Mark M. |
IMHO, that depends a bit on how the chat will work
|
Mark M. |
if you only need to receive chat messages when the app is in the foreground, then FCM would be overkill, and I would use WebSockets
|
Mark M. |
if, on the other hand, you want to continuously receive chat messages, even when the app is not running, FCM (for Google Play devices) may be necessary
|
Mark M. |
FCM mostly exists to deliver messages when your app might not be running
|
Aug 20 | 9:30 AM |
Urban |
I see. What about database/storage perspective? Many people reccomend Firebase database while also there are costs one needs to consider.
|
Mark M. |
if by "Firebase" you were referring to Firestore or Firebase Realtime Database... I only worked with Firebase Realtime Database and did not like it much
|
Urban |
I was reffering to database yes
|
Urban |
Sorry for inconvenciance
|
Mark M. |
no problem -- there are lots of things under the Firebase brand
|
Mark M. |
personally, I would not use Firebase services, but that is because I am "a control freak" and prefer to run my own servers
|
Mark M. |
it helps that I have decades of experience in running servers
|
Urban |
I see. So what alternative (for DB side) would you use instead?
|
Mark M. |
well, the Warescription app server is written in Kotlin and stores its data in SQLite
|
Mark M. |
SQLite is not a good choice for a busy server
|
Mark M. |
my server is not that busy
|
Urban |
In additon, SQLite is for internal storage. What about hosting online DB?
|
Mark M. |
if I needed a more powerful database, MySQL, MariaDB, or something like that would be candidates, though I have not researched this area recently
|
Mark M. |
SQLite can be used just about anywhere
|
Mark M. |
I have used it on servers for over a decade
|
Mark M. |
but, you need to run your own server
|
Urban |
Oh, I did not know that. Thank you for that information
|
Mark M. |
personally, I have never used a hosted database service, other than about a month's use of Firebase Realtime Database
|
Urban |
SO all that being said, you would advice me against using Firebase DB and instead rather roll my own implementation of DB?
|
Mark M. |
no, I am merely saying what my experiences were
|
Aug 20 | 9:35 AM |
Urban |
Okay, will try to do some more research on that part then
|
Urban |
Will be right back: grabbing water
|
Urban |
Sorry for taht
|
Mark M. |
no problem!
|
Urban |
I have a question regarding app debuging: at this point, I am only using my phone to debug while using LogCat. I have seen that in your book you go through many debuging tools. Would you reccomend to start using these and which one/two would you reccomend?
|
Mark M. |
I am not certain what tools you are referring to
|
Mark M. |
on a daily basis, I use the Android Studio debugger, plus Logcat
|
Aug 20 | 9:40 AM |
Mark M. |
periodically, I use Leak Canary and Android Studio tools for leak detection
|
Urban |
I think at one point you mentioned Espresso/Mockito(?)
|
Mark M. |
those are testing libraries
|
Mark M. |
those are not really debugging tools
|
Mark M. |
other than to the extent that tests help you find bugs, of course
|
Urban |
Oh, my bad. Would you reccomend me using these?
|
Mark M. |
some sort of mocking is very useful in testing, and I have settled on Mockito, though there are others (e.g., PowerMock)
|
Mark M. |
Espresso is very useful in UI testing, but I find those sorts of tests to be fragile, so I try to minimize how much testing I do there
|
Urban |
So what do these "testing libraries" tell us that Android Studio cannot?
|
Mark M. |
they are independent of Android Studio
|
Mark M. |
that is akin to asking "what does an Android app do that Android Studio cannot?" -- they are not really comparable technologies
|
Mark M. |
instrumented tests and unit tests exercise our production code to confirm that we wrote it correctly
|
Mark M. | |
Urban |
But doesn't just running the code on the emulator tells us the same thing?
|
Mark M. |
not necessarily
|
Aug 20 | 9:45 AM |
Mark M. |
for example, you seem to want to communicate with a server
|
Mark M. |
suppose this is a REST-style Web service
|
Mark M. |
you need to know if your app can handle unexpected Web service responses (e.g., HTTP 500 return code)
|
Mark M. |
manual testing probably cannot test that
|
Mark M. |
so, we write test code that can simulate the server and return responses that our tests need, to see if our code handles those sorts of responses
|
Mark M. |
software testing is a major portion of any sort of software development
|
Urban |
Oh I see. So for this purpose, you (personally) mainly you Mockito correct?
|
Mark M. |
in some of my books, I show how to test Android apps, but I assume that you have learned about the concept of software testing from someplace else
|
Mark M. |
in terms of writing mocks, yes, I mostly use Mockito
|
Mark M. |
though for Web service responses, I sometimes use MockWebServer from the OkHttp library
|
Urban |
And for "UI testing", what did you mean with that?
|
Mark M. |
you were saying that you do manual testing: poking at the UI and seeing what breaks
|
Mark M. |
UI testing is automated "poking at the UI and seeing what breaks"
|
Mark M. |
so, with Espresso, you can say "click this button", "fill in XYZ into this field", and so on
|
Urban |
Oh I see. Thank you - will try to use these during my next tests then!
|
Mark M. |
then examine the state of other widgets to see if things worked (e.g., "confirm that the 'Save' button is now enabled"
|
Aug 20 | 9:50 AM |
Urban |
So, the last question: in one of your books, you describe GraphQL in detail. So far, I have mainly used Retrofit to do the comparable requests. Would you reccomend using GraphQL over Retrofit in general?
|
Urban |
Or this again depends on many factors?
|
Mark M. |
comparing GraphQL to Retrofit is not quite the correct comparison
|
Mark M. |
you might compare GraphQL to REST
|
Urban |
Er correct, I see the destinction
|
Mark M. |
so, if your server is set up to have a GraphQL endpoint, you would need to talk to that from the Android app, using something like Apollo-Android
|
Mark M. |
just as if your server is set up to have a REST endpoint, you might use something like Retrofit
|
Mark M. |
what you use on the device is controlled by how the server is implemented
|
Mark M. |
in terms of whether you should use GraphQL or REST on the server -- again, I cannot really provide recommendations there
|
Mark M. |
GraphQL has some interesting characteristics, but REST is much more common
|
Urban |
I got to know that GraphQL might be much better in scenarios for doing 1 query instead of many
|
Urban |
So i guess that if I have many such queries replacing REST might be worthwile
|
Urban |
Otherwise not
|
Urban |
Do I have correct idea?
|
Mark M. |
yes, usually it is easier to get all your data in one request-and-response with GraphQL
|
Mark M. |
GraphQL can offer better performance as a result, but it is going to be more complex to set up
|
Aug 20 | 9:55 AM |
Mark M. |
partly, it will be more complex simply because it is newer and has less support in terms of libraries, tools, and knowledge
|
Mark M. |
partly, it will be more complex because that complexity is what enables the powerful query language
|
Mark M. |
for a personal project, unless you really wanted to play with GraphQL, I would lean towards REST
|
Urban |
So would you agree with my theory of using GraphQL where i have to perform multiple queries and otherwise using REST*
|
Mark M. |
well, usually, you implement either GraphQL or REST, not both
|
Urban |
I have done everything with REST so far but *again* i would like to learn "optimally"
|
Mark M. |
there are many facets to "optimal"
|
Mark M. |
so, GraphQL might perform better in some apps, but it will take more development time
|
Mark M. |
whether you need that extra runtime performance will help determine how much the development time cost is worth it
|
Mark M. |
for a personal project, since performance is rarely an issue, REST is the simpler solution, on the whole
|
Mark M. |
so, for example, the Klassbook (https://klassbook.commonsware.com) uses a REST Web service, not GraphQL
|
Mark M. |
and that's all the time I have for today -- I have to take a call in two minutes
|
Urban |
Thank you Mark, you have helped me much agagin
|
Mark M. |
you're welcome!
|
Mark M. |
the transcript will be posted to https://commonsware.com/office-hours/ shortly
|
Urban |
Hopefully I will leave you in peace for a few weeks
|
Mark M. |
have a pleasant day!
|
Urban |
have a nice rest of the day
|
Urban |
:_)
|
Urban | has left the room |
Mark M. | turned off guest access |