Wednesday, June 18, 2014

Lessons Learned: Part I

I'm going to do one of these posts every time I release an app, where I talk about what I learned throughout the development process.  As with everything on this blog, hopefully someone will find it useful.

1.) Plan ahead

I'm just going to say this in advance: many of these are going to be incredibly obvious.  Including this one.
Before you start, take a few minutes (or hours) to plan your app's layout and figure out what you want in advance.  I did this, and it made the layout process incredibly easy and smooth.  It also helped me to recognize inconsistencies and issues before I even started writing any code.  If you just dive in without thinking about things, there's a good chance at some point you will need to make big changes because you didn't factor in ________.  5 minutes of planning saves 5 hours of headache.

2.) Don't say "I'll reorganize stuff later"

Make your code extensible and reusable from day 1.  I made the mistake of writing messy, copy-pasted code everywhere, and it turned out to be a real pain.  For example, I have some dialogs that I use in multiple places.  When I first started writing the app, I just copied and pasted these where I needed them, because I (for some reason) didn't want to slow down for 5 minutes and think about how I could reuse that code.  Then of course, I needed to make changes to the dialogs, which left me scrambling to remember every place I had copied that code.  When I would miss one, I would waste time trying to figure out why one dialog worked and the other didn't.  At the time, it felt like I was saving myself time and effort, but in retrospect I definitely wasn't.  Even if you don't plan on using something again, it doesn't hurt to take 30 seconds to throw it into a function or its own class.  Which brings me to #3...

3.) Don't be afraid to extend stuff

This one is actually kind of new to me.  Most of my programming experience comes from school assignments, and most in classes don't need to use inheritance at all.  The classes that do need it typically give you a very specific architecture that you need to create, and as such you miss out on the practical side of concepts like this.  I never really realized how easy it is to modify a class's behavior.  For example, bringing up the dialogs again, most of the dialogs that I used had an EditText for entering semester/course/assignment information.  I wanted the soft keyboard to automatically show itself as soon as the dialog appeared.  (I think I mentioned this in another post.)  Anyway, once I found a solution, I ended up copying and pasting it in every single dialog that needed it.  Looking back, I could have simply made my own class extending from AlertDialog that could have handled that automatically.  And there are a lot of other ways this can help; changing the behavior of an ArrayAdapter, or creating a special kind of Button for example.  And if you only need to override one or two functions, you can always use an anonymous class.  (I had no idea that you could do this until a few weeks ago.  Anonymous classes are now by far my favorite Java feature.)

That's all I've got right now.  Basically they all boil down to: don't rush things, and don't avoid a bit of extra work if it will save you trouble later.

No comments:

Post a Comment