My Top 7 Clean Code Tips for Android Developers (You Can Immediately Apply These!)

preview_player
Показать описание
Proper coding style is fundamental if you want to build solid apps. In this video, you'll learn about 7 tips, you can immediately follow to make your code style a lot better.

⭐ Get certificates for your future job
⭐ Save countless hours of time
⭐ 100% money back guarantee for 30 days
⭐ Become a professional Android developer now:

🎓 Become an industry-ready developer in the Mobile Dev Campus:

🎁 Get my FREE 4.5h course "The Best Practice Guide to Android Architecture":

Read our weekly Android blog:

Join this channel to get access to perks:

Join my Discord server:

You like my free content? Here you can buy me a coffee:

00:00 - The Rule of Three
01:22 - Don't comment what happens
03:29 - Don't be afraid of long names
04:31 - Avoid genius code
06:57 - Follow the Law of Demeter
09:35 - Avoid side-effects
10:52 - Avoid if-else
Рекомендации по теме
Комментарии
Автор

I like the Rule of Three. I've been doing that intuitively

codinginflow
Автор

7 tip - it has unofficial name of "return early pattern" :)
3 tip - I agree with third tip about long name, but i can't completely agree with the example you show there. For me it is okey to have function like findPerson(name:String), because param name inside braces says itself about condition. Also such naming as findPersonByName downgrades possibilities of using methods overload which is really nice feature to have, where you have findPerson(name: String), findPerson(id: Int), etc.

bty_s
Автор

I wish you were there 4 years ago when I was still new programmer. Your content would've saved me learning things the hard way and would save me from some YouTuber how just give wrong information. It is only a matter of time before you become one of the best recognized YouTubers in the android dev community. Good luck

AbdulelahAGR
Автор

To be honest the "Rule of Three" is a trap, it is nice to not repeat yourself, but now let's imagine a case where you have refactored the code to not repeat yourself, and let's say that you have like 5 occurrences of your code that you replace with some kind of base class of whatever, now let's imagine that you need to change the behavior but only in one of your occurrence, but you have extracted this code to a single shared piece of code, so you either need to give up on using this shared code for this occurrence or use some kind of flag or whatever passed to this base code, okay, you've got it done, now you need to again change the behavior of another occurrence, but only this one, now you're in the same situation like before, and it becomes messy as hell

Overall the awareness of not repeating yourself is good, but forcing it to not repeat yourself actually makes the possibility of changes really limited and error-prone

buszi_
Автор

I bought both of your courses and I'm learning so much. You are a huge help! A video about Entry forms would be great (like a bunch of titles with matching edit text fields) I'm struggling to grasp the concept of Lazy column/ RecyclerView with this scenario. Either way, thank YOU!

jeepaholic
Автор

Good stuff big 🐕. Agreed with all of them.

I've been doing software development professionally since shortly after college, so about 15 years, and I've seen most of those often. The pointless comments and crappy variable/class/function names the most often. There's no good reason not to have descriptive (reasonably so) names for things; abbreviating things and making names like 6 characters long is just unnecessary and makes maintainability more difficult. Heck I even didn't do that at a previous job where I did a fair amount of VB6 coding (shudder), where there was no Intellisense (although you could press Tab to autocomplete names if they were already correct iirc, it was a good check).

clamum
Автор

Thanks! I just found your channel and with you I learn good practices and English at the same time, my day to day I use patterns, refactoring and smell codes, it would be interesting if you made more content of good practices. No matter how much you know a language or SDK (Android), the next level as a programmer is this.

tadeogonzalezalvarez
Автор

genius boy, still uploading videos, Even though he is traveling south africa, what a boy

arfinhosain
Автор

Thanks for share. You covered good amount of tips in short video.

PawanGupta
Автор

Thank you for this Video~ it's very worthfull~
Does Secret number 5 ( Follow the Law of Demeter ) means the "Capsulation"?

riyupapa
Автор

Well, my example of genius code is needed when I don't want to repeat myself.
Check this example:
if (prop == "something" || prop == "something_else" || prop == "anything") {}

you can shorten it to this:

if (listOf("something", "something_else", "anything").contains(prop)) {}

it's shorter and you avoid repeating yourself.

ciach_
Автор

hi Philipp, could you make a video explaining some of Google's architecture sample apps ? I tried to look into those but it was not that straightforward. Thank you!

kimcherwoo
Автор

I agreed with all the points but about comments. I guess people should add comments what they feel like it's totally subjective.. your code might read by someone who just started learning things few says ago...also it effect dev performance..he/she has to think about what should be the comment.. comments should be natural...it can be improved later...when you code focus on logic .

RanbirSingh-dlco
Автор

I would also like to add that you should avoid adding different logic code in one function. For example you have calculateDistance(), it should only contains logic related to its name and don't add irrelevant logic like conversion and etc. It should be a separate function.

bitwisedevs
Автор

Well done - You have interesting names for some of these rules. I didn't know 'field encapsulation' was called the law of demeter.

AliasdHacker
Автор

Please mention more about law of Demeter. From my work experience, there are a lot of incomplete codes using Clean Architecture and Util functions which break the the law of Demeter. Given repeating functions are found, what is the rule of thumb on when to categorize functions into UseCase and when to let functions alone as util function?

larrystreehouse
Автор

In the last section of the video, you can actually remove the {} associated with the "if" statement and make it a one liner:
if (isActive) return

yayiiz
Автор

very good one, the last tip i thought i was a weirdo cause i use it a lot.

nicolasfelipe
Автор

Hey Phillip
Can you make a video on new project level gradle model
I am little bit confused about adding classpath and other thing in it

r_yan
Автор

nice video, could you please share an example of testing android project with clean architecture i am having difficulties to understand how to test viewmodels, test cases and the view with states and events

baselnat