For Assignment 1, I am making an Android implementation of the nslookup utility.
The original design was for the app to take a hostname and convert it into an IP address. During development, I decided that the App should also be able to convert the IP address into a hostname as well.
Here is a picture of the App running on the Android emulator.
John Ingram’s presentation on Thursday had a lot of good advice about software engineering and project management. Here are some good tips that helped me with this assignment.
Start with your requirements.
- Know the app absolutely needs to do first.
- Worry about perfecting it later.
Software design is an iterative process. Get something that works first, then add to it. Don’t try to solve all the world’s problems at once.
The original iPhone was terrible even compared to other smartphones of its era. No App Store, no Copy/Paste functionality, not even 3G support. But it did what it did well and it became very successful.
Design the interface before coding.
- I used the interface builder in res/layout/activity-main.xml
- Bug in API version 19.
- Can’t choose properties from the menu.
- Must downgrade to version 18.
- Great for getting a basic picture, but still must be comfortable with XML
- “Absolute positioning” may look great on screen, but may be terrible on the device.
- Some function is simply faster and easier to add directly via XML.
- Bug in API version 19.
In the “real world” interface can make or break your product. If your interface is well designed, you’re going to have an easier time coding. You’re not going to have to redo things to adapt to a changing interface, if you have a good idea of where you are going early.
I’m a terrible procrastinator.
This assignment looks easy, so there is a temptation to put it off until, for example, this weekend, right before it’s due.
What I found was that things that seem easy might not be. For example, the nslookup functionality that I used to find hostnames and IP addresses is all taken care of by the Java API functionality at java.net.InetAddress.
Not so much. I designed my interface, added the appropriate onClick functions, made my call to the java.net.InetAddress function…
…and instead of everything working as expected, I got the following exception.
Basically, network calls cannot should not be made in the main thread. (You can bypass this protection security settings, but don’t.) So, to get this working required a crash course in AsyncTasks and Java generics. It’s not difficult, but it can be time consuming.
Expect things to take longer than expected and plan accordingly. If things go well, you can do more and learn more and make a better app, or you will have time to goof off guilt-free when your app is done and everyone else is stressing out trying to get it handed in.
Nobody likes documentation. Except when we have to read someone else’s code and it’s not there. Or when we read our own code and can’t remember what we did.
- The best time to write documentation is before you write the code.
- Simply writing out what you want to do in plain language can help you think things through.
- The second best time to write documentation is while you write the code.
- Explaining your ideas captures your thought processes while you are writing.
- It can also help you prevent errors. If something in code is awkward to explain, that probably means it’s not the best implementation.
- The next to worst time to write documentation is after the code is written.
- Which is when most of us do it.
- The absolute worst time to write documentation is not at all.
Special thanks to John Ingram for his excellent in-class presentation on software development.
Also, thanks to Greg Edison for demonstrating the drag ‘n’ drop functionality of Eclipse and other hints.
Great info about procrastination, including the instant gratification monkey, at http://waitbutwhy.com/2013/10/why-procrastinators-procrastinate.html and how to beat it at http://waitbutwhy.com/2013/11/how-to-beat-procrastination.html
Acknowledgements in the source code:
Handling networkonmainthread exception with AsyncTask: http://stackoverflow.com/questions/6343166/android-os-networkonmainthreadexception
How to do nslookup in Java: http://www.coderanch.com/t/328875/java/java/nslookup-Java
More on InetAddresses from: http://download.java.net/jdk7/archive/b123/docs/api/java/net/InetAddress.html
Determining whether a string is an IP address: http://stackoverflow.com/questions/11723184/checking-if-string-is-web-address-or-ip-on-android
How to clear a edittext field: http://stackoverflow.com/questions/8758635/how-to-clear-the-edittext-when-onclick-on-button
How to display toasts: http://developer.android.com/guide/topics/ui/notifiers/toasts.html