Thinking Aloud
Curious case of Facebook Hackathon

Who knows about ongoing facebook hackathon?

It is in it’s 2nd second year and I had many hopes from it. Last year, in its first avatar, it was almost a disappointment. But since it facebook, even in its disappointment, the problems were good and to solve them was fun.

This year, i must say, i feel more disappointed. Don’t take me wrong, the execution of the event was quite good. I am not able to make peace with just one rule. The only rule which makes or breaks your solutions. The rule is, you can submit your solution within a period of 6 minutes after downloading the input. This i feel is madness…utter and complete madness. A bit too dramatic in my head, i sound.

Let me tell you why all this kolaveri..

A person spends quite some time, energy and sleep in case of Indians, just to be a part of such events. I would hope, like any other event of this kind, I am allowed to make some mistakes. 

A person who works fast, makes mistake, and adapts fast, is a good person to have on your side. This is coming from the philosophy of fail quickly, fail fast. But if you tell me, i can submit my solution only once, and thats it. It becomes a problem for me. I spend more time looking at my code for corner cases then actually testing it. 

In my past experience with such events, I have seen this issue addressed by simply allowing the user to upload the code and trying to execute the code on the receivers side. This is the most accepted solution for coding competitions. The other solution, if you want to remove the server side is, providing different inputs every time someone downloads the input and check for the output accordingly. I understand this means dealing with a lot more input downloads and solution uploads, but you will at least get away with blog entries like mine.

This is coming from my experience, single syntax mistake makes your couple of hour work go in vain. Almost makes me not participate anymore. But again, its facebook, the problems are good and its fun to race against time. :)

A Hackathon

Today i want to pin down my experience with hackathons. I have been recently part of two close to close hackathons and the experience was very new to me. I mean i have done coding, quite a bit of it. I have written long programs, sometimes even before pinning down what i will be doing, i have dived into code. But to think of something, finding out what all you need to learn to accomplish your mission and the final execution to create a product, all within 24 to 48 hours. Its exhilarating
to say the least. Almost a adrenaline rush. Pushes you to think beyond, makes you feel you are meant for something bigger, better and you have so much more to contribute.

I have never been of the fast kind when it comes to creating something. I like to think about what i want to do, learn what i need for it, then plan it and yes, executing it should be fast. The best part about hackathons is that you have so many people around you to tell you that you are wrong. Correct you, help you and improve you.

Here is mostly what i used to think before i wrote any piece of code.

1) Why? 

2) How? - Select one from multiple solutions available

3) Learn what you found out in step 2.

4) Create a modular framework for whatever you wanna write.

5) Code.

Here is what usually happens in Hackathons

1) Why?

2) How? - Select the first or the quickest solution available.

3) Very less time to learn, google for existing code snippets and learn while you copy.

4) The quickest way goes, no time to think over modularization.

5) Keep coding, which btw you started somewhere around point 2. 

Its not ironic if you see that the events are named hackathons. But the best part is ahead of us. After the hackathon is complete, everyone is a winner.  You are always proud if you did something meant to take long times in 1-2 days by whatever means possible. Whatever you learned in the 1-2 days can never be taken away from you. And you get to meet and bond with people so passionate about what they are doing, that’s always a nice experience. 

I think everyone who is techie and wants to have a larger than life experience, should go for a hackathon. 

“You have so much potential, only if you had a platform to reveal them” : Me

Siri :)

DropBox SDK and Android

So recently i worked on Dropbox SDK provided by the Dropbox team and tried to integrate it with an android app. Wouldn’t say it was easy but i got through it, and they the result is worth the time spent. :). I am writing this for anybody who wants to use dropbox api and i bothered by the wide spread info.

So here is what i did.

1) Get the idea of your app in place and get the code ready. (apart from DropBox integration part)

2) You need to register yourself on DropBox to be able to use their API`s.

3) You have to add an app there. This will give you an app key and an app secret. There is a small trick though. DropBox doesn’t allow you to spread you app without their permission. So with the Keys you just got, you can only use it for development. When you think your app is ready to be distributed, you have to pass it through them to be checked for their standards and best practices.

4) Assuming you have your app registered, you should download the DropBox SDK. This includes the libraries required to use DropBox and it also includes an example app.

5) Go through the example app. Its pretty decent. It doesn’t showcase all the functionality available though. You can find out what all you can do with the API here.

This is all you need to get started. After this point, its all you and your app.

How i did it comes next.

One problem with DropBox API is the authentication screen is to created by you. You ask the user for username and password. You pass them along to the respective authentication API. Its not a very good way to do it as the programmer can save the usernames and passwords on the go. Its not allowed though its not clean by any standards.

The API itself is damn simple and easy to use, with functions like “put(file, path)” to put a file in your DropBox and “get(file, path)” to get a file from your DropBox. The problem i faced was to keep a user logged in even as the activities change and not to ask the user to enter his credentials again. But i guess it was more of a lack of knowledge on my side then the problem with the SDK. Once i figured out that a session class can do the job, it was more or less about implementing the session class. Still i feel the ease to as we have in Facebook API is missing. There is a lot of scope to do better and i hope things are in the pipeline. Here are a few screen shots of how i solved my problem of using DropBox for saving a single or multiple photos.

There is still work to be done on the app. But as they say, its the Journey that matters the most, result is just a byproduct.

Testers and Android

Continuing to my last post. Today i want to discuss how to make android apps which are stable, fast and efficient on resources. By now we should understand, mobile platforms are different and need specific tools as well. But whats common is, the need to optimize resource utilization. Again, like for iOS, we discuss the following topics for Android.

  1. Feature Testing
  2. Automation
  3. Profiling for leaks
  4. Profiling for CPU Usage
  5. Profiling for memory usage
  6. Allocations

Before you start reading further, i recommend reading abut the instrumentation class in Android documentation and DDMS. DDMS is a great tool provided by android specifically to profile your application and is for our good luck, very nicely integrated in Eclipse.

Feature Testing is usual manual testing. It doesn’t require any tools and so is the same as how you do it on Desktop Application or on iOS.

Automation : There are many tools out there to do automation on android. AutoAndroid, SeeTest, Calculon, Robotium and many more may be. This image taken from Vendor Benchmarking depicts nicely the comparison of the first three tools.

I would personally say, Robotium, having used it, is very easy to start with. Being a library so can be imported directly to your project. You can also create a separate test project along side your app. This is the normal way of using it. In order to use it for one click automation, you need it be a totally independent project. And so you need to write a wrapper above Robotium which can be bit of a pain. All the above mentioned 4 automation tools solve different problems and you need to pick one based on your product and your requirement. This goes without saying that all of these are black box testing tools and may or may not require maintenance as you go along developing.

Lets go to profiling, Leaks in your android are hard to find. I couldn’t find any useful tool out there to successfully monitor leaks on android. There is no equivalent of Instrument Leaks of iOS for Android. But there are other ways you can try and monitor. Instrumentation class provides us access to the memory usage of your app at any point of time. You just need to make a call and you can get the memory usage. Now using this function you can track the memory usage before and after the code you want to monitor. I understand its hard to find small leaks through this approach but its the best i got. Let me know if you find something better :).

While we are on memory usage. Lets go through memory utilization as well. There are many many ways to get to know your apps memory utilization. DDMS is the easiest, just select the DDMS view and your app from the left side pane. Then there is Instrumentation class, you can use it to track the memory utilization from your code. Then there is another way, your adb shell. You can use many commands to do so, top, dumpsys meminfo proc, procrank, vmstat. There is another tool named smem but you have to separately install it.The tricky part is, once you run the above commands, we get many memory values and its not very clear which one is useful

  • Vss = virtual set size
  • Rss = resident set size
  • Pss = proportional set size
  • Uss = unique set size

Different command line functions would give different outputs.

Because large portions of physical memory are typically shared among multiple applications, the standard measure of memory usage known as resident set size (RSS) will significantly overestimate memory usage. PSS instead measures each application’s “fair share” of each shared area to give a realistic measure of the activity of a system during boot. Hence PSS is our best shot for the memory usage by our app. I use procrank as it directly gives me the PSS value. Sometimes if you need more in depth output of dirty pages, you should use dumpsys meminfo.

Profiling for CPU. This is a bad one as i know only one way to do it. Use the top command and see the cpu usage. It works great for me tough because thats all i am looking for :).

Allocations again is something which can be done in multiple ways. I particularly like the DDMS solution for this. You can also use dmtracedump.exe and traceview. Whats good about android allocations is, you can create a dump file for the period you were monitoring your app for, and store it to be viewed later or used later or compared later. its an amazing debugging and testing tool and you should definitely read more about it.

All along the way i have assumed you have the knowledge of what is logcat and how to use it. Its basically a console output of what your device is doing. If you are reading this, you must already understand that for mobile testers, you need to get close to the product from the start and just UI level and feature testing is not enough.

I hope this was helpful. In case i mentioned something wrong or you want to ask anything, drop me a mail at maheshgattani@gmail.com

Testers and iOS

Before i say anything else i want to mention that these are my views. So they might not be coherent with yours. Well you just gotta deal with it.

So about testing on iOS. Let me first start with just testing on mobile devices. As a tester, you have a few more responsibilities as compared to testing desktop applications. Let me pin down what i think are the requirements to make up for a comprehensive testing and assuring a stable and optimal product across revisions.

  1. Feature Testing
  2. Automation
  3. Profiling

But when you talk about mobile devices, things unfold in a bit more complex, narrowed way. Also testing has to be done along side development, otherwise it just wouldn’t work. Waterfall model of development is not at all suitable for mobile development. For mobile testing, the list goes like this

  1. Feature Testing
  2. Automation (How?)
  3. Profiling for leaks (We wanna be very memory efficient right?)
  4. Profiling for CPU Usage (We don’t want to choke the device now do we)
  5. Profiling for memory usage (Again, cant choke the device out of memory)
  6. Allocations (Later?)

Now whats new is that in Desktop applications, you don’t need to be so particular about profiling. Fair enough is good. But for mobile apps, you need to be sure you are not doing anything to use extra resources. Reason obviously being we have limited resources and more importantly, there are other apps as well who want those resources. We need to live in harmony remember.

Another thing to remember for a tester on mobile devices. If you go to a developer with “Our app is crashing”, “We are using too much memory”, “We are using too much CPU”. Its not good enough. You need to figure out whats causing that behavior. Is memory the culprit, is CPU or is there some wrong call in the code? And for this you need to profile the builds at the same time you are testing it. You need to get hold of how to use allocations to figure some things. For the testing to be comprehensive, you need to be hand-on with all these things.

Except for manually testing the features, everything else would require tools. This is again something which would be mobile OS dependent. But the bottom line is, we need tools for automation, profiling leaks, CPU, Memory Usage and tracking allocations. Also we need to save the traces (dumps?) of the runs we found problematic, so that developers can look at it and more often then not figure out what the problem is.

Now lets talk iOS testing.

We will keep Automation for the end. The good news is, Apple provides us with tools for all the profiling and allocation tracking in a nifty Mac application called Instruments (remember instrumentation?).It ships with XCode. You have many many tools in Instruments for instrumenting your app. Starting with activity monitor to automation. Lets talk a bit about some of them and how they are useful for mobile testers. You can also go through the list here.

Activity Monitor : Use this to track the system workload and also virtual memory. This is basically a counterpart of Activity monitor for Desktop on iOS. Use it as you use activity monitor.

Allocations : Monitor memory and object allocation pattern.

Leaks : This along with allocations is used to track memory leaks.

CPU Sampler : Use for CPU profiling, you can compare the workload of your app vs the whole system.

And there are many more tools in Instruments which you can use to profile your app. The whole kit is in there. It sure is a pain to start but it makes your life so easy you cant even imagine. Now the best part, you can use these profiling tools on the actual device as well as on simulator. You can create and save the dumps anytime you want, and not to mention, load it later.

Allocations, i want to talk about allocations once again. To start with, it might look like why does a tester need to worry about allocation patterns. Well for mobile devices, you need to help the developers, and in turn the product in finding out whats causing the problem. Allocation lets you do that. Using allocations you can find out which function consumed most amount of time, which function was called most number of times and so on. This information is very useful. Even in case you don’t understand it, remember to track this information for your dump, because it will make life easier for the people debugging the code based on your dumps.

Now we come to automation. This is a bit tricky one because of the requirements of automation systems. Sometimes we want one click automation which would do everything for us and generate the reports, sometimes we want the automation system to be in CI (Continuous Integration). Most of the tools available right now don’t allow these upfront, well not unless you make some tweaks of your own. Most of the tools are UI automation, and given the scenario, i would strongly suggest doing UI automation, because in mobile apps, its the feel that matters. White box automation is always good to have, but in mobile apps, black box automation is a necessity. I have been through some of the tools like FoneMonkey, Frank Framework by ThoughtWorks and the Automation Instruments (shipped in with XCode by Apple). Where Automation Instrument and FoneMonkey are completely UI driven automation, Frank Framework has the capability to do White box automation. Lets talk about each of them.

FoneMonkey : Easy to start with, record and playback, option to change and save the scripts on device(Yay!!), black box testing, found that a few commands got executed without actions (Ouch!!), required to be added in your source code (Eeee!!!) and not very accurate.

Frank Automation : Assume you have a server sitting inside your app and you can communicate with that server. White box testing, Reasonably Hard to start with and maintain, Can very easily be used in CI. Required to be checked in to your source code, with a server sitting in your app, you can basically do anything in the app using white box testing off course.

Automation Instrument : Black Box Testing, One script at a time execution, No interference with code is required, Profiling tools can be used while running automation instruments leading to automatic generation of dumps,

As i said, none of these are a sure shot winner. All of them can be tweaked to be useful. I would recommend frank for white box testing and Automation Instruments for Black Box.

CI with Automation Instruments : Automation Instruments uses javascript as the scripting language and runs one such script at a time, generating a xml output file on the go. We can use apple script to automate Automation Instrument itself. i can say its very much possible having done it myself. After this you can use Automation Instrument for CI as well.

This is a very small outline of what is the minimum required for testing and what are the option to get it done. This is mainly for iOS thought the concept pass the boundary can carry on for android and other mobile platforms as well. Hope this was useful, for any clarifications, mail me at maheshgattani@gmail.com.

Experiment with Android

So today`s post is about my first experiment with android development. Its like they say “The best way to learn is to do it yourself” or “The first step is the most hard to take” or in my words “to be the best, you have to pass through good and better first”.

Coming to the app and what i went through. The app is as simple as it can be, A Facebook album viewer for you and your friends. Easy to start with, it allowed me to learn two things, Android app development and Facebook SDK for android. Lets talk about each of them.

Android: Oh My, if you have tried your hands on iOS development, it might not be so easy to just switch. The first and the easiest part in iOS is to create your views. You start the Interface Builder and its just drag and drop, as easy as it sounds (well for simple apps atleast). But in android, the drag and drop thing doesnt work as simply, you have to write most of the things in the xml file manually. That`s a pain. And doing it for all the activities takes a lot out of you.

After that things are a lot simpler and similar to the way you code anything mobile. There are lot of view available and you can use any number of them on a single activity. You can hide the not needed ones, create views on fly or remove them. If you are down with the UI, its more about the concept then the code.

A simple UI View can look like this with some image, some button and some text

And a bit more complex can look like this: an image, multiple texts, gallery view, list view.

It takes time to get used to the way Activities behave, how to navigate between them, how to communicate between them. This was the second problem i faced. Once you figure this one out, the concept of adding view becomes simple. I actually became so comfortable that i added multiple new views against my earlier mocks.

Next problem i faced was how to let views interact with each other. What if you want one view to be updated if some changes are made to some other view? This is actually very simple using adapters (notifydatasetchanged() method)and comes in very handy to improve your user experience. In this activity, i was changing the gallery view if the list view changed, and changing the list view if the gallery view changed.

You need to remember, views and activities are two different things. An activity can contain any number of views. And a view can be used as an activity.

You can go through the code at https://github.com/maheshgattani/DownloadFacebook

Now the Facebook SDK. Man o Man, this is the reason Facebook can never be the next Orkut. They just made it so simple for developers. Now its not only Facebook people working for them, they have people like me also. Its just the simplest thing. Go to Facebook Developers page, setup a test app, get an app ID, download the SDK, and you can start writing code. The first thing i figured when i started writing this app was Facebook SDK is the least of my worries, because its just so simple and easy to use. and what more, Facebook has provided tools to test a few things while you are working on them.

Android vs iOS

I have been having these long discussions with friends and colleagues about android and iOS. Which one is better? Which one has a better future? Which device to buy right now, IPhone or Android device? I have heard so many arguments, arguments from hard core android fans and arguments from apple fans.

I for one, believe iOS is in a very very good state as compared to android. Also, when we say iOS, we can assume the device and the OS as the same because of the integration apple provides. When it come to Android, we have to think of the OS separately and of device separately. But lets see what each of them has to offer.

For Developers?

When we talk about the developer view, we need to take care of 2 things. What all we can do and how easily we can do that?

Android is a clear winner in what all you can do. Being an open source, it provides such an environment that you can essentially do anything if your device permits it.

iOS is a restricted environment. Somethings are not meant to be changed because the OS is designed that way (read Flash, Any app which can be used to run other programs is not allowed). Apple has a screening process, so just because you developed an app doesn’t mean you can put it on App store. You need to follow some strict guidelines only then you can assume apple would approve your app.

iOS is a winner when it comes to how easily can you do something.

To start with, the toughest part being creating the UI experience. iOS development SDK provides you with a tool for interface building. A very easy to use and effective tool. MVC(Model-View-Controller) implementation might be a bit tricky to start with but is very effective as well. The code goes in Objective C which is just another OOP language and you tend to get used to it as you use it. Also since there are only a small set of devices with iOS, building an app on it takes a lot less of thinking as to what all devices you support.

Android lacks heavily in terms of UI experience. Without any standard interface builder, it is a haunting task to get your UI as you want it to look. Writing whole or part of views in XML might not suit all the users. The code goes in Java which is very well known. Also, with so many android devices in market, it might be a painful experience to figure out which all devices you want to support. And since the OS and device are not so well linked, you also have to think about the device specification when you are building an app.

For Users

For users, things boil down to ease of use, User experience and ability to do more.

iOS, for me, is the winner when it comes to ease of use. The devices with iOS gives you an easy feel to everything. Be it accessing things, be it closing things, be it downloading music and videos, be it downloading new apps, almost everything. For a person who is not very technical, iOS is far far easy to use then it android counterpart.

User experience, again iOS. This is true because of the tight integration between the device and the OS. This is an easy one, just try playing a game in android and same on iOS, the difference is visible. Also, android as a platform isnt as stable as iOS is. The apps on android arnt as stable as they are on iOS (read apple`s filtering process).

Ability to do more? This is tricky, mainly because android as a package does provides you more stuff to do. But iOS provides you more app to do search and use from. The difference isn’t very apparent. On the contrary, you can do almost anything on both the OS`s. You would find app for everything on both the platforms. As of now, you have many more devices to select from in android and many more app to select from in iOS. My vote goes to iOS, being more stable and with lot more apps.

Going Ahead

Both the platforms, iOS and android, have great future. iOS 5 has been announced and it includes lot of nice features. Android 3.1 (Ice cream sandwich) is out which is the first in line to supports both tablets and handsets. Though Android is behind iOS right now, i expect it to match iOS sooner than later. With contributions from everywhere, android is developing fast. We have Microsoft “Mango” coming. Mobile field is very exciting right now and rapidly progressing.

What to buy?

My vote goes to iOS mainly because of the tight integration. The iOS devices are high end when it comes to specs. The user experience is amazing as compared to only good for android. Android OS depends a lot on device hardware. Samsung has done some rights with Galaxy series. It basically boils down to

“Freedom of choice OR freedom from choice”

read

“Android OR iOS”