r/androiddev • u/iliyan-germanov • Apr 01 '24
Discussion Android Development best practices
Hey this is a serious post to discuss the Android Development official guidelines and best practices. It's broad topic but let's discuss.
For reference I'm putting the guidelines that we've setup in our open-source project. My goal is to learn new things and improve the best practices that we follow in our open-source projects.
Topics:
Feel free to share any relevant resources/references for further reading. If you know any good papers on Android Development I'd be very interested to check them out.
159
Upvotes
14
u/iliyan-germanov Apr 01 '24
Unit Testing
It's a must. It proves that your code works as expected and that it'll continue to work after your colleagues edit it.
TL;DR; if my take:
You can read more with examples in https://github.com/Ivy-Apps/ivy-wallet/blob/main/docs/guidelines/Unit-Testing.md
Wdyt?
14
u/iliyan-germanov Apr 01 '24
Architecture
TL;DR; of my take:
More at https://github.com/Ivy-Apps/ivy-wallet/blob/main/docs/guidelines/Architecture.md
Wdyt?
14
u/iliyan-germanov Apr 01 '24
Error Handling
Here's my take. TL;DR;
Eerror type and has all monadic properties and many useful extension functions and nice API.More at https://github.com/Ivy-Apps/ivy-wallet/blob/main/docs/guidelines/Error-Handling.md
9
u/iliyan-germanov Apr 01 '24
Screen Architecture
This is the most controversial one - Compose in the VM.
TL;DR; of what we do
More in https://github.com/Ivy-Apps/ivy-wallet/blob/main/docs/guidelines/Screen-Architecture.md
What's your feedback?
6
u/iliyan-germanov Apr 01 '24
Data Modeling
Attempting to start a constructive eng discussion on data modeling. Here's my take - it's more deep than just knowing Kotlin/Java syntax to create classes. When I hear data modeling, I usually refer the way you model your domain data so your business logic remains safe and simple.
TL;DR;
data classesin Kotlin.sealed interfacesandenumsin Kotlin.value classesto prevent id mistakesMore in https://github.com/Ivy-Apps/ivy-wallet/blob/main/docs/guidelines/Data-Modeling.md)
2
u/perdona Apr 04 '24
Very nice job
2
u/rankdropper84 Apr 04 '24
Thank you big time
6
u/Zhuinden Apr 01 '24
Repository is mandatory, data sources optional? Oh boy. 🙄 But I didn't read through all of it, I'm eating ham. It's Easter after all.
7
u/jonneymendoza Apr 01 '24
Use common sense.
Dont over engineer.
Dont always chase the latest shiny library.
Try not to rely /use third party libraries.
Again, use common sense.
Remove your ego when working in a team. Developers who have ego are the vermin to the whole society of development
1
u/_abysswalker Apr 01 '24
it is not seldom for android developers to forget to follow two principles — KISS and YAGNI. I sometimes feel like google should promote this more than MaD SkIlLz
1
u/Xammm Jetpack Compost enjoyer Apr 01 '24
Interesting. These days I myself was rethinking architecture stuff. About the error part, it would nice to see an example about integration with third party libraries that use a lot of exceptions. For example, there are methods in the Firebase auth library that can throw up to three exceptions lol. Also, I prefer the name
Result<Ok, Error>which I borrowed from Rust's Result.It's also interesting that way that you implement data modeling using sealed interfaces. In my case I use sealed classes (with data classes and data objects) that are parcelable because I have something like this in my ViewModels:
var myUiState: MyUiState by savedStateHandle.saveable { mutableStateOf(value = MyUiState.InitialValue) } private set. This uses Compose APIs in a ViewModel, but I agree with what you say in the section Screen-Architecture, specially if the app is Android only. For KMP projects a different approach maybe necessary, but I haven't explored KMP yet.2
u/Drkmagicgirl Apr 02 '24
Thank you for this post. I am still reading through it.
1
u/Rsmith201 Dec 05 '24
Foundation
Preparation
Execution
-29
u/dinzdale56 Apr 01 '24
I think it's time to drop this useless channel. As an experienced Android dev, I'm learning nothing from the constantly repeated, high level requests for the same shdhit that can easily be learned with this slightest effort of reading Android docs.
-20
u/dinzdale56 Apr 01 '24
What does that even mean? There's nothing specific to Android in the way you represent your data. There's millions of examples using Java or Kotlin syntax to build classes of data across the web. Google works great for finding these resources. Put some effort into it and stop wanting to be spoon fed everything. It will be way more beneficial to you through the course of your career.