Google+ Badge

Thursday, December 12, 2013

How do you respond to "Who cares? It's going away soon anyway."

I am hearing this more and more "Who cares? It's going away soon, just hack in a solution!" Guess what? Nothing goes away soon. Unless the replacement is fully written and ready to ship and the users have no choice but to upgrade then it is going to be around.

What is your response when this dilemma is posed to you?

I try my best to avoid hacks. I want to use the best possible coding practices when possible. So, when are they not possible? Let's say one of your apps has been internationalized and localized. You are working on an second company app that has not been. It might drive you crazy to add yet another hard coded string to that app but doing it right and starting the whole internationalization / localization process is not going to pay off in this situation.

Maybe you are on an app that has styles mixed in to the HMTL instead of being in CSS files. Not hard to create a CSS file right? Nope but it might create large changes to the build / distribution process thus doing that towards the end of a release cycle might not be the best idea.

Maybe you end up in some Java code that only uses Vectors where is should be using List and ArrayList with generics. If the collections are localized then I would probably fix them.

I find it depressing when the development staff has given up and goes into hack mode because everything is about to be replaced with a new design. I know code outlives your every expectation.

I was working at a company three years ago that was converting from Java via WebStart in the browser to C# with WPF. For some reason the CEO hated Java even though it was half their income with the other half being the C++ version of the product. Java ran on Windows, Mac and Linux. I worked on the C# product too and left for other reasons than the switch. I don't mind C# although I did not feel it was the best solution here. They pretty much only wanted hack fixes to the Java stuff.

Three years later and guess what? Yep, the Java code is still running in the field. It is taking much longer to replace than originally thought. They have moved it to Java 7 to keep up with Oracle and bug fixes.

I have seen this happen way too often. With the web it is easier to kill something. If you replace all the JavaScript on your server the next time the user hits your web page they get the new code. They don't get the choice to continue to use the old stuff. Mobile is close. Most folks update their apps unless you toss in some new crazy permissions like read all my contacts when you are a simple game. Desktop is a bit harder. Using WebStart allowed us to force the upgrade. On the Mac you get update notifications which is nice. On the PC you pretty much get patch notifications from Microsoft and then it is up to the vendor to write their own. Adobe likes to patch stuff.

As a professional programmer I like to treat all my code the same, like it will live for a long time. I don't want to fall into the hack in in trap. Design it, write it, test it then check it in. I refactor things when method and variable names are getting confusing or no longer reflect what they do. I move things into new objects when the line count in current objects gets out of hand or where a new object or base class just makes sense.

Monday, December 9, 2013

Thought about dipping into Windows Phone dev but it requires Windows 8

I do Android and iOS programming already and I thought about dipping into Windows Phone just to test the waters. I have done C# WinForm and WPF development in the past so I know my way around Visual Studio and C#.

I did a little research and you must have Windows 8. I just am not in the mood to do that. I support my family and my extended family on all things technical. I use TeamViewer to remotely take over their machines to clean up toolbars - oh man do I hate toolbars - and other issues.

Every machine, as of last Saturday, that I support is runnings Windows 7. Finally they are all in sync. I don't want to move to Windows 8. It seems a big MS mistake attempting to combine touch screen and desktop into one platform. I have buddies who have used it and don't like it. It may be more end user friendly but it is less technical dude friendly.

Stinks, I probably could have had some fun playing around with Windows Phone development. Who knows, I might have converted on my apps to it and put it on the store. At this point I am saying NO to Microsoft. My hardware can easily handle Windows 8. I built the machine myself, which is what I have done for years.

If the upgrade was cheap I might consider running it in a VM. But MS charges quite a bit for an OS thus they are keeping me out of the experimentation phase. Real shame MS, you want more phone developers but things like this keep me away.

Oh, just in case you think "Well you bought a Mac for iOS!" Nope, I only do iOS stuff for work, not for my personal stuff, so I only do it on my work MacBook Pro. Heck I could probably Hackintosh my PC via a VM and get a Mac running cheaper than Windows 8.

Updating my first Android game. Taking on a different perspective

I wrote and published my first Android game in a week between jobs. Always good to take time off between positions so I took a week and learned Android and wrote a game. It made enough off ads to pay for entry fee into the Android market plus I learned the Android SDK and have been working mobile jobs since then.

The game had hard coded images thus it did not scale up on tablets or larger phones. I have been recoding the app over the past several months. First I redid all the graphics using Canvas drawing code. Consider them vector graphics instead of PNG files. I can pass in a size to the drawing routines and it will draw all the games pieces to fit. I have been testing on my Xoom, Nexus 7, Note II, Galaxy S3 and original Galaxy. Right now all the game pieces are drawing properly and the game code is in place. The family is playtesting the game.

I have some issues in the help screens that I need to clean up that I found late last night on the S3. Probably get that up and going this evening.

Next I want to add a multiplayer mode. This will not be playing on different devices and not be playing at same time on one device but one player attempting to solve the puzzle then handing it to the next player and the winner will be the one with the shortest time. I have a lot of ideas around this mode that I will work on once help is running smoothly.

Before I ship I need to integrate an ad network and test on all the devices again.

Great, that is all background but what about the perspective change? The first cut and release was all about speed. Getting the game working and out the door. Android tablets barely existed at the time. I tried to make stuff generic but was learning the SDK at the same time so things were hardcoded. Now I am weeding out all the hardcoding and really using the power of Android such as styles.xml, canvas drawing code, various simulators and more generic programming techniques.

At first it was really cool just to say "I have a game available from the Play Store!"Now I want to say "I have a game and it scales and plays on you device and you can play it with friends!"

The help system was confusing. People could not learn how to play. It is much better now as it uses the full game board to show you how to play instead of screen shots snippets in dialog boxes. Even doing that aided me in fixing other areas of the code.

I am taking my time. No need to rush, get it done correctly and test is out on a lot of devices. The game play is in place and the single player scoring system works. I am pretty happy with the graphics although I have been tweaking them a bit here and there. While the single player aspect is nice I feel the multiple player side of things is going to make a much bigger impact. People like to play together. A friendly competition is always a bit of fun. I hope this area keeps the game installed longer on devices and earning more ad dollars.

The more I play the game the more things I see to tweak. My son was playing last night and found an issue. Soon I hope to be playing against him. The more I play the more ideas I have for the multiplayer mode. My first thoughts are not the direction I am going to take. Some of it I figured out while doing the new help screens. It is amazing what you think up when you are forced to relook at the game.

I plan on splitting some of the code out into some other objects too. The main Activity is getting a bit large for my tastes. Most of the code is drawing things so I will be passing a Canvas into objects so they can do their part of the drawing but that is not a big deal. I won't hold on to it, just pass it in for the drawing to occur and be done.

So what is the game? Not going to say until it is ready for release. The current version in the play store, which is a few years old, does not run on a lot of newer devices.

Funny running it on my original Android phone, the first Samsung Galaxy that is now my son's primary device, and how small everything looks. It plays fine on that but once you play on the stunning display of the Nexus 7 everything else looks kind of crappy. Cool how everything scales up and looks fully detailed as I am not blowing up pixels but I am drawing to scale with all the pixels available.

A game makes you use parts of the SDK you never touch while doing business apps. I have not used sound or off screen images in a business apps. Most of those have multiple activities and fragments using standard Android view based controls. I have written custom Android controls that needed to scale but nothing with a ton of graphics. I have not need to access data from styles.xml programmatically in the past. The Android SDK has a lot of power and is very flexible when it comes to running on devices of various sizes.

If the app does well enough on the Android store maybe I will pick up a used Mac Mini and convert it to iOS. I think it would look nice on an iPad and I should be able to port over the drawing code pretty easily. I have done a lot of iOS business development so I already know my way around Xcode and Objective C.

Wednesday, December 4, 2013

Bought a Nexus 7 - my thoughts

NewEgg sent a coupon for 10% off tablets. It was time for me get a Nexus 7. I have a 3 year old Xoom that gets a ton of use around the house but I wanted something smaller, faster and with a better screen.

The Xoom was really starting to show its age. It was heavy and slow. Holding it took two hands. Sure, I would balance it with one hand but then a cat rubbing on my elbow or a kid knocking a knee into it and I would get bonked on the head or have it fall in my lap.

I was using the Nexus 7 (old style) my boss loaned me for some code testing at work. From that I knew it was the right size to be held in one hand. I also got to see how the multiple accounts worked. This is something else the Xoom does not have as they are no longer updating Android for it. I could root it and get something on there but I think I will leave it alone for now.

I had a number of goals for the Nexus 7. I want to read more and not just technical books but some biographies, non-fiction and sci-fi. I have read books on my phone and the Xoom. Again the Xoom is a bit big and heavy to hold for long periods of time plus the screen is just not that great. I grabbed some free books from Amazon via the Kindle app. There are a ton more free books than the last time I checked. It used to be the old classics but now they have a decent selection of newer books.

The screen of the Nexus 7 is impressive. I used the default Kindle font and sepia colors. The device holds in one hand as it just a bit bigger than a normal paperback book as far as height / width but obviously no where near as thick. You don't have to worry about losing your place and having the book close if your fingers slip or you drop it. I found reading on this device to be very enjoyable and plan to read a lot more books on it.

For gaming it is a really good size too. My younger son really likes it over the Xoom. Both devices get used nightly for looking up internet items, checking email, weather forecast, reading books and games. Setting them side by side really shows how much nicer the high resolution and brighter colors shine on the Nexus 7.

Being 3 year newer technology it is a lot faster than the Xoom. Bringing up Chrome on the Xoom and waiting before you can type in your search was painful. The internal browser was a bit easier but it did not share my bookmarks. On the Nexus Chrome starts up quickly and lets me get right to business.

Having multiple accounts is a boon and a bane. I like being logged in as me and only seeing my email and having my home screen look the way I want it. When I install an app it installs to my account. We are not sharing a game so my high score is mine. The levels I complete on games are mine. The bane? I have to install the app under each account if each account is admin based. I just want to pick from a list of installed apps and let them appear under certain users. Not a huge deal.

Battery life is good too. It gets used a ton and holds up well. KitKat installed a few days back. I have not noticed anything super spectacular about it. I did like the old color for the battery and time, not a big fan of white, but otherwise it has not caused any issues.

I enabled developer mode of course. Connected right up to my computer and I have been able to install APK files for the code I am developing.

So far I am very happy with the unit. It is the proper size and weight and the screen is really impressive. It is going to work for book reading, gaming and developing. 10% off was the icing on the cake.

Wednesday, November 13, 2013

Life with Mavericks - lots of bumps in the road

I installed Mavericks on my MacBook Pro at work. It has been a very bumpy ride. I really wanted multiple monitors to work better, and it does to a point. I have been able to unplug from my second monitor at my desk, move the laptop to a conference room, connect to the TV there and have it mirror the image then reconnect to my monitor when the meeting was over and have it restore the window positions. That is awesome.

The problem? If my machine goes into a deeper sleep, say when I lock and close it for the night, the next morning or maybe even after an hour lunch and an app window will be hosed. Outlook will disappear into the upper corner and you can move it but no resize it. I have to kill the app and start it back up. It has happened to Chrome, Outlook and VMWare fusion so far. Can't find a definite pattern but it sucks when it happens.

I installed Slate which allows me to take a snapshot of my desktop and restore it. I still have to kill Outlook as the restore is not strong enough to put it back where it belongs but after I restart Outlook doing a restore puts it back on my primary monitor sized correctly. I really hope they fix this mess with an update to the OS.

Next up is Apple decides to wipe out or install older versions of tools such as perl, java, etc. The way the base operating system works is you install common libraries and other tools use them. Of course if you have an old library version things go bad. Also if it used to find the library in one place but it moved then things stink too.

I use xml-grep a lot. It was not working post Mavericks. I updated perl and it still did not work. I reinstalled Twig and no go. I looked at where it was attempting to load things and they did not sync up. I ended up doing a copy + paste of the XML/Twig stuff from one perl directory to another. While doing all this fun something dropped a skeleton .bashrc file in the root directory which load before my .profile so iTerm did not have the proper settings.

MacPorts did not work for the first few days after Mavericks came out. They fixed that pretty quickly but it was failing on the SVN 1.8.4 update. I finally just downloaded the tar file and put it where it wanted and was able to move on. Right now MacPorts is updating and installing as expected but I know they got bit by another Apple tool shift.

Look, DLL hell was no fun on Windows. Most ended up including their DLL copy in their own directory. I did not run into issues upgrading Windows like I have on the Mac. Yes, this only applies to developers (probably) as most folks are not dealing with command line tools. Heck the graphic artist I have worked with had never seen this magical terminal window I spoke of. The problem is Apple is just not very developer friendly which makes me mad at them and hard for me to recommend them to family members.

At this point I am back up and running. I have to kill programs at least once a day to get them back visible on the screen and not is some weird docking mode. That has the potential to affect a lot more than just developers. I am sure I will get bit by another command line tool that is not working as expected soon enough. I am trying to get past all the surprises so I can just do my work.

Wednesday, October 23, 2013

Mavericks, Java, Android Studio, GIT

I installed Mavericks today on my MacBook Pro. The install went fine but it stop me cold for developing on my Android project. Sweet Apple revenge? Not really, they just don't install the developer tools you need by default. I wish the update would look at what you had and update to match but it does not. I did an update of the OS, not a clean install.

Some are getting prompted to install the Apple version of Java 6. I did not get prompted to do so the first time I tried to start up Android Studio. It just did nothing, no bouncing icon and no error message. Highly annoying and not user friendly.

Apple link to Java 6 that works on Mavericks

With that installed I was able to fire up Android Studio but it could not find GIT. I shut it down.

I was waiting on the install of Xcode to finish. Once that was done I fired up Xcode and it decided to grab the developer command line tools. Now GIT is installed and ready to go.

I appear to be back up and running as far as my Android and iOS development goes.

Outlook is acting weird. It decided to sort of dock itself and moving it just popped back into place when I tried to move it. I then tried Window -> Minimize and restore but that did not help so I did Window -> Zoom and then Outlook did some odd animation witch under a house shrinking up into the corner. I did command Q to quit and restart. It came up with half an email message scrolled off the screen. Doing View -> Navigation Pane seemed to get it back in order for now. It is painting weird in that you can only see half the "Today"header of the email headers.

Macports is not working. First it could not find GNUTAR so I did the following:

sudo ln -s /usr/bin/tar /usr/bin/gnutar

Which let it update and start the update of apps but now it has new issues. They plan and releasing an update soon so I am going to wait on that.

What I really want fixed is the crappy multiple monitor support of Mountain Lion. I really hope Mavericks makes that better. So far it has been a real time killer to get things up and running as a developer though.

I really miss Xtrafinder too. I know Apple added tabs but the other huge feature to me is the ability to sort directories to the top of the listing always. I understand if you don't like that but give us a freaking setting Apple! I don't want to scroll all over to find a stupid directory intermixed with my files. I am sure there are plans to update that too.

Thursday, October 10, 2013

Hey technology stop bothering me!

I love technology, it is how I earn a living but there are times when the magic turns into an annoyance. Let's take Amazon for example. I don't order a lot from them but I do order a couple of times a year and it has kept me out of the mall at christmas. There are times I am just researching something that I buy local, like our new microwave, and there are times I am looking up products for someone else.

To Amazon this means old Kevin is about to buy product X. We need to hound him about it until he buys it from us. To some folks this might look like magic. How did Amazon know I was thinking about getting a new camera? They just sent me a list of sales, that is awesome. Yes, I bought a zoom lens from Amazon for my camera. That is the only camera related thing I wanted to buy but to them I need to be an impulse buyer and get more and more crap. I want a setting to shut that off.

At least camera equipment fits in the all age range. One year my youngest son was into Go Diego Go so I ordered a few items related to that for christmas. I still get emails from Amazon about Go Diego Go. That ship has long sailed for him. No longer age appropriate. Don't know if they have an age out flag or not.

I have also researched things for other people while there were at my house. Things I am not interesting in ordering for myself. This included looking prices up for the Kindle. Yes, I am an Android programmer but I would stick with a stock Android tablet. The Kindle was the right thing for this person though so I was simply helping out. Now I get Kindle based information in my email.

Companies can only guess at what you want. There is no magic here. I have been able to kill some of the email from Amazon. They stopped sending me stuff about shoes because I could disable that category. I am pretty sure this happened from me ordering house slippers one year. The categories they manage are too broad. I don't want to shut off all electronics to stop Kindle emails.

I guess I could stop all the emails. Silly me thinks one day I will get some super sale email that is the deal of the century and who wants to miss that? Right now they go straight to the trash. Well, not straight there, I usually peek at the contents of the email and trace back to what I might have researched for them to bother me this time. Yes, I am analyzing Amazons analysis of me. Let's just file that under vicious circle for now.

Wednesday, October 9, 2013

Initial thoughts on iRadio - not overly impressed

I have a Mac at work that I use for both iOS and Android development. I installed the latest iTunes to go along with the latest Xcode and it popped up a reminder about iRadio so I figured I would give it a shot. I have used Pandora in the past and have ripped a good number of my personal CD collection to various formats to listen to on my PC / phone / etc.

As an old school hair metal band lover, which greatly explains my tin ear, I chose Kiss as a radio station. It played the first song from them then played the exact same song again and tried to play it again. I finally got it to skip forward to a new song. So far this has been a one time glitch.

I have used iTunes to listen to a shuffled version of ripped collection at work. It appears iRadio has the same issue that iTunes does which is terrible shuffle logic. Same song can appear twice in a row or with only a few songs between it. You may hear a couple of songs off the same album in a row. Ugly.

I use MediaMonkey on my PC at home and don't have this issue with shuffling. It appears to remember what it played and what album it came off of giving me what I consider a proper shuffle. Apple just does not appear to care as this has been an issue with them forever. They went random song selection without other context around it.

So far every song but one I have heard I also have in my music collection. Which is good in one way, I like them, but bad in that I am not getting exposed to anything else. When I used Pandora it found bands I was unaware of - Iced Earth being one of them - and I bought CDs from that band. I find Pandora's discovery system to be superior. This may be catalog related, I don't know what Apple has to choose from and I am well aware new hair metal is hard to come by.

I was happy to see you are allowed to pick explicit lyrics. I really want to hear the original version of the song, not a censored version. So far only one song has played with obvious explicit lyrics from the land of Ted Nugent.

Ads are short and don't appear too often but I have only heard 4 different ones. I have been told about Neil Diamond and the Nissan Versa way too many times already.

iRadio played "She's only 17" from Winger and had no clue what it was. No album art, no song title or artist. It just showed "Kiss Radio". Heck of a way to sell songs. It has done it twice with that song, there were only two songs in between the plays, stupid shuffle logic.

It got stuck trying to stream a song. I had to hit next song and it played an ad then the next song. So far most of the time I skip forward it decides it is time to play an ad before giving me a new song selection.

You can't go backwards. If you really liked a song and wanted to hear it again you are screwed. You can pause, play and skip. Can't even rewind the song you are on. This is a not an optimal user experience to me.

Underwhelmed at this point. Sound quality is good. No skips or stutters while the music is playing. The internet connection I am on is speedy so that is to be expected. Some glitches but none of them are total show stoppers, just annoyances. Apple has some work to do here.

Friday, September 27, 2013

Finally I get to do a tablet only app

We have a dashboard style web page used by our clients. I recently converted the charting side of that from flot to HighCharts. HighCharts gives much nicer looking charts by a long shot and the price was reasonable. All of that work was in JavaScript which I must say I don't miss and am very happy to get back into the mobile side of things.

JavaScript is just barely acceptable on an iPad or Android Tablet. Yes, I tweaked various UI aspects to make them more touch friendly but if we want to be able to look a client in the eye and tell them we have a dashboard that works on their tablet we need to go true native mobile.

All the code I have done in the past has been universal phone and tablet. For this type of dashboard we are going to start tablet only. We really want to design to use the space available. Of course 1024x768 (older iPad and iPad mini current maximum) is not a ton of space but it is what a number of folks run on even older desktop PCs if they only have a 15" LCD.

At this point I am sketching out ideas and have started a framework on the Android side. I am going to start there as this seems a perfect fit for fragments within an activity. Previously I have used fragments to learn about them and knowing it is the proper way to approach the future. Now I will get to exploit so much more of their power. I have not had the need to swap in one fragment for another or to add new ones to an activity, I have only defined them in the XML and let them operate as is.

Since this will target 3.0 and above on large devices I don't even have to worry about the compatibility library. Nice to get to be able to fully use the newer API features.

I am using achartengine for the pie, line and bar charts on the Android side and core-plot on the iOS side of things. The current smaller app just displays a pie chart so I will need to learn my way around the others.

Not sure what approach I will take on the iOS side of things. There is nothing like fragments there so I will get to deal with UI views and manual placement of things. This is why I plan to get it up and running on Android first so I can knock out the initial design without fighting layout issues. I should be able to figure out a number of UI patterns such tab controls, menu options, widget manipulation buttons etc. and run them by beta testers before I begin the iOS conversion.

Thursday, September 5, 2013

AAAARRGGGG iOS layouts stink!

I hate iOS layout management. Yes, everyone loved it when you knew the iPhone had this one resolution and you could perfectly layout everything. All phones were held in portrait only mode. Even the auto code generator blocked landscape by default. We knew what you had and how you would use it so just shut up. All Apple devs told Android devs they were hosed with their stupid layout managers without true WYSIWYG editing. Na-na-na-na-boo-boo.

This meant if you wanted to support landscape you added code to move things around and resize them during orientation changes. You could still use IB to see that pristine portrait view. Then came the iPad which was used in landscape a lot. Just do IB in that mode.

Well IB sucks. Adding storyboards just allowed it to suck in some new ways. Sure you can tie you portrait screens together and you can do separate iPad and iPhone screens but you have to manually tie all the controls back to your source code with crazy Ctrl + Click drag and drop if you can get the right source file to appear in a squished down window below the stupid layout that is way too damn big for iPad screens that wants to constantly scroll and resize every freaking time you click on it!

You are an idiot - use auto layout. If you don't then you are hosed. But Apple did not backport that, you had to wait until most users were on iOS 6. Google backports, Apple does not. Apple is a jerk in this area. iOS 6 seems like a safe enough target at this point.

Auto layout has a new set of issues. IB really blows here. It has to have everything in perfect order even though when you are creating the layout you can't get it in perfect order until the layout is fully loaded with all the controls. They IB rewrites the damn file over and over. You lose the battle every single time wasting a huge amount of effort.

So screw IB, it has been screwing you. Besides if you want a team working on things they can't all have the storyboard open because version controls DIFF is nearly impossible. It is a SNAFU. Time to write it all in code and skip everything related to IB.

You have a couple of choices. Use the auto layout weird ASCII stuff, which is just ugly to read, or use NSLayoutConstraints manually. I think I am going NSLayoutConstraints. If I am getting no WYSIWYG support I might as well take full controls. That ASCII stuff is too bizarre. Honestly this all feels like I am moving back into the land of GridBagLayout in Java.

GridBagLayout was the end all do all layout manager for Java back in the day. Yes, I did some crazy layouts with it that worked and even allowed you to resize the panel and flow properly. The code was ugly and not maintainable. You could not look at it and tell what the hell was going to display on screen and you could not add a new control between other controls without totally screwing everything up. I worked with developers that used GridBagLayout for everything even though a simpler BorderLayout would have worked. Use the right tool for the job people.

Look Apple there were a ton of other good examples of how to do things. MigLayout for example if you only want one layout manager. The Android XML way of doing things if you don't might multiple layout managers that deal with each other. At least with Android you can layout portrait and landscape and just put them in different directories. There is a WYSIWYG viewer too. I use it to preview the code changes I make in XML and so far have been able to build every layout I have wanted. The Android side is not perfect but is better than what I have seen from Apple.

Nope, Apple just puts all of that on you. Now I get to manually code all this crap and other devs will be able to see what it looks like when they run the code.

I just wanted to convert a current screen from a table view to a normal view. The original developer misused a table view for the screen and I need to clean it up and give a better look. IB does not like it when you try to change view types. Time to punt. Yes, I am using Xcode 5.x and I know it is supposed to have better auto layout support but it is still a mess.

Having spoken to my other iOS developer friends they have all stated it is time to move as far away from IB as possible. It has done nothing but screw them over. They think I am a fool for attempting to stick with IB as long as I have. I really just wanted to get the current project off the books but that is not going to happen. I can try and blow away the current table with a normal view then reattach the segues to the new view and leave it at that but that seems a new waste of effort.

I am going to have to learn auto layout. It is the new Apple way of doing things. It is the only hope if Apple decides to ever come out with a new resolution, which I really think they should. People are expecting HDTV on their devices. 1024x768 on the iPad mini is not cutting it anymore.

Maybe someone will come out with an excellent layout manager for iOS that will solve a number of these issues. At this time I don't care about WYSIWYG at the start. Something that is easy to code and maintain is what I want. I enjoyed working with MigLayout. I converted over 300 Java desktop screens from old NetBeans format to MigLayout at a previous company. I find the Android layout managers more difficult that MigLayout but still serviceable. The new Android Studio does a really nice job showing me a preview of my screens as I edit the XML. The layouts work and scale on various device sizes.

Done with my rant. Off to code NSLayoutConstraints.

Wednesday, August 28, 2013

UITextField Change made by Apple

The following worked prior to Xcode 5 + iOS 6:

@property (weak, nonatomic) IBOutlet UITextField *source;

if (![self.source.text isEqualToString:@""])

It now needs to be

if (self.source.text != nil && ![self.source.text isEqualToString:@""]) {

Previously if the user never touched the text field you got back an empty string. Now you get back a nil string instead. 

Just found this while testing code I am updating for iOS 7 while running on a device under iOS 6.

Shown for simplicity. In the actual code I am using a utility method to trim the string and check for a length of 0. The stupid trim method for iOS is a super long line and can be found all over the web as everyone must write it over and over as Apple does not include it in the base NSString object.

Tuesday, August 27, 2013

Finally have new ActionBarActivity working with Android Studio

Yes I am a sucker for punishment. The new Android Studio 0.2.6 came out today and I found this out my usual way - saw it on Reddit. Since I just battled this beast yesterday I thought I would give it yet another shot.

Post install it still could not build my project but was mad about even more things. I decided to delete the entire project off disk and start fresh especially since it kept being mad about gradle build settings and make settings that I would change and save and it would forget I had done that.

I deleted the project. Started AS, told it to create a new project with old project name, single activity. While it did this it appeared to download some additional gradle files. Probably updating from 1.6 to 1.7 but I am not sure. It did not do that when opening my old project.

Shut down AS. Copied the java source code, resource files and manifest over from the working Eclipse project. I did not want to risk changes to a working project. Started up AS and it found all the files automatically. I love that about Java, just put the files in the proper directly and have at them.

Copy in the build.gradle from this web site then add the dependencies to the two bonus libraries I am using - achartengine and GSON. Run the rebuild all and everything worked like a champ. No errors. I was able to deploy it to my Note II and it ran perfectly.

Obviously multiple things happened here. AS was upgraded and it needed to upgrade various support tools which it did not do until I forced it via creation of a new project. That is pretty annoying. Once that was in place it is finally working.

I am glad they fixed the issue dealing with Google support libraries. The actual editing you do to the build.gradle is simpler than the project import work I had to do in Eclipse. You can read those steps here

Do I think this project will keep working? Who knows, seems on the AS side of things they make changes that require you to start with a fresh project or you are hosed. Gradle is in flux too. I like the editor and layout preview features of AS so I may use it for the next parts of this project. I really want to come up with functional tablet layouts beyond what you can do on the phone. I have everything split into fragments so this should be possible. I also want to use more than just the pie chart from achartengine and have more than one chart on screen in tablet mode.

This ties back into the JavaScript work I was doing in another area of our product. While that works in the browser on tablets it is slow and cumbersome. I should be able to do something similar in native code with large gains in speed and usability.

Using Genymotion to test against various device sizes. Nice and fast and recommended when you are not testing on an actual device. Very happy they added device rotation support.

Monday, August 26, 2013

Converted from ActionBarSherlock to new Android compatibility library

Since I was never able to get ActionBarSherlock (ABS) to play nice with Android Studio (AS) I thought I would convert to the new blessed by Google Android Compatibility Library and the ActionBarActivity.

Of course that did not work out as planned. I finally gave up on AS and just got it working in Eclipse. I tweaked the code and add an action bar menu item, setup a new base class and did some code clean up. It all works great. I guess I need to try it all in AS again but it gets so frustrating. I really like IntelliJ and there are some cool features I am missing by sticking with Eclipse but AS just is not right in the head when it comes to working with 3rd party libraries you need to import as library projects.

Some are now saying "Yeah, the IDE will show an error but it will run on your device!" Look, I hate warnings in my code and tend to turn as many of them on as possible so the IDE catches as many stupid mistakes as it can. Now to have an outright error everytime I build? No thanks.

I do like the new compatibility library. Got rid of the word Sherlock from various areas in the code so it all looks more native and cleaner. I have missed working in Android land and with a little break in the action I have been able to sneak back in there to do some minor tweaks to our app.

My plan is to get it all working in Android Studio so I can use the best of both IDEs. Prior to ABS and now the compatibility library I was not having any issues doing that.

Friday, August 9, 2013

JavaScript and Highcharts

When you work at a smaller shop you get introduced to a lot of technology and you pretty much have to go with the flow. For the past couple of weeks that flow has been down the white rapids of JavaScript for me.

The goal of the project was conversion from flot to Highcharts. Flot offered some very basic graphing and they wanted more eye candy and functionality so they decided on Highcharts. Will cost the company a licensing fee but it will be a much more professional product in the end.

I have not done much JavaScript in the past. I know it is not Java but the syntax is very close so getting up to speed on that was not an issue. Figuring out all the nuances is another story. I have the project up and running now with some final polish so it works better on iPads and Android tablets.

This would be considered a small project. Single page with two tabs. The page contains a dashboard layout control and you can add widgets. Each widget has associated HTML, shared CSS and a JavaScript to query for the JSON data and convert it into Highchart format. We have all the fun of formatted tooltips and configuration settings such as legend position and visibility of data labels.

So where does the fun begin? The whole code / debug cycle is a bit frustrating. I am using Eclipse and Chrome. If I just change a JS file I can save it in Eclipse, hit refresh in Chrome and see the results. If I am changing CSS or HTML I get to clear the cache in Chrome then refresh to see the changes.

Chrome has a decent debugger but you have to make sure you include the JS in the proper file for Chrome to see it as a source file. I had to remove it from a styles.js and move it into a controlling HTML for this to work. Then the break point may or may not work. You end up doing console.log(object) and then just sniffing around in the output console to see what is happening.

Don't forget console.log('Widget is ' + widget); is totally different than console.log('Widget is'); console.log(widget); The first one converts widget to a string which is generally useless. The second set of lines will show widget as an object you can inspect.

JSON.stringify(object) can come in handy at times. You will get circular references for core objects but for looking at return values from the server and what not it works fine. I usually copy that output into Sublime Text 2 and run the JSON formatter on it to get a good look at the results.

Since JavaScript is not strongly typed Eclipse is not a lot of help when it comes to finding variables and methods. You just have to know what is there by opening code and looking around. Not the best way to be productive. You also are not told your code is crap until you run it. I know dynamic languages have their strong points but I really missed this area of strongly typed languages.

Scoping is another bit of fun. If you want to trigger an event from one place and catch it in another, well it works but figuring out the proper scope can be a bit of a pain. It is all up and running but I ended up getting a lot of help from a developer with a stronger JavaScript background than I. In the end I was still unsure why what he handed me worked but I was just happy it did.

Highcharts is a really solid product. I am very happy with its final look. I was able to pull off a number of cool features. I did a lot of web searching to find out how to format tooltips, grab events, set up gradients, use multiple y axis, do stacked bars, etc. It really helped to be able to run jsFiddle sample projects. Guess that is one of the nice things about JavaScript, you can piddle around with it on a webpage before you toss it into your project.

Friday, July 12, 2013

Trusting the API is not a good idea

You are programming right along and need to accomplish what appears to be a simple task. You look at the API used by the company and find a one line call to do what you need. Make the call, get the expected results and move on to the next task. All rainbows and unicorns right?

Not so fast there bucko! The key word here is fast. The method I called did do what it needed to do and returned nearly instantly because I hardly had any data in my test database. Once you had a large amount of data it was painfully slow as we found out when attempting to run it at a client site. I had no logging output around the call as it was never an issue for me. It just looked like the program froze when running at the client location.

When something breaks I blame myself. I figure it must be in my code. Took another developer looking over my shoulder to point out "That call might be slow". I had looked past that line over and over again. Of course when I ran the program it sailed right past that line so I never thought about it. I was blinded to it because I was sure I was the one to blame.

We were able to have the client run another command against the database to clear out some old data to get them past that point. We then found the next step, again relying on the API, was also very slow but I had logging in place to watch that progress.

Time to rethink how all of this needed to work. We fixed the initial call to work in a reasonable amount of time and are in the process of gutting the code to write records to a file which we will then import via "copy {tablename} from {outputfile}" x 4 instead of doing inserts in the code. We were able to import 1.2 million records in 1 minute and 46 seconds using the 3 copy calls where it was going to take days to do it in code one insert at a time while parsing JSON streams.

This particular client has a much larger dataset than any other client. We are talking to a 3rd party vendor to get the 8.2 million records that need to be inserted via JSON requests. After these code changes things will run faster and scale better for every client. My part of the code is the JSON to our database format conversion. So far that appears to be working properly at least.

I made the mistake of trusting the existing API calls. I have only been at the company for 4 months meaning I had no background in company lore. I had no ideas what areas had bitten folks in the behind in the past and I figured the every call was optimized. Trust no code especially "this one line can't do much or take long". I should have put logging messages above and below the API call so I could have spotted this in the client run quicker. We knew up front they had a ton of data. We knew we did not have a large sample for testing. This is where extra logging is really helpful.

Lesson learned. I hope I don't make it again.

Tuesday, June 18, 2013

When you know it can be done is coding is easier?

There are times when you are coding that you are not sure what you writing can be done. Oh, sure most anything can be done if you sit down and look at it logically and have enough hardware and time. What I mean is you have not seen it done before so it feels harder. It is easier to give up and work on something else.

But what if you have seen it done before? A really cool transition effect on a mobile device, a pop-up menu on a double tap of a row, fragments that work differently between a phone and a tablet in a unique manner, etc. You know it can be done, you have seen it running on similar hardware to what you have, now duplicating it is a challenge.

Same thing goes when you have written similar code in the past at maybe another job. You don't have access to that source code but you know you basically wrote the same thing before. Again you have a programming challenge instead of a "how the heck can this even be done" task.

I ran into this again today as I was converting code from straight activities to ActionBarSherlock fragments. Everything I was doing I had solved in some manner in the past. I totally knew it could be done so even when it was not working I knew it was because I had done something stupid. My frustration level was pretty low. I did get stuck on one issue but a lunch break and trying to word a question mentally for a web search triggered a new thought showing where I had messed up.

If you are writing a new piece of functionality and it is not working you are unsure if you totally screwed up or if there is a limitation of the SDK or language you are butting up against. Of course you don't want to blame yourself so you start looking for things that are wrong with the API especially if you are new to this framework. You tend to get frustrated quicker and the frustration will be deeper. "This just can't be done" you tell yourself. "There must be a bug in the SDK" rolls through your mind.

Grabbing at straws comes into play. Move it to another thread, yeah that's it. Change the order you call things, that'll fix it! Try a 3rd party API or another widget, the one I first picked must be a steaming pile even though it was the highest rated one on Stack Overflow. This stupid thing has got to work, ain't nobody got time for that.

Finally you solve the problem. Turns out you were at fault the whole time. You were on the right track but you thought the range was 1.0f to 0.0f when it was 0 to 100. You found an obscure post on the web and you spotted the author passing 75. The API is fine, in fact once you stopped cussing at it there are some really cool features it has that you hadn't gotten a chance to use yet.

Programming is a really weird occupation. You spend a good part of the day dealing with the unknown, trying to pull something off you think can happen but maybe can not. Some days you are writing code nearly from memory just humming right along. You have done something similar and this is nearly a no brainer. Just create some objects and parse some JSON, easy peasy.

Other days you are trying something totally new. You have to integrate a third party pie chart widget. You barely know where to start. You spend some time pouring over documentation so hopefully it works the first time. You find some example code and pull it off the web. Do you start a test app? Do you try to drop it into the existing app? Is all the example code in fragments and you are using activities? Can't I just find an exact example of what I am doing? Of course not, the chance of someone else doing the exact same thing you are doing is really low. Heck if everyone needed it then it probably resides in the base language, one of its core libraries or somewhere in the SDK.

The best we can do it post things we figured out to our blog or answering questions on blogs or Stack Overflow. Let others learn from our experiences. Coding should be about solving specific issues for a company not constantly reinventing everything. Grab as much code as you can from other projects you have done, other websites and the SDK itself.

Why I stopped using Android Studio - for now

I was pretty happy using Android Studio. Loved the way I could see the preview of a layout while working on the layout. I had written a new app from scratch to match the functionality of our current iPhone app using Android Studio. I also like the dark theme they provide. Easy on the eyes.

Then I ran into a problem that made me stop using it. I wanted the app to run on more devices so I turned towards ActionBarSherlock. I found various posts on Stack Overflow on how to make it work. I tried them all but was ending up with some weird gradle errors that I was unable to solve.

Gradle: A problem occurred configuring root project '{my project}'.
> Failed to notify project evaluation listener.
   > Main Manifest missing from /Users/kpeck/AndroidStudioProjects/{my project}/AndroidManifest.xml

I have a manifest file of course. It is not in the directory given. I even tried to copy my the file to that directory, even though it does not belong there, and attempted the build again but it still did not work.

It is possible that starting a project from scratch with ABS in it and then copying in my files may work. I will have to give that a shot at some point.

Having run ActionbarSherlock under Eclipse in the past I knew pretty much what to do and had it up and running in a matter of minutes. Import the project into the workspace, delete the duplicate android-support-v4.lib, set the dependency between ABS and my project and it was working. I spent the rest of the day converting code to ABS format. That was generally pretty easy with a few minor snags around loaders.

At some point I may go back and attempt to get it working in Android Studio but right now I need to move forward on the project. I have other areas that I want to convert to activities hosting fragments. Currently I only converted the one that needed a loader but I have some ideas on how to layout items on a tablet that would benefit from fragments.

Android Studio keeps changing the way you deal with project settings. It was through a dialog but now they want you to manually edit things in the build files. Somethings happen automatically as you import but it does not seem to finish the job. It is still alpha software and they are pushing out changes quite often. I want to get familiar with gradle but I don't have the time to pause right now and do that.

I also found the preview has some issues especially with Relative Layouts. The above / below / left / right layout parameters seem to be suggestions in the preview. They work fine in the emulator or on a device but that gets frustrating. I may see the screen look just right in the preview then a change to the XML in an area unassociated to the Relative Layout will cause it to paint incorrectly, usually overlapping controls. Really need a preview I can trust so I am not chasing down issues that don't exist.

Probably good to wait another release or two of Android Studio. There will be more tutorials on how to make things like ABS work with it and I can skip the headaches. Back to trusty old Eclipse for now. I found a dark theme that is reasonable for it but it only changes the editor pane. That is the largest part of the screen so it is better than nothing.

Wednesday, June 12, 2013

Cancel SVProgressHUD process by tapping on HUD

I am using NSURLConnection to potentially pull a lot of data from the server based on user search criteria. There are times when the user does a pretty board search and getting the results back can take a couple of minutes. It can be a waste of the user's time and server processing especially when the user realizes how much data they are about to get back. I wanted to add a [Cancel] option. Since I already had this working on the Android version I really needed to make it happen on iOS. I looked on the SVProgressHUD site and there was a rather heated discussion about this and how if I was using the HUD to run super long processes then I was doing it all wrong. 

Obviously I beg to differ on that point. I have a potential long running process based on a user request and I show a progress indicator and allow the user to cancel as needed. The code below shows a simple sample but I actually show "Processing record X of Y" in my code so the user gets a feel for how long the process is going to take. I don't know how many records are coming back in the response until I make the request so I can't give a "Are you sure you want to suck down 10meg of data?" message first.

After reading the SVProgressHUD site I investigated some other HUDs to see if they solved my needs but found them to be harder to use or they had other issues once I hooked them up in code. I sniffed around in the SVProgressHUD source code and discovered a solution - Notification Center messages.

Just before I show the HUD I do the following:

[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(hudTapped:) name:SVProgressHUDDidReceiveTouchEventNotification object:nil];

A sample of showing the HUD which lets the user know how to cancel the operation:

[SVProgressHUD showWithStatus:@"Requesting data...\n(tap to cancel)" maskType:SVProgressHUDMaskTypeBlack];

The method that gets called when HUD is tapped:

- (void)hudTapped:(NSNotification *)notification
    NSLog(@"They tapped the HUD");
    // Cancel logic goes here

and any time I am done with the HUD, either via tap to cancel or run to completion, I call:

[SVProgressHUD dismiss];
[[NSNotificationCenter defaultCenter] removeObserver:self name:SVProgressHUDDidReceiveTouchEventNotification object:nil];

So far it is working like a champ and appears to be a pretty clean solution. I hope you find uses for my discovery as well. Maybe you want to put in an Easter Egg if they tap it 10 times. Have fun.

Thursday, June 6, 2013

Use adb to update APK on device even with emulator running

For my Android development I use the fast HAX based emulator on both my PC and Mac. I do the bulk of my testing on the emulator and push the APK to a real device maybe once a day to to make sure everything still looks good and runs as expected.

If you try adb install {yourapp}.apk it gets mad if it finds multiple devices such as a physical device and the emulator. Plus install gets annoyed if the program is already installed on the device.

You should use the following command

adb -d install -r {yourapp}.apk

The -d option tells it to find a device attached via USB. The -r tells it to upgrade which keeps all the existing app data in place which is handy if you are using SQLite databases or have settings saved such as username and login server. This command can save a lot of time and headaches as you don't have to shut down the emulator to push to a device and you don't have to lose any saved data.

If you have a lock screen enabled you will have to unlock the phone before you can push the update to it.

You can also use adb -devices to make sure it is finding the USB connected device. There are times you have to unplug and replug the USB cable to get things working.

Wednesday, May 29, 2013

Back as solo mobile developer - not easy

Being the solo mobile developer at a job is not easy. I had just gotten used to having a couple of developers around me at my previous contract position. Everyone had bits and pieces of experience in different areas so you would quickly get answers to questions without doing a Google search. They might have some sample code laying about from another project or just know how to do it.

Sure the big boss here wrote the initial iOS code that I have been cleaning up and adding features against but I rarely get to speak with him and he has no Android background. I have been working on the Android port this week getting stuck on silly things that the guy I worked with at the last place would have handled with ease as he had a lot of background in those areas. Now that the core networking is in place I can start moving forward at a pretty good clip.

A real feeling of isolation when you have developers all around you but they either don't know the language (Objective C) or the framework (Android SDK) thus you can't really bounce any ideas off of them. Sure I can hit them up for general business knowledge or Java questions but not for the meat of the development cycle.

For my Android work I have been using Android Studio. I know it is a 0.1 release but that is really just the Android plug-in side of things. The over all IDE is at version 12 and I have enjoyed using IntelliJ in the past. I like the dracula theme as far as colors go.

The ability to edit layout XML and see the results side by side in the preview window is super handy. I have gotten that to generate crash reports from time to time but they did not kill the IDE or lose any of my work.

What I miss from Eclipse is the new class wizard. It asks for the base class and interfaces and lets you quickly build things out. I have asked about this on the IntelliJ forms and they basically stated you can do all of that via a number of steps. I want a Wizard. I also want the auto add of the Activity to the manifest. I should not have to do all that work manually every time I add a new activity to the project. Since this is a new project that has been happening a lot.

The Log Cat filter seems pretty iffy too. I turn it on to filter out things but it forgets about that between program runs so I have to go back to "No Filters" then back to my filter again. It is silly how much junk the emulator kicks out into Log Cat. Since I am using the HAX high speed emulator I get a ton of extra stuff.

I was happy to get the upgrade to 0.11 this morning. Good to know there is active work on Android Studio and I am sure it will continue to improve. I have been using it at home on my Win7 64 bit PC and my Macbook Pro at work. Both seems to run equally well.

Wednesday, May 22, 2013

Core Data stinks for bulk inserts - direct SQLLite is much faster

I was handed an iOS app that was using the basic JSON handlers and keeping everything in memory. This was slow and running out of memory for large requests.

I converted the project to use stream based JSON parsing stored to a Core Data database backed by SQLLite. This solved the memory issues allowing all requests to work. There are 5 tables involved with a total of 239,000 records if you requested all the data from the server.

The problem - that request took 5 minutes and 43 seconds to process on an iPad 2. It took 33 seconds on the simulator. Let's state this again - Always test on a device. That kind of time is totally unacceptable.

After sniffing around the net and attempting to speed up Core Data I determined that Core Data sucks at doing bulk inserts. Core Data is really nice at hiding the gut level fun of SQLLite but for large inserts it is not the way to go.

I converted everything to use SQLLite directly and saw a massive speed increase. I can now process the same record set in 1 minute and 23 seconds. That cuts a whopping 4 minutes and 20 seconds off the time. The simulator went form 33 seconds to 12 seconds.

A typical user would rarely if ever request all the records but testing worst case scenario is really the best way to go. The speed improvement is seen across the board in the app with similar percentages of improvement. I am very happy with the results even though it took a couple of days to get it all sorted out.

As for the code there are areas that are more involved than the Core Data version and there are areas that are actually a lot cleaner. Everything is a trade off and there is no clear winner.

I had never used Core Data before. It was a really good learning experience to set it all up using the GUI editor in Xcode and finding out what it took to add the Core Data library and support code to an iOS project that was created without it originally. I found a lot of Core Data really straight forward and easy to use. I will not shy away from it on other projects unless they involve bulk inserts.

Having used SQLLite in the past I had a basic object set to start with and I knew my way around FMDatabase. My previous experience did bulk insert processing and I wrote both iOS and Android versions so I stuck with SQLLite to make it easier to convert code back and forth. I wanted to learn something new this time around so I went with Core Data. Good thing I could quickly fall back on my direct SQLLite experience to solve the speed issues that arose.

Tuesday, May 21, 2013

Mobile app usage and development - do you just have to magically know what to do?

The more mobile development I do the more I am finding you are just expected to know things magically. There are very few help screens, tips of the day or on screen tutorials. There are so many potential gestures in any app that you need to magically discover. What can we do to make this situation better?

A lot of apps allow swipes to perform an action. Swipe left to call, swipe right to text. Long presses may do something or bring up a menu. Some actions are instant and others prompt you but you are never really sure what will happen. Delete should prompt. Add a new item most likely does not need to unless it will cost money i.e. send a message or use your data plan or will take a long time to perform.

Some will answer the mobile device is so small and we all want to save on code size and people never use help or only use it once so skip it. The original apps were very small and had few features so that worked. News apps have a ton of features. We basically have computers in our pockets and we do a lot of work on them.

Do we need a standard "Cool Features" button showing quick help? Maybe it should show a standardized overlay on the screen to explain the swipes and long presses so people can get more out of our apps.

The other side of this is developer tools. They have a boat load of features too and a lot of their power is there but hidden from the coder. I know Xcode drives me crazy with its lack of right mouse button menus. I expect to be able to perform most actions a context sensitive menu. In general the menus are very terse. Want to add a view controller to a story board? Right click on the story board and you get zooming only options. You have to know to drag a view controller for the Utilities panel. But first the Utilities panel has to be visible. That is the only way to perform this operation. That is not friendly.

Speaking of the Utilities panel it has 6 tabs on it and I seem never to go to the correct one to do what I need. Do do nearly anything you shift between 2 or 3 of the tabs. Somehow I would like the most common settings on a single tab that I could define.

Right click on a segue control and you get zoom options but nothing associated to the segue. Click on the Scene Name in the left hand panel and nothing at all happens. I excepted the editor to scroll to that Scene. You have to click on a view of the scene for that to happen. Oh and it changes your zoom factor when you do that. Just scroll there! If I was zoomed out I want to stay zoomed out!

Is the layout of your windows wrong? Can you right click on something and fix it? No, you have to go to View -> Assistant Editor and pick the layout you want. I did not even know the window I was looking at was called Assistant Editor as nothing on screen indicates that. You can mouse hover over the toolbar button to find that out. Those same buttons are inconsistent. The first three toggle between modes of a view and only one can be pressed at any time. The next three toggle the visibility of views and any or none of them can be pressed but the two sets visually they look identical.

Highlight a word in the editor and hit Cmd+F most editors will automatically put the highlighted word in the search box but not Xcode. I get to copy / paste it up there. Heck I can highlight a word in Eclipse and just hit Ctrl+K to find the next occurrence skipping the Find prompt altogether.

Add files to a project and guess what? They are not flagged as needed to be added to version control. Why? Right click on them to add them and that menu is not there. I have to fire up SourceTree to add them to GIT for this to work. Xcode version control integration is crappy at best.

Tuesday, May 7, 2013

Windows Update error 800B0100 - I finally just gave up

I have been battling Windows Update Error 800B0100 for over a week. I searched the web over and over and tried pretty much every solution presented. I don't know how many times I ran the Windows Readiness Tool, update fixer, fixer fixer, Mr. FixIt, delete this, delete that, uninstall all of these, manually install those, etc.

Nothing made it work. I finally just blew away the VM - this was Windows 7 Professional on my Mac, and did a reinstall from DVD. After many updates it all appears to be working. I have never run into this sort of issue in the past where Windows got so messed up that I had to give up.

Another odd thing, I needed .NET 4.0 so I download that. Right away I have to download 16 patches. This means MS does not keep the installer updated. Must be the original install then you have to download all the patches. Seems a waste of bandwidth to me. I should get a pretty recent version of the .NET 4.0 installer when I download it. I don't expect to download Chrome, 7Zip, Sublime Text or others just to turn around and have its updater run and get more stuff. To me it makes MS appear lazy.

At least it is up and running now. I needed to install IIS but with the update issue that was not possible as the windows features list just came up empty. Now it fills in and I could install IIS. Turns out that was for naught because the final piece of 3rd party software was holding all its errors and only showing me one at a time. It complained about IIS but once that was installed it turned around and told me my OS was not supported. Gee, seems that is a much more important error message. You really should from the worst situation forward or show a list of issues instead of just the first one you find.

Now we have to find and configure a Win Server 2008 to get this all rolling. Guess I will go back to some iOS clean up coding while I wait for that to happen.

Wednesday, April 24, 2013

Using YAJL with Objective C

I have been tasked with getting an existing iOS code base ready to be released to the App Store. After loading the existing project into Xcode and resolving static library link issues I was able to run the program but not log in. I added some #ifdef DEBUG processing to allow me to log into a server without a valid certificate and got to play around in the app on the simulator.

I was quickly able to crash the app and after setting the debugger up to stop on all exceptions I found it was running out of memory. Boy, if you can run the simulator out of memory you know you can easily do that on a device.

Looking through the code I found it was using NSJSONSerialization for all JSON processing. That library is fine and it is provided by Apple so you know it is legal to use but when you have large amounts of data it is not super efficient. If you have used XML in the past and are just getting into JSON this is similar to using DOM vs SAX. DOM is great and easy and hands you a nice tree of data but if all you are doing is plucking things out of that tree to put in another format you are better off using SAX especially if there are memory concerns.

The code was parsing everything into a big NSDictionary based tree with 13,318 base records and tons more child records. This is just not going to work on a memory limited device.

I looked up information on stream based JSON parsers and landed on YAJL which you can find at I won't cover how to configure it for Xcode as all that information is on the base site. It was easy to set up for both Mac OSX (my test program) and iOS.

They show a streaming sample that was too basic to be very helpful. Hopefully I can fill in some of the gaps. The first issue with their sample is they read the WHOLE file into memory via NSData then run it through the parser. Not fully streaming at that point. Second they show no samples on what to do in the callbacks.

The code snippet below will help you parse your JSON by keeping track of where you are in the data. It will keep a stack of named dictionaries and arrays as you parse through the data. You can then create and act on the proper objects as you get map keys and values.

It also reads in the JSON file in chunks instead of tossing the whole things into NSData. In my final iOS code I am using a NSURLConnection and parsing the chunks in the didReceiveData call.

The original code ran out of memory when receiving 38.9 meg of data and took 5 seconds to run. I put in some cheater try / catch blocks to let it "finish" without crashing for timing results. The new code does not run out of memory and runs in 2 seconds. Of course this is all in the simulator on a fast MacBook Pro with a lot of RAM. I don't currently have a device to test on but will get one soon.

I looked around on the web for a long time before I was able to piece together enough knowledge to pull this off so hopefully it will help others get up to speed a lot faster.

Things that go in the header file

// Array used as a stack to keep track of where we are
NSMutableArray *stack; // create this in init method
NSString *mapKey;

// Actual class code

- (id) init
    self = [super init];
    if (self != nil) {
        stack = [[NSMutableArray alloc] init];
    return self;

// Code to parse the file in chunks

- (void) parseFile:(NSString *)jsonFileName
    YAJLParser *parser = [[YAJLParser alloc] initWithParserOptions:YAJLParserOptionsAllowComments];
    parser.delegate = self;
    uint64 offset = 0;
    uint32 chunkSize = 10240;     //Read 10KB chunks.
    NSFileHandle *handle = [NSFileHandle fileHandleForReadingAtPath:jsonFileName];
    NSData *data = [handle readDataOfLength:chunkSize];
    NSLog(@"Starting parse of %@...", jsonFileName);
    [stack removeAllObjects];
    mapKey = nil;
    while ([data length] > 0)
        [parser parse:data];
        if (parser.parserError)
            NSLog(@"Error:\n%@", parser.parserError);
        offset += [data length];
        [handle seekToFileOffset:offset];
        data = [handle readDataOfLength:chunkSize];
    [handle closeFile];
    parser.delegate = nil;

// Stack adds newly named object OR last object on stack
- (void)parserDidStartDictionary:(YAJLParser *)parser
    NSString *dictName = mapKey;
    if (mapKey == nil)
        dictName = (stack.count == 0) ? @"" : [stack lastObject];
    [stack addObject:(dictName)];

    // Create new object here based on dictionary name
    // ready to hold soon to come key + value pairs

// End of dictionary - pop off stack
- (void)parserDidEndDictionary:(YAJLParser *)parser
    mapKey = nil;
    [stack removeLastObject];

    // Save object created in start Dictionary to
    // array or core data here

// New array staring, push name onto stack (use previous if we don't have one)
- (void)parserDidStartArray:(YAJLParser *)parser
    NSString *arrayName = mapKey;
    if (mapKey == nil)
        arrayName = stack.count == 0 ? @"" : [stack lastObject];
    [stack addObject:(arrayName)];

// End of array, pop off stack
- (void)parserDidEndArray:(YAJLParser *)parser
    mapKey = nil;
    [stack removeLastObject];

- (void)parser:(YAJLParser *)parser didMapKey:(NSString *)key
    mapKey = key;
    // Do processing here for each map key
    // Something like
    // if (!inResults && [key isEqualToString:@"results"])
    // {
    //    inResults = true;
    // }

- (void)parser:(YAJLParser *)parser didAdd:(id)value
   // Do processing here for each value (will have a mapKey)
   // Something like

   // if (inResults && [mapKey isEqualToString:@"query"])
   // {
   //   query = ((NSString *)value);
   // }
   // value will be (NSString *), (NSNull *) or (NSNumber *)
   // booleans come as (NSNumber *) 0 = false, 1 = true


Thursday, April 18, 2013

Is there really any such thing as a typical day?

I have been at my new job for a little over a month now. I have had the chance to learn a lot of new things. Generally I have been a front end developer doing the GUI and writing custom controls. Of course that does not mean I don't get to do any middle or back end coding. I use SQL where needed, write business logic handling objects, etc.

Here we are using Spring, Hibernate and Postgres for the database chores. I am finding my way about on all those annotations and have sent off and received requests for new table schemas to the DBA.

In a given day you can find yourself using little bits of each framework in a few hours time. I started the day setting up a chron job to call some existing code that calls two different 3rd party APIs to get some data. One of the vendors uses XML and the other JSon. The objects are created via Spring and we use Hibernate to interact with the database. I was using various internal SDK calls to do most of that with all of the work being done in Java.

Once that was up and running I was asked to look at some existing Objective C iOS code to see how close it was to being app store releasable. First off I was not able to login in as the servers I have access to don't have valid certificates on them and our API is HTTPS based. A browser will let you ignore the suspect certificate after a warning message. I added some #ifdef DEBUG to allow the Connection code to accept any certificate. That got me into the app and allowed to try out rest of the GUI.

Sadly I crashed the app pretty quickly. Did not know initially if it was bad memory management or if it ran out of memory. Turns out it ran out of memory. I added a @try block around things so it could push itself along a bit farther and I was able to run everything.

I then started to research why it ran out of memory. I looked at the server request it was making and tried it in a browser. A huge pile of data came back so I ran used curl to grab the data and write it to a local file. Turns out there was 38.9 meg of JSon coming back.

I wanted to sniff around in the JSon so I asked python to pretty print it and sent that to another file. I then opened it up in Sublime 2 to see what I had. Straight forward JSon, just a lot of it.

Next I wanted to see how the code was handling the JSon. Turns out the developer used the standard NSJSONSearialization calls in iOS. This is like using the DOM in XML in that you get it all in memory and they you double it up or more by converting to your internal object format. It was the easy way to go but not the most optimized way to handle things.

Time to hit Google and see if there is a streaming JSon parser. I found YAJL which I plan on experimenting around with today. I also think we should write the results out into a database instead of holding it all in memory. I have written similar code, it was XML and not JSon, storing to SQLite at a previous position so this should be fairly straight forward.

So was this a typical day? Yes, in that I ended up using a pile of different languages, data formats, command line tools and frameworks / SDKs to get my job done. You really need to branch out and learn new things.

I played around with Python in my spare time at home as I kept hearing about it and now I have used it multiple times. I used it at my previous job for a quick error log parser. I have used it here because some sample 3rd party code was written in it and I needed to convert that to Java. I was able to run the Python code and tweak it until it worked before I converted it to Java. I have used python to pretty print JSon files.

Curl was something new to me here. I have used it a lot with the 3rd party vendors as one did all their sample code it in. Curl makes it very easy to grab server results and shove them into a file. It works great with HTTPS as you can pass the user name and password in the command along with ignoring invalid certificates which seems to be a recurring need.

I have used Java for years so that is second nature. I have not used Spring or Hibernate in the past. I am really starting to see the power of the annotations. With great power comes great responsibility though. I am learning when you need to put code in other objects so it can be properly initialized. Anytime you use a new framework you find new and interesting ways to crash your code.

There is very little iOS knowledge here so I was able to step in and handle that too. A bit of a mind shift to get back onto Objective C and it will take some time to remember the syntax, framework and ins and outs of Xcode. Keeps you on your toes to shift around between languages, IDEs and frameworks. Good thing my Mac has a lot of memory, disk space and a large second monitor to keep all of this open and ready to roll.

Just to add to the mayhem I am working on updating my Android game at home. It does not scale well to tablets so I am converting the graphics to vector based allowing it hopefully work on nearly every device. At the end of most days I am pretty mentally fried.

Thursday, April 11, 2013

Motorola Xoom aint what she used to be

I have had the Motorola Xoom for a couple of years. One of the early Android tablets. It is dual core but boy is it showing its age. Part of this is due to my quad core Note II. Everything on my phone is really snappy. Things on the Xoom used to be snappy but now everything seems slow. Boot up time really stinks.

Button presses to get to home screen or bring up list of running apps are pitiful. I still use the tablet a lot for content reading. That works just as well as it always has although the screen is not super bright nor does it have the great colors of the Note II. I enjoy doing crossword puzzles more on the tablet as you can see more of the clues and all of the grid.

Not ready to get a new tablet just yet though. The Xoom works for its specific purposes. The direct plug-in charger quit working but the base charger I ordered from Amazon works just fine. If that goes out then the tablet will be useless.

Next time I will look in a smaller than 10" range but I don't know if 7" is big enough. Probably something in the middle. At least on the Android side of things there appears to be a nice variety to choose from. The current size / weight can make it a bit tough to hold one handed for extended periods of time. I am usually petting a cat while reading articles or using my other hand to one finger type crossword puzzle answers.

Monday, April 8, 2013

Life is a series of subscriptions

It used to be you had a few recurring monthly payments:
Rent / house payment
Utilities (gas, electricity, water, sewer, land line phone)
Car payment

You probably got your TV over the air. There was no internet and without that no such things as multiplayer games that were fee based.

Now you might have had some self imposed recurring fees like a monthly comic book store stop, new miniatures to paint for DnD sessions or something similar.

Today we have added:
Cable or Satellite TV including DVR rental
Internet provider of some type, bundled or otherwise
Cell phone including data plan
Online gaming subscriptions
App purchases
Netflix, Amazon or Hulu type service

We probably dropped:
Land line phone

It all seems so simple. What is another $20 here and there. Sure, get HBO and add data to all the kids phones and up the internet connection speed. Chuck on $3.50 for cell phone insurance, $14.99 to monitor your credit score, etc. When you look at it all - boy does it add up quickly. I cringe every time I think of adding another monthly fee.

I feel I would really enjoy playing WoW but I don't want to pay for a game then play every month to play it. I worry I would eat up too much time playing the game or feel like I had to play it to get my monies worth that month. I don't need a second job that is a game. I know I am generally pretty cheap. I don't buy new releases, I wait until they are sale usually on steam. I like to get Gold editions or multi-packs. When I play an RPG I generally finish it and I feel I get my monies worth out of it. I really enjoyed the Gothic series, Divine Divinity, the original Diablo (later ones became too multiplayer specific, still enjoyed them but not as much as the first), Might and Magic. Boy my wife was sick of MM6 by the time I finished it. Could only have done that before kids.

I enjoy a good FPS and have played through many of the single player experiences more than once. As weird as some of the Delta Force games were I have enjoyed them over and over through the years. Adventure games are fun to play with others helping you. Monkey Island and the Broken Sword series come to mind.

So far I have never signed up for a monthly fee based game. I have never made in app purchases. I did not buy fancy armor for any of the Elder Scrolls series. I like games that I buy, play at my own pace and play through more than once generally with years between the play sessions.

A lot of that is coming to an end. I play games on my phone that last just minutes a session. That is all the time I end up having. At best I try to carve out time each day to do crossword puzzles for a little mental challenge. I miss having an RPG story to return to a few nights a week spread over multiple months. I was gifted Torch Light 2 which was hack and slash and less RPG which I had fun playing and finished with multiple character types.

My son and I had a blast playing Portal 2 especially the co-op mode. We need to fire that up again for another play through. My wife had to keep the door to the computer room closed as we were laughing to hard for her to get any work done. We both have upgraded computers for this go round and it should be a really good time again. Sure, we will remember some of the tricks of the levels but there is a lot of timing involved and a lot of stupid ways to die. We need more co-op games.

We keep thinking computers will make our lives easier. They do remove some of the grunt work but they also make our lives harder. Keeping the wireless network up to snuff, adding new devices to the home network, print, scan, copy, collate, update drivers, new Android OS, new iOS, change the data plan, fix the NetFlix streaming issue, adjust the clock for DST and reboot you freaking car! Good thing I am in the tech field and can usually deal with the issues in a timely manner.

Wednesday, April 3, 2013

A handy Mac terminal command for getting IP without all the other junk of ifconfig

In a terminal window on a Mac you can type:


This will give you your IP address in the midst of a bunch of other stuff that is useful on occasion but usually not anything you care about.

If you type this:

ifconfig | grep "inet "

You will only see the lines related to your IP address which narrows things down a ton.

If you want to narrow it down a bit more you can do this:

ifconfig | grep "inet 192.168" 

If you are on a 192.168 network (which you probably are if using WiFi) then the top item in the list will be your IP address. Of course you can substitute 192.168 for your network prefix.

As a final helper if you need your IP address a lot you can add the following to your ~/.bashrc file

alias ip="ifconfig | grep 'inet 192.168'"

Reload .bashrc via

source ~/.bashrc

Now every time you type:


and press enter in a terminal window you will get your IP address without having your eyes dance all over the full output of ifconfig to find it.

If you forget what you set the alias to you can always type


This will show the current alias list. I also have

alias ls="ls -G"

This shows my directory information in color.