Mistakes made by blooming Android App Developers — Construct ‘THE’ Pattern

Your pattern takes you back to the right path

I am really into android app development for more than 4 years out of which 1 year was pure learning curve(ball). But the one that did teach me a lot was not the first year, it was the second one. So what happened in the second year — “chaos” that’s what. I nearly would give up on my ideas because of these simple mistakes that even well experienced developers have gone through at some point of time. So what happened after that?

For this whole story I am referring to the word ‘pattern’ as ‘a routine’ which is followed by any android app developer ’n’ number of times.

Pattern in naming

Yes these are basics of any programming language but there is some thing that is different in what we do here. We do not use only one but many components during our process of creating an app — eg: layout names, layout resource ids, classes, methods, drawable names… well I can go on but you get the point.

What I used to do is mix-up the names which sometimes didn’t make sense and would go hunting back and forth between the layouts and classes and sometimes even extraterrestrial with ‘File Explorer/Finder’.
(the pattern) Let’s just say that I am making a layout for an activity with a button in it which when clicked shows a toast. The naming pattern that I follow is:

Activity Name: MainActivity
Layout Name: activity_main
Button Id: show_toast_button
Button Name in Activity: showToastButton

Now whenever I need to change something like the dimensions of the button my hand simply puts the ‘_’ in between the camel-cased letters, which I find is a super efficient way to search for your components.

Pattern in building blocks

This is that thing which each newbie programmer/developer learns the hard way. I once had a function with 200 lines of code, well it certainly is a laughing matter for me now but more than 50 lines of code (comments not included) is never good.
(the pattern) The trick is knowing which blocks of code can be split into different functions and can then be used privately. If a function has line of code that can return a value which can be used by another function don’t hesitate to split them up.

Pattern in creating tools

What are tools ? — The things that aid us in achieving certain tasks. How can we code a tool inside our android app? — It is called an “Utility”. These utilities are nothing but classes which contain static methods which can be re-used all around your app — activity, fragment, you name it. 
(the pattern) You too see a function which can be used in many activities, services or fragments ? utility is the place where it should be. Don’t waste your time thinking that it can never be used the third time and leave it. These play a huge role and prevent duplication of code.

Pattern in modeling

Well this article is turning out to be boring so I thought I should talk about models, and I am certainly not talking about the one that you are thinking right now. Models are super useful in android app development. They are widely used in ListViews, RecyclerViews, and Databases. Models are nothing but classes with getters and setters.
(the pattern) Let’s say I’m creating a music app, will it be wise to use —

List<HashMap<String, String>>

OR

List<Music>

Yes HashMap can contain different key-value pairs but will you every time use a List full of HashMap the whole time you develop an app. It is an example of bad code and you should definitely avoid it and create models instead.

Pattern in writing

Before we finish up this story of mine follow this simple flow of writing any function or a class. Documentation is an integral part of android app development whether you like it or not and it is the most important of them all. Documentations gives you that — “you have come to the right place” message without which you’ll be wasting an enormous amount of time finding out what it does, which parameters are used where and what not.
(the pattern I learnt the super hard way) I have created a snippet for documentation which I paste above each functions/classes that I have created on that day and replace the it with key information about that block of code — Main cause of my chaos.

Well, blooming developers, I hope that I have made some of your long term issue go away by creating sharing my story and warn you of these mistakes and there are lot of useful routines that you can develop in your experience which can immensely improve your coding abilities. I can certainly share some more tips and tricks for you guys but this post is getting too long, but, feel free to drop in the comments if you feel like getting some tips on early android app development.

Construct “YOUR” pattern and in time you’ll find making any app is just like writing a story — in blocks just like this one.