Google+ Badge

Wednesday, August 24, 2011

Android and iPhone apps in sync - here are the code results

I sent the Android version of my app off to QA yesterday. Both the iPhone and Android versions are now in sync and here are some code stats.

*.m   100 files   589,431 bytes
*.h   109 files   123,079 bytes
      =========   =============
      209 files   712,510 bytes


*.java 97 files   633,177 bytes

A lot more comments in the Java code as I have JavaDoc comments over each method but even with that the code base is a lot smaller and a lot less files. Anytime you have less code and less files it is easier to maintain and will tend to have less bugs.

I was surprised at how quickly the conversion went. A couple of things play into that, first I started on the more difficult of the two platforms - the iPhone. It is more difficult due to my experience with Objective C and the Mac in general. Some things are easier on the iPhone such as only having one screen size to deal with. Second once you have the database schema in place and the logical layout of the program ready to roll you are doing more straight coding and less designing.

Doing double development has some benefits. There are things on each platform that are pretty easy to do. They force you to look for a solution on the other platform. I don't want either version to outshine the other. The end user should be able to pick up any device with the app installed and be able to use it. There are differences in button placement - iPhone on bottom, Android on top - and the iPhone always has the "Back" operation as a button on screen where Android users know to press the dedicated back button on the device.

Programming differences

  • I found programming for SQLite much simpler on the Android. I pretty much had to build SQL statements by scratch on the iPhone and pass them off to the database. The Android helper methods make this much easier. Android made it super simple to handle cursor data in a scrolling list. All of that had to be written manually under iOS. 
  • I had to write the multi-part entity code to send images to the server on the iPhone where I was able to use the Apache libraries under Android.
  • Hiding buttons on a toolbar is as simple as setting visibility state on Android. Under iOS I had to totally recreate the toolbar for each unique button layout. Some views are reused for editing vs. viewing of the same data. I needed to hide buttons such as [Save] in the read-only version.
  • The home screen with icons laid out in 2x3 for portrait and 3x2 for landscape was easier to do on Android as I just defined two XML layouts and put them in the proper directories. All of this had to be done in code on the iPhone although I was able to use the animation framework to have a cool looking transition under iOS that I did not port to the Android.
  • Handling JPG images was easier on iOS. Pretty simple access to camera, gallery and image viewer. It was also simple to get to the raw data to store in blobs under SQLite.
  • Doing background / busy threads is much easier under Android. On the iPhone you have to control everything, shut off the UI, get the spinning gear going, dimming screen, etc. On Android I just put the busy work in an async activity and invoked it.
  • Date manipulation is much easier in Java. The method names make sense  startDate.after(endDate) where it is [startDate timeIntervalSinceDate:endDate] > 0 on iOS. 
  • Settings seconds to zero startData.set(Calendar.SECONDS, 0);  for Android and    NSTimeInterval time = floor([startDate timeIntervalSinceReferenceDate] / 60.0) * 60.0;  startDate = [NSDate dateWithTimeIntervalSinceReferenceDate:time]; for iOS
  • iOS wins for speed of simulator (much faster than actual device) and speed when running in debugger but Android wins for actually being able to see variable values, do ad hoc expression evaluation while in debugger and separating output log messages into tabs in the LogCat output window.
  • Android wins for being able to run on a multitude of devices via one code base. I have run it on various phones, the older Samsung Galaxy Tablet and a Motorola Xoom. The iOS version is for the iTouch and iPhone. I can run it on the iPad but only as a double pixel app. Some call it fragmentation but with very few program tweaks having the ability to run on a variety of hardware is just fine with me. Heck I do that with PC programs all the time. I rarely know the monitor resolution up front. Use the space you are given.
  • Easier to view the SQLite database under iOS. I used the SQLite Manger for Firefox on the Mac and was able to point to the DB in the simulator directory and look at all my tables with ease. On the Android side I had to export the DB from the device to a temp directory and use SQLite Database Browser to see the table contents. 
  • Releasing to the clients is a huge win for Android. I can just put it on any device I want. I can submit it to Market and have it available in minutes and the same for updates. For the iPhone I can submit it and wait until Apple approves it. I can not give our clients a solid date as to when that will happen. Same thing for bug fixes. This means our Beta cycle will be pretty simple on the Android and a royal pain on the iPhone. Our clients are not local, I can't just have them stop by for new version. Doing it ad hoc might be possible if we can get a doctor to understand iTunes and how to drag and drop things I send them along with getting their unique phone ID to me so I can provision it and build it into the app. This is a gigantic pain.
No matter which device I was programming against I spent a lot of time in Stack Overflow looking for answers. As I have gone back to the iPhone side to do some program tweaks and add missing features I put into the Android side I again realize how much Objective C and I don't think alike. I still have to look up method names as they just don't roll off my brain. Trying to think how many staring '[' I need before I get to type code just seems silly. Having to type multiple lines to do simple things gets old.

I really don't care for Xcode, I really want tabs that keep open the code I am looking at instead of reusing themselves as they see fit.

Even though I was used to it with C/C++ I really don't like having two files for every object - the H and M files. I just want to add a method and have it there to use instead of adding it twice. Then you have the fun of static variables you want others to access which is tons of lines of code.

It will be interesting to see how the users respond to the application. Will any switch between devices and will they spot differences they don't like between them?

The application is used by anesthesiologist to do charge capture and billing. You have to be a client of ours for it to be of any use to you. All you could see without that access is our login screen so I can't give a link the program for anyone else to give me feedback on why I am insane to prefer Android over iPhone or to tell me where I totally hosed up doing something on either platform.

Tuesday, August 9, 2011

Remember when hardware was fun and exciting?

Back in the day - this would be the 90's - InfoWorld, PC Week (now eWeek), PC Magazine and Computer Shopper were huge publications. They had massive hardware reviews, dozens of printers, 10 graphics cards, 8 sound cards, etc. It was a blast to read. The industry was exciting, new hardware was on the way every month. Now they are all electronic only or pamphlets. Printers cost $100 and you can hardly go wrong with any of them, just get what is on sale. Graphics cards are down to two major players with not much excitement around them. Hardly anyone cares about the sound card, use what comes on the motherboard and move along.

To me this is all pretty sad. I still build my own machines. Every time I think I can just do something off the shelf I can never find what I want. I really want a better sound card, I want something above the mid-line graphics card, a SSD drive at least for the boot drive, a big case where I can add things and a power supply I trust to run the whole thing for years to come. I do buy off the shelf machines for relatives, they don't play games or care about the best. By the time you buy an official copy of Windows you can't build one for them at the price you can get from Dell or random Best Buy vendor.

Since magazines don't have new hardware innovations to talk about and there seems to not be much in the way of software innovation either they have been spewing out top ten lists and comparing everything else to Android device X and Apple device Y. It has gotten damn boring. They also keep running "Study shows iPad will be the champ until 20xx". Give me a break, how can you predict any of that? Some of this stuff came out of nowhere and took the world by storm. In 9 years it will be ancient stuff and something new will be kicking it in the tail. Did they predict this same crap for the BlackBerry? You bet someone did. Just filling space so they can publish some article every day. Content has fallen off and most of the news is now just noise. I end up deleting most of the articles the minute they hit an inbox. Even Slash Dot articles have been more "maybe this will happen" or complaining about DRM or a movie review.

I want some excitement in the PC industry. We are not getting it from hardware or software. Both Lion and Windows 8 appear to be nice incremental updates but nothing to wow your socks off. Everyone has a color printer, LCD monitor, plenty of processing power and a big enough HD. Heck I just got a USB 1t HD for backup for all of $70! Terabyte was unheard of in a house a few years back.

My machines at work and home compile my Java and Objective C code in a matter of seconds. My phone beats the power of machines I had not long ago. My Xoom tablet does pretty much anything I need for the web and plays some decent games. I still enjoy playing Wii sports Tennis.

Tablets are cool but they are just what we had in a different form factor and we use our finger instead of a mouse. I am not doing anything that ONLY a tablet could do making it a must have. Sure some games let you tilt it to move your character but I had that on the Wii with its remote. I like it but it is not earth shattering. Most of the time I use the tablet it is just to read content from a website on the couch.

People talk about all the apps available on the Android Market and the Apple App Store. I don't know if you have checked many of them out but most are pretty crappy. You hit a block buster from time to time like Angry Birds or Monsters Ate my Homework but honestly most of the games are fun for just a few minutes. Even those games are just level after level of more of the same. They don't hold your attention for nearly as long as a reasonable Nintendo DS game. Games are not easy to write, they are one of the harder things you can do for any device as you are going to push the limits of the hardware. Stuff is being cranked out but you can tell. Some may be pretty but there is no substance behind it.

Doing a productivity app on a mobile device is also not easy. Typing much on any of them is just not fun. I don't want to do word processing or spreadsheets on my phone. I can stomach them a little bit on my tablet but really I consume data and don't create data on those devices. I can type 100+ WPM on my computer so I go there when I want to create much of anything including graphics. I am not finding must have productivity apps on mobile devices either.


Guess I am going to have to find my excitement elsewhere but I not sure what it will revolve around. Anyone have an idea where that could be?