Google+ Badge

Thursday, December 30, 2010

Synchronized Android and iPhone development

I have been working on both the Android and iPhone. We plan on releasing a new version of our app on the iPhone and the first version ever on the Android. My goal was to get the Android side to match the feature set of the iPhone side. Of course I ended up making some improvements on the Android side while I was at it. That meant I had to move those changes over to the iPhone.

At first I was pretty worried it was going to take a long time to move the changes over. Turns out I know just enough on the Xcode side that I was able to move almost all the changes over in less than one day. I am still not a big fan of Xcode / Objective C but I am getting faster at using it.

Since I had them both running it was time for some side by side comparisons. First thing I found out was our appointment recurrence code was not correct on the iPhone. The original author is no longer with the company so I needed to just figure it out. I had written that code from scratch on the Android earlier in the week. Lots of bitmask operations and all sorts of fun date manipulations. I thought porting it would be a big pain but it was not bad. I just looked up "day of week NSDate" and a few other things to be able to get to the source code snippets I needed. The one big difference is pulling time in Java is in milliseconds and in seconds in Objective C so I changed my math by a factor of 1,000 to fix that. Everything else ported very cleanly.

Below are my thoughts on differences I found. I am not saying either one is better than the other, just listing differences and annoyances I found with each platform. I have not used either platform for an extensive period of time.

(iPhone is really a version 2 iTouch, Android is my Samsung Galaxy S)

iPhone - Top of screen is used to show where you are and have a button to get back to previous screen. Gives you a bit of an odd look as the "Title" of the screen is not centered due to the button to its left.

Android - Title is over data and centered. There is a back button on every phone to take you back to the previous screen. Of course you don't always know where back happens to be.

iPhone - Layouts we are using take longer to generate and paint. Most likely due to slower hardware and I don't believe the layout code being used is very optimized. It is using WebUI for some things and I am sure that part of the issue.

iPhone - rotating phone forces you to watch the rotate animation. Look, animations are cool and all but I really just want to get work done. Maybe they should allow you to turn that off.

Both - the standard date picker stinks. They are both very similar with iPhone doing a fancier pinball wheel display but they both suck when you want to get to a specific date quickly. On the Android side phones are not consistent in what they show, some show the day of week which I think is very useful and others don't.  Pressing a [+] button 10 times to get to a date in the past is crappy. Trying to stop a spinning wheel with any sort of accuracy is no fun either. At least on the Android you can click on a field (month, day, year) and just type what you want. On the iPhone all you get is the spinner.

Both - Each platform has a perfectly fine date chooser in their base calendar applications. Oddly only the one on the Android allows you to rotate the screen. What logic Apple used to decide which base apps supported screen rotation and which ones don't truly escapes me. I need to find or write a date selection control similar to the base calendar controls that shows an entire month at a time with simple arrow keys to change month or year. Obviously people can accurately finger pick a date this way.

Android - I wish you could just plug-in any phone and dump the APK to it. Instead I end up hunting down USB drivers to make things work. Some phones have the USB drivers on them and will transfer them to the computer when you plug them in and others require a web search. We need to set up a mini-market on a server so I can just put the app there to let QA get to it. Once the driver is installed the copy to device is very easy, just the initial setup that stinks.

iPhone - You must provision each device with Apple to install anything on it. All devices use same USB driver. Every time you plug in a device is fires up iTunes and wants to sync which I find annoying. I run / debug in the simulator and only plug in the device for final testing. I have only ever used one iPhone device on my Mac so I don't know what will happen when I attempt to plug-in another one.

iPhone - I hate typing my password, which has numbers and uppercase letters. Too many presses to navigate to numbers etc. Android is easier with the long press to get to the one number I have in my password. Of course I have to type this a ton of times a day during testing. This is where the Simulator comes in handy, just type on the keyboard.

Android - Fonts look better. Bold looks more bold. I am using bold to help the data stand out from the labels. It just looks better on my Android device than on my iTouch device. I know it is a much better screen. I really want to see what it looks like on an iPhone 4.

iPhone - Touch input seems a bit more accurate. We have images next to certain lines of text that you press to invoke a mini-text editor. Seems to work easier on the iPhone. Could be a bigger touch target, could be screen differences.

iPhone - If you have a table with sections headers and you scroll the table the section header gets stuck at top of screen until the next section header hits it, the first section header then scrolls off and the second section header sticks. This is actually a pretty cool effect that you get for free.

iPhone - I still don't like Interface Builder and Xcode being separate applications. I did set up Spaces on the Mac and I plan on running each on their own virtual screen. I wish I had a dual monitor setup on my Mac like I do on my PC. I find it too easy to click off the UI element I am working on to get the focus rectangle to disappear so I can see what the layout looks like and accidentally click on some part of Xcode meaning the whole focus shifts and I have to meta+tab back to Xcode. This should be fixed with Xcode 4 when that gets released.

Totally random side note that still applies to this as it affects my programming

I asked for and got a set of Sennheiser wireless headphones for Christmas. The wired headphones I used at work had a pretty short wire and if moved to my right to use the Mac I would get a tug. Wireless seemed the way to go. I checked with some buddies and most said wireless sucks in general unless you get Sennheiser. The RS-120 seems like the way to go, decent price and rechargeable.

The verdict? I am very happy with the headphones. They were shutting off on me at first then I found a web post that you need to crank up the volume out of the computer and use the volume adjustment on the headphones to tweak the sound. Once I did that no more issues in that area.

Sound quality is very nice. They do a good job covering my ears. I can still hear people around me if needed. Could be a little more bass but that could be my sound source too. I did some tweaking in my sound card settings panel to help them out.

They are lighter than I figured they would be. I have Sony wired headphones that weigh more. Nice to not have much weight on your head. Good padding on the top of the adjustable over the head band.

The one thing I don't care for involves pausing sound. If the headphones are not getting a sound signal they output static, not super loud in my case as I don't run them loud at work but if your sound feed stops you get an earful of static. I generally hit the off switch on the headphones and pause button at same time. I also start the music before I put the headphones back on. User training but I wish it just went silent instead of static.

Tuesday, December 21, 2010

Finally have my app on the iPhone building / installing

This has been a long drawn out battle with the Mac, Apple and Xcode but I finally have my app running on the iTouch. It all starting trying to get an account with Apple so I could get a developer key. The account got hosed and it took many phone calls and emails to get it fixed. It was over a month and a total refund with cancellation of account to make it happen.

Yesterday I finally get a developer certificate set up. I plug in the iTouch which fires up iTunes which wants to do an install of latest iOS. I let it do that and then fire up Xcode where it says it can not work with the attached device even though it is registered with Apple under my account. I try to provision it but that only annoys it as I am not the company administrator. After looking up various things on the web I land on the dialog that states my SDK it out of date so Xcode can't deal with the device.

Hit the Apple site to download the SDK update, it is 3.5g! Honestly I could download every Java IDE out there for pretty much every OS and not add up to 3.5g of download. There is no "upgrade" either, you download the whole damn thing. Guess that makes it easier for Apple and keeps every Apple user out of trouble but it is a huge waste of bandwidth. Nothing I can do about it so I start the download knowing I will not be able continue my experiment until the next day.

This morning I installed the new SDK. That goes cleanly so I plug in the iTouch. It does not recognize it but asks to talk to it for a bit to discover things. No problem there. Do a build but it will not work on the device as the architecture does not match. I dig around in project properties - and remember this has all worked just fine in the iPhone simulator - and change it all from armv7 to armv6 and armv7. Build and it is mad, clean and build and it is still mad. Do more Google work and find another place you have to set it to armv6. Build and mad, clean and build and it seems to be mad but still it pops up on the device.

Runs just fine but I see a small change I want to make so I adjust the code and the build / run on device is no longer mad. Everything appears to be in working order at this time but it sure was a long battle. I know I had a minor battle with my Android phone to get proper USB drivers installed but everything else was very smooth. Even the USB battle only took a few hours tops, the iTouch battle was over a month. I really wanted this in place before Apple shut down for the holidays. Happy it is working but very frustrated with the overall developer experience with Apple.

Today I get to go back and work on the Android code base. Will be much happier over there but I am really glad I got the code pushed to the iTouch finally.

Thursday, December 9, 2010

I published my first Android game tonight

Must say this is a big ball of stress that I can throw back into the void. I began working on the game in October while I had some time off between my old and new job. Always good to take a little time off after giving notice.

If you have an Android phone and like logic puzzles do a search on "Grid Hunt" on the Android Market and give it a shot. The game is free. I decided to go the AdMob route to see how that works. Seems like a good time of the year to release a game. Lots of people will be getting new phones and people will be taking time off so they will have some extra gaming time. I know I hit the market every so often to see if there is something new to play for a few minutes.

Actually writing the game was the easy part. It became a real headache when I tried to tie in AdMob. There is not much in the way of documentation which is very unlike the rest of my Android experience. First off I wrote a game so I was using the full screen. I had forgotten that I plugged my view directly into the activity instead of doing it via the XML file. I put all the AdMob stuff into the XML and of course nothing happened.

I changed the code to use the XML to drive the view which meant a shuffle of some other things as I was not using the XML based constructor. I got that working but no AdMob so I shoved in a simple label and it painted on top of my game screen. I realized my game code was a custom view so I needed to tell the layout manager what my size happened to be. I added the following code:

* We want to take up almost all of the screen
protected void onMeasure(int width, int height) 
Display display = ((WindowManager) getContext().getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay();
int dispWidth = display.getWidth();
int dispHeight = display.getHeight();

setMeasuredDimension(dispWidth, dispHeight - 48);

This put the label at the bottom of the screen. I was then able to piddle around with the AdMob code to get it to appear. I really don't remember everything I did to get that to happen. I needed to get some options configured and I finally got some output in the less of reliable Android log window of Eclipse. I was able to get the special code line from the log console to show the test ads.

I configured a private key and used the really handy Eclipse export signed APK menu item and created a nice ready to roll APK.

I wanted to get this rolling tonight but I wanted to clean up the help text and add some separators in the options dialog. I plugged in my phone and it would not install the app! What the heck is going on here? I have been using my phone at work to develop our app there and I have been using IntelliJ. I did find a quick answer on the web. I just need to adjust the time out value in Eclipse. Then it started working again but not until my wife closed the door to the office due to my choice words of "I don't need to to ^%%$# happen to me tonight!"

When I tried to pull up the options screen it crashed. How could this happen? Turns out when I switched to the other XML style view loading I used same variable name hiding the one in the main class. I thought I had that warning enabled in Eclipse but I did not as I had started a new Eclipse workspace when I renamed parts of the project which annoyed SVN. I hate that part of Eclipse, I want my workspaces to all have the same warnings settings. I enabled nearly all warnings, fixed a few of those in the code and did the easy fix for the view issue. Once I figured it out so I was back on my way to having a fully functional app.

The Android Market Website was really easy to use. I plugged in my information and uploaded the file along with screen shots and descriptive text. I knew I had an issue with new ads not appearing but I though that would only happen after it was on the market. I was wrong. Ads still were not working, you got the first one but it never changed. So I checked the AdMob site and set it to override the interval then the ad did not show up at all! I unpublished the app and started doing Google searches.

I found out I have to set the interval which I tried to do in the attrs.xml file but I had no luck there. I never got the other attributes to work via the XML file but I did not really care to override the base colors. Now I needed something to work. I piddled around with that for too long and then found I could just do it directly in code so I set it up for 30 seconds. It worked as I tested the phone via the debug cable so I put it out on the web again after upping the version numbers.

Of course I sent out a note to all my buddies that have Android phones and put an update on my LinkedIn profile. Finally the brain dump on the blog. I sure learned a lot and I still think this is easier than the iPhone hell I have been going through with just getting a developer certificate. I still can't put my iPhone code on a stinking device.

I know I have been using a lot of things I learned from my game development for my work development. I was able to really chug along today at work on the login screen that I am redoing. Now I can take all my market place set up knowledge and use that too. We will not use Ad Mob for the app I am doing at work but if this game makes me a few bucks I am sure I will write a few more apps outside of work and I plan on using ads again. Since I now have real working code to look the next time it should fall into place really easily.

It will be interesting to see what comments I get on the game, how much money I am able to make off of it and how many downloads occur. I have some ideas for a two player mode which would make a really nice update if the games gets a few eyes on it. Always good to have an update after the game has been out a bit and I don't think there are many two player games out there. This will not be two playing at same time but one player solving the board then another player getting the same board and trying to beat the time or each player designing a board for the other to see who can screw the other one up the worst.

MigLayout Verification plug-in for IntelliJ - what it was like to write it

I am happy to report I have written my first plug-in for IntelliJ. It gets around the issues I reported in a previous post about MigLayout using strings for constraints and those strings are validated at run time. This puts in you the fun situation of writing code, running it, getting an error, fixing it and repeating until you have the constraint syntax correct.

That is no longer an issue if you use the MigLayout Verification plug-in for IntelliJ. I have submitted it to Jet Brains but have not heard back from them as of yet. You can grab it and manually install it from the MigLayout form if you want to give it a shot. Download from MigLayout forum. This will be moved to a permanent spot on his main page soon and hopefully available from JetBrains too.

If you look at the forum you can see the author of MigLayout is an IntelliJ user and is using the plug-in himself. I needed to contact him as I am using MigLayout code in my plug-in and I wanted to make sure that was OK with him per his license agreement. He was very kind and allowed me to use the code meaning the parse logic and errors you get are the exact same as the ones you would get at run time.

What does the plug-in do for you? It allows you to highlight the lines of text in your Java code that use MigLayout, press Alt+Shift+Y and it will find every constraint error in the code showing them to you in a console view. You can click on each error to have it pop to that line of code highlighting the string in error so you can fix it. Notice it is every error so you can quickly clean them all up. It handles layout, row, column and component constraints.

On a side note I am happy I did not try to name this blog based on a language. A lot of blogs are C# Corner or Java Jabbering etc. Since I end up all over the place - Android, iPhone, Java, C#, plug-ins, etc. that would have been pretty misleading.

What was it like to develop an IntelliJ plug-in?

Not easy which is a shame. The big issue was the lack of documentation. I figured IntelliJ had been out for a long time, they are in the process of finalizing the version 10 release and there appear to be a lot of plug-ins so there must be web sites about it and various bits of on-line help. That just was not the case. The only help I found was directly on the IntelliJ forums and a lot of that was many years out of date. See very bottom of this post for code snippets to solve the issues I mention.

I wrote the guts of the program using a MigLayout based test program. A basic text area with a button to parse and a listbox with the errors I found. I needed to get the code processing in place first as I have to skip comments, combine lines of code that span multiple lines, split out the string pieces, do RegEx processing and guess if it really is constraint etc. No need to do all that work with the plug-in overhead. Once I had that running I contacted the MigLayout author to see how he felt about things.

The initial plug-in documentation seemed pretty easy, set up an action, query the editor and parse. I have written Eclipse plug-ins in the past, in fact it was a whole RCP, so I remember how involved that can be. Very powerful but very involved with XML things here and linking three files perfectly via string names to tie it together. This was going to be so much easier.

First thing you can't just developer a plug-in using the out of the box community edition of IntelliJ. You have to install GIT and download the full source project. This is 1g worth of data. It failed on me the first two times. I had to make sure my machine did not come anywhere near going to sleep during the process. After that initial 1g hit was another 1/2g of deltas that got automatically downloaded. GIT is an all or nothing download so it does not restart in the middle if things to awry. It takes a really long time to download. Finally you have to build the program with a simple ant build script. No problem if you have ant installed and configured which I did not but that was easy to do.

It then creates a ZIP file for Windows and the proper images for the other support OS platforms. Honestly if would be nice if they just posted the 80 meg zip file I needed for Windows. This is a fully functional version of IntelliJ along with plug-in SDK support that you install.

You point your running instance to this new instance as the plug-in SDK and you can start code development. So far so good but there is very little sample code to get you started. I did a lot of source code scrounging and using the little bit of on-line help I could fine. I was able to figure out how to get the project, editor and document so I could pull out the selected lines. I found a way to determine what line number I was on and I could run my already functional parser and show the errors in an alert dialog. I wanted a console window.

Others have asked on the forums about the console window and I pieced together various posts to get it working but all I could output was straight text lines. I wanted you to be able to click on them to jump to the spot in the code of the issue. Others had asked the question with no answers. I did my first release to the developers at work without that support. In the end I did figure out how to use the printHyperlink call to do what I wanted.

Hot keys threw me off for a bit too. I misread the dialog and thought you put in two hot keys, a primary and a secondary but it really meant if you put in two the user would have to do them in order. I wanted different hot keys for the default key mapping vs. the Eclipse key mapping I use. I did not figure out how to do that so I finally found Alt+Shift+Y that was free in both mappings. Since access to the feature also appears in the Code menu you can still use it even if that key sequence is not available in your mapping.

Even getting to the name of the currently edited file was not something I was able to find on the forums. I pieced together how to do that too. While doing that I realized there were various deprecation warnings. I like my code to be warning free so I went about fixing those. Remember I said a lot of forum post are years old, many from 2004. I was able to clean up all the warnings and the new code looked better and is easier to read. One clean up just created new deprecation warnings around the console view. I was finally able to piece all that together and ended up with warning free.

The hyperlink stuff into the console window was confusing. Each hyperlink you create needs to implement an interface but the only call you get is public void navigate(Project project). You don't even get the text they clicked on! I was hoping to have one generic link click listener but instead I had to create a new object that implements the interface taking the text of the link in the constructor. From there I had to figure out all the editor document access to pull lines and selection model processing to scroll to and highlight the errors.

I am very happy with the end results and will get a lot of use out of the plug-in as I am sure others in the office and hopefully you will too. I don't have a good code formatter for blogspot so below are my code chunks that may help other plug-in developers.

UPDATE: The plug-in has been accepted by IntelliJ and is available from their website.  MigLayout Verifier at JetBrains

Imports I am using for all of the below

import com.intellij.execution.filters.TextConsoleBuilder;
import com.intellij.execution.filters.TextConsoleBuilderFactory;
import com.intellij.execution.ui.ConsoleView;
import com.intellij.execution.ui.ConsoleViewContentType;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.PlatformDataKeys;
import com.intellij.openapi.components.ServiceManager;
import com.intellij.openapi.editor.Editor;
import com.intellij.openapi.editor.SelectionModel;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.vfs.VirtualFile;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowAnchor;
import com.intellij.openapi.wm.ToolWindowManager;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;

Creating an associated console view in actionPerformed(AnActionEvent e) method

  if (project != null) {
      ToolWindowManager manager = ToolWindowManager.getInstance(project);
      ToolWindow window = manager.getToolWindow(id);
      if (window == null) {
          TextConsoleBuilderFactory factory = TextConsoleBuilderFactory.getInstance();
          TextConsoleBuilder builder = factory.createBuilder(project);
          view = builder.getConsole();
          window = manager.getToolWindow(id);

          if (window == null) {
              window = manager.registerToolWindow(id, true, ToolWindowAnchor.BOTTOM);
              ContentFactory contentFactory = ServiceManager.getService(ContentFactory.class);
              Content content = contentFactory.createContent(view.getComponent(), "", false);
                  public void run() {
                      // Nothing for us to do here

Jumping to a line of code and highlighting text on that line

public void actionPerformed(AnActionEvent e) {
  Editor editor = e.getData(PlatformDataKeys.EDITOR);
  String findMe = "Text to find on line"
  int line = {line in document you are processing - 1 based}

  int lineStart = editor.getDocument().getLineStartOffset(line - 1);
  int lineEnd = editor.getDocument().getLineEndOffset(line - 1);

  TextRange textRange = new TextRange(lineStart, lineEnd);

  String lineText = editor.getDocument().getText(textRange);
  int pos = lineText.indexOf(findMe);
  if (pos != -1) {
      SelectionModel selModel = editor.getSelectionModel();
      selModel.setSelection(lineStart + pos, lineStart + pos + findMe.length());
      ScrollingModel scrollModel = editor.getScrollingModel();
      scrollModel.scrollTo(new LogicalPosition(line - 1, col), ScrollType.MAKE_VISIBLE);

Getting file name of active editor

public void actionPerformed(AnActionEvent e) {
  VirtualFile virtualFile = e.getData(PlatformDataKeys.VIRTUAL_FILE);
  String fileName = virtualFile.getName()

Getting selected text and line where it starts

public void actionPerformed(AnActionEvent e) {
  Editor editor = e.getData(PlatformDataKeys.EDITOR);
  SelectionModel selModel = editor.getSelectionModel();

  int curLine = editor.getDocument().getLineNumber(selModel.getSelectionStart());
  String selText = selModel.getSelectedText();

Saturday, November 20, 2010

MigLayout - you really should try it

At my new job they used the NetBeans GUI editor to create their panels / dialog boxes. At some point they started to use MigLayout now want to replace all the existing panels. I started with around 220 and now have about 160 to convert.

So why use MigLayout? Why not GridBagLayout or one of the other Swing layouts? My previous job used GridBayLayout for everything even when a very simple BorderLayout would work. I wanted them to switch to MigLayout but it never happened. I have used MigLayout for a few of my side projects and I really like it.

MigLayout Pros:
  • Handles all your layout needs - if you draw it you can lay it out
  • Very simple to learn - string driven
  • Easy to read even if another developer did the initial layout
  • Very concise making for compact code
  • Will handle Mac vs. PC differences in button layout ([Cancel] [OK]  vs [OK] [Cancel])
  • Handles high DPI settings
  • Will handle insets for each OS (also a con, see below)
  • Easily lets you keep a set of controls to be the same size. You can have all buttons in a panel be the same width by putting them in a size group
  • Add special gaps to any side of a control. For some layouts you may want a little extra spacing above or below a control
MigLayout Cons:
  • Handles insets for each OS but the Mac uses large insets with can throw off look and will cause issues if you use setSize in your code for a dialog box. You can override the insets so you get the same look on every OS
  • Since it is string based you will not find out if you typed something in wrong until run time. Of course you are going to run the application anyway to make sure you layout is fine but your code is not validated by the compiler which is something you get used to with the base layouts
  • Another JAR file to include in your download
The Pros outweigh the Cons by a large margin. I have been able to take a screen shot of the current panel, drop it in Paint.NET on my second monitor and quickly type the new MigLayout code just looking at the screen shot. I don't have to sit down and draw out things like I did when I was doing a mix of BorderLayout, FlowLayout, GridLayout etc. I don't have to constantly do a row++ or column++ to add things to a GridBagLayout and I don't have to fill in some big GridBagConstraints object or pass a pile of parameters to a help method to add a component. Really it is as simple as this:

setLayout(new MigLayout("ins 5", "[grow]", "[][grow][]");
add(new JLabel("Enter comments:", "wrap");
add(textAreaScrollPane, "growx, growy, wrap");
add(okButton, "gapabove 10, split 2, aligny right, sg btn, tag ok");
add(cancelButton, "sg btn, tag cancel");

This would be a standard comment entry dialog with a label telling you want to enter, a text area in a scrollpane that grows vertically and horizontally to fill the space and the [OK] and [Cancel] buttons that are the same width right justified in the dialog box. The buttons are tagged so each OS can swap the order if needed. I put a 10 pixel gap above the [OK] [Cancel] button area to separate it a bit from the text area. The "sg btn" just puts them both in the same size group named "btn" you can name it whatever you want and have as may different size groups as you need. This is a tiny example. I have layouts at work with over 50 controls in them, everything is handled perfectly and all of it sizes as the user sizes the dialog box with no problems.

See a bunch of funky numbers in there? See me incrementing rows and columns? Nope, pretty clean stuff. Check out the MigLayout website to find out more. I am not associated with the program in any manner other than being a happy user for many years.

Thursday, November 11, 2010

Objective C is like programming with the dinosaurs

I finally got the HTML / GZIP / XML parsing to work on the Mac. Do you know what the problem was? I was not using the same version of the TouchXML code as the person who did that left. I described some of those issues in the last post.

This morning I downloaded an even newer version of TouchXML figuring that was the issue. It still crashed. I installed Wireshark on my PC and on the Mac. I though maybe the server call was hosed so I looked at the packets and they were fine. That meant it was the code at fault. Another developer and I worked on tracing through things and figuring out the odd way you have to query the contents of variables. If I would have known how to do that earlier I would not have messed with Wireshark.

For me it is hard to fathom why the XCode IDE is so behind the times. It is just not anywhere near as powerful as IntelliJ, Eclipse, NetBeans, Delphi, Borland C++ or Visual Studio. It is not that I am not a Mac guy it is just that I have used a lot of very nice IDEs. Have Mac developers not used other IDEs? Eclipse and IntelliJ are available on the Mac, I have used both on the Mac. They work just as well on that platform as they do on the PC. XCode is crappy. It does not have may hot keys, it does not support tabbed files, it loves to pop up all kinds of windows and the debugger stinks.

I just want to see the contents of my variables but it does not show them even things as simple as string don't show up. I used the GDB window to type "p (char *)[(NSString *)[element data] UTF8String] to see the data in a String! This is just crazy to me. In Java or C# I just hover over the variable and I see the contents. Even if it is just a NSString I still have to do "p (char *)[data UTF8String]. I had some really deep variables and it was a real pain to type all the typecasting to get any data out of them.

The IDE works, the debugger works, it is just a pain to get to your data.

Getting to the actual issue - the debug window was trying to tell me the problem. I thought it was crashing in a method but it turns out the method did not exist. Of course I am used to the compiler telling me with a very obvious compiler error not having this happen at run time in a debugger window. The new version of TouchXML changed from childElements to children and elementCount to childCount. I thought it was crashing in the childElements call getting back 0 elements thus annoying the loop. This is due to Objective C being a dynamic language. Part of my learning experience but man was it an annoying experience.

This is a bizarre situation, I was upgrading by accident as I had no idea what version the original developer used. Normally you would know you are upgrading and when the debugger complained you would spot the problem quickly. I was just happy I was able to get things to compile initially. I thought that meant I had the proper TouchXML code.

Things are not all rosy still. It is giving me back blank strings when I request the "name" for one of my XML items. I will have to chase that down too. Not crashing, just a blank string. No idea what is going on there. Just getting to a variable with no depth is bad but getting to a collection of things is going to be a major hassle. I hope I can find it quickly in the morning. Probably just leads to other issues and I am not going to trust the code until I can run it through all of its paces.

I will check it all in, including the new TouchXML classes tomorrow if I can get the XML strings to display. It is making us wonder if it would have been better to start this application from scratch instead of trying to update the code. That is pretty sad actually. Not something that I have done in other languages in a long time, just punted, unless the code was just super crappy. I think the code is generally OK it is the IDE and the language this is fighting me.

Tuesday, November 2, 2010

Initial iPhone Development Experience from a PC Java guy

At my new job I get to do some iPhone development. Not new development but some enhancements to an existing application. So far it has been a real uphill battle.

First all the code was not checked in to SVN. That meant I could not compile things after the initial check out. Once I figured out you can click on a red (ie bad) file and do Get Info to see where it thought it should come from I was able to figure the missing images. Luckily they were checked in to the build directory - not that the build directory should be in SVN but it was. The other files are part of TouchXML. I figured that out using Get Info and was able to locate the files on the web. Then all the frameworks links had to be updated as it was originally done with the 3.1 SDK but I have 3.2 and 4.0 installed on the Mac Mini I am working on so I had to point to newer versions.

First I copied the TouchXML files into the ExtraLibs directory as was suggested on the web but figured that was not really optimal for others to use and get from SVN so I moved them under the project. If we do more than one iPhone app that needs to share them we will move them into a shared project but there are no plans to do that at this time.

Next up was figuring out the xCode IDE. It does not appear to be as full featured as Eclipse or IntelliJ. All the basics are there but it seems to be missing some of the advanced things I am used to like multiple open files in tabs and hot key support for various actions. The keyboard actually drives me bonkers. I have a regular PC keyboard hooked up so at least I have a full set of keys and don't have to press extra FN to get to things I use on a regular basis. Pressing HOME - which I expect to go to the start of the line - takes me to the start of the file. I know, I just need to learn Mac keys but old habits are hard to break. I also have to press the Windows Key a lot to do things. Getting the hang of that.

I was able to get the program running in the debugger once I got all the libraries / frameworks linked properly to the project. It would run but accepted no mouse or keyboard input. I finally figured out I was running the emulator in iPad mode. Switching to iPhone mode and it worked. I thought iPad was just a big iPhone, sure app would maybe look ugly but should run. This is not the case. Don't have time to figure that out right now. It is my understanding the last build for the original developer works fine on the iPad. The IDE keeps switching back to iPad mode though which is really annoying. When I start it up to a rectangular emulator I know it is wrong, shut it down, change the target and start it up again.

Once you are familiar with the Android on screen keyboard the iTouch one seems really limited. All keys show as uppercase on the keyboard, the only way to know you are in uppercase is to see glow around the Shift Arrow. Keys only do one thing so you have to switch to symbol mode to get numbers and another mode to get some symbols. On the Android you can just hold down on a key and get to the associated symbol. Plus I love Swype now that I have started to use it. Finally the keyboard on the iTouch totally covers up where I am typing so I can't even see what I am entering and there is no Next button so I have to type then press ENTER then press on the next entry field and type. Data entry, which I have to do for user name and password really stinks. I have an iTouch at home and have used it a lot in the past. After using my Android phone I am much happier with it for data entry. Personal choice.

I finally got it to log in but now it crashes processing some XML data from my HTTP request. The data is coming back in GZIP format, because that is how I asked for it, but I don't think it is getting converted to plain text. I am in the bowels of code trying to figure that out. Maybe the TouchXML handles it or maybe some other code. I could be I got a newer version of TouchXML. The original author is not at the company and no one else has worked with this code. I don't know Objective C and have not worked on the Mac much so I am pretty handicapped at this point. It is a challenge.

For me the whole Android configuration was much easier and since I already know Java I could get up and running pretty quickly. I also knew Eclipse and the PC keyboard allowing me to start typing and experimenting right away. I started on a clean app so I could learn at an easier pace. Finally I did not get tossed a 3rd party library right at the start which meant I could write tiny bits of code and to see what happens without the worry of multiple frameworks in my way. And I comment my code, none of the iPhone source for this app is commented and it is not using iPhone standards for naming conventions making it extra fun.

The app is working on the iTouch. It is the code from the original author. I don't know if my build will run on the iTouch and it is just the emulator that is screwy. I can't put my code on the iTouch as I don't have the signing certificate set up yet. This was a fresh install of the development environment. It is nice the Android does not care about signing for you to run and debug on your device. Maybe the iTouch does not either, just seemed to be annoyed without that set up during my initial attempts. I need to get that working to see if I have to run that way for things to work but I also hate to kill the one working instance I have of the application.

Interface Builder (IB) is also another new area. Since the iPad version was not working I thought maybe some of the event connections got broken and I decide to hook them back up. They were not broken but I did learn a bit about IB while trying to figure that out. I also saw some on the net needed to remove / re-add connections to make things work so I went through that whole experiment. Threw me off when hitting the (+) button did nothing. It is a dragging starting point and not so much a button. You drag over to your classes and it will pop up things you can connect to. All makes sense once you know what to do.

I will say I was a bit surprised at all the information I could find on the Web. I was under the impression that Apple was keeping a lot of information under lock and key. The whole programming on the iPhone was supposed to be shrouded in mystery. I did not find that to be the case. Pretty much anything I did a search on via Google popped up numerous results with quick answers. My misconception probably came from a few years back when a lot of the SDK talk was NDA making it hard to publish much without raising the ire of Apple.

SVN support in xCode seems workable but again does not work as it does in a lot of other PC based IDEs. I was finally able to check in code - mainly the missing files - but it took some doing. I think part of the issue was the build directory files being checked in which annoyed SVN on both the PC and the Mac side of things. There were temp files with ~ in them which SVN does not care for in the least. I cleaned it up using TortoiseSVN on the PC then the PC and Mac both worked. There just are so many more free tools on the PC to get things done in this area and again I have used them in the past. It was easy for me to quickly give up on the Mac, do it on PC and move back to Mac to move forward on the app again.

Am I saying the Android development environment is totally superior to the iPhone or the PC is better than the Mac? No, I was more familiar with everything about the Android environment - IDE, Windows and Java so it was easier for me. Not being a Mac person I am learning a whole new way of looking at things. I am not saying right or wrong, just different and difficult at this stage. I have learned enough programming languages and frameworks in the past that I figure I can get up to speed in a reasonable amount of time. I will learn the keyboard, various short cuts and all the cool stuff you can do with Interface Builder, xCode, Objective C and the iPhone SDK. Right now I am in the newbie struggle mode but I will enjoy the challenge and hope to find many things on the Mac that I miss on the PC.

Maybe I should port my Android game to the iTouch which would give me a balanced picture of development on both sides. I will have to wait until we give the Mac Mini to QA at work and I start using a Macbook for my iTouch development so I can do that conversion at home on my own time. Of course I still have some performance and other tweaks I want to do to my Android version and I would like to finish them up first but starting a new job has meant I am mentally burnt out by the time I get home so final touch up to a game is really not high on my list. Making money from a game is so I should push myself...

Monday, October 18, 2010

My first Android app - 18 things I learned

I have written my first Android application. It is a game and it works pretty well on my phone and the emulator. I still want to tweak the sound effects to match the themes and to maybe add a two player mode. Then I will have to decide how to release it on the market. I could go with a lite free version and a small charge paid version or I could go with an ad supported free version. Leaning toward the ad supported free version at this point.

For this discussion the actual app does not matter. I want to cover what I learned. First off I have been programming in Java for a number of years so this is not about Java programming.

1. If you know Java then Android programming feels pretty natural but there are enough differences that you can't make assumptions. I got burnt more than once.

2. Setting up the environment took more than I expected. Everything is out on the web and I was happy to find a lot of on-line support no matter my question. What took a bit was a lot to download for all the Android flavors from 14. to 2.2. I had a little issue finding the proper USB driver so I could debug on my actual phone.

3. Running directly on the phone is faster than using the emulator. Plus it really shows the experience as you use your finger instead of a mouse. When you drag small things around with the mouse they are easy to see, not so much with the finger. The emulator is pretty solid. I did not find differences between what the phone did and what the emulator did.

4. Eclipse is a really nice IDE. Drop files into the drawable directory and they show up as resource IDs automatically. It does have some issues. It did not install the app 100% of the times when I pressed the run button. Could be the phone's fault. I was not totally consistent in swiping to unlock and getting ready to run. I also had the IDE pause when using intellisense, very annoying.

5. The UI does not stop running when you show an alert dialog. Something you get used to in Swing. Not a big deal, once you know that you just code with it in mind and it does make sense. You don't want to freeze the UI waiting on the user.

6. Rectangle is left, top, right, bottom instead of x, y, width, height. Just something to remember. 

7. Checkbox uses isChecked and setChecked. I had code to do isSelected and setSelected. The code compiled but did not do what I expected. Made an assumption. Never understood why Swing did not use the properly named methods. Glad Android does.

8. There is no Combobox but there is a Spinner. When I think Spinner I think numbers but the Android Spinner does the work of the Combobox and it does it just fine.

9. Strings belong in string resources, not in your code. I am familiar with this as the Java code I have written has been internationalized. Of course I was not doing that by default, I was hacking together code to make it work but in the end I moved all the strings into string resources.

10. The canvas is pretty powerful. All the features I needed were supported and well named.

11. Not all phones are equal. Different screen resolution being the big one. I have a new phone so I have a big screen. I set the emulator for a smaller screen. I need to tweak the code even more to fit as many screens as possible and to not leave dead space on big screens.

12. You have to draw a lot of icons. I had an icon in my drawable directory but it was not the one I would see on the phone. I had to drop special sized ones in each of the drawable directories to have the proper one to show up. Even at that the proper one only showed up under applications. I had put a short cut to my app on one of my screens but that icon did not change during the next app install. I had to remove it and re-add it to the screen to get it to change. Icons are not a standard Windows size - 256x256, 128x128, 64x64 but are 72x72, 48x48 and 36x36.

13. Playing sound is easy but they don't always play to the end. I need to figure out why that is happening. The API is really straight forward.

14. The amount of on-line information is impressive. The official Android help pages are a great starting point then I would use what I found there to find some solid example code. I was always able to find what I needed with minimal searching. 

15. The preference system is simple. I needed to save the sound, flashing and theme settings. Find a quick sample and 5 minutes later it was in place.

16. The options dialog was harder than I thought it should be. This seems like something that nearly every app will need so I thought there would be base classes to handle it. I found what I needed on the web but I can see where we will not see standardized dialogs.

17. I love the menu button, something I wish the iTouch had, but I had to dig around to find images for that area. These images tend to be gray scale with an indented look. Not typical color icons. I wanted to stay consistent with t;he Android look so I found where they are hidden in the SDK samples.

18. I was worried the game would take a long time to write but I got it done in a few days. I had the game running in Swing so the engine was ready to roll. I took the game to a new level with themes and greatly improved graphics. I also put in a help system using a basic alert dialog. I never did a help system with the Swing version as I did not want to learn RoboHelp or some other HTML based help system. I really could have cheated like I did with Android, just never push myself to do it.

All in all I am very impressed with the Android platform. I am late to the game so others have done the hard stuff and published a ton of code samples for me to use. It appears the SDK team learned from various Swing mistakes and weirdness producing a cleaner API. I am sure I forgot a lot of other things I learned, this is just my first Android app and I don't consider the app done. It is fully functional but like any piece of art it never really feels done. I will have to choose a stopping point and release it one day.

Monday, October 4, 2010

I now own and Android phone

Various things came into play but I decided to buy an Android phone. I have the Samsung Galaxy S via T-Mobile, which was my current carrier. First, my son is doing a lot of things with Boy Scouts so he has needed a phone while out in the neighborhood selling popcorn, trash bags and grocery store coupon books. He has also had to borrow others phones numerous times to get hold of us after camp outs.

Second my wife calls me to get web information while she is out and about. Mainly phone numbers and addresses. She has an older BlackBerry but with the new data plan it also gets web access.

Finally I am going to get to do some coding on a project for the Android and just using the emulator seemed like not the way to go. You always want to run on the real hardware if you have the chance.

I have an iTouch so most of the operation is very familiar. Still learning all the ins and outs. Seems to be a solid phone, very fast and I am happy with it so far. Nice to have the web in your pocket all the time. I was able to monitor NFL scores while out shopping yesterday.

Wednesday, September 29, 2010

Internationalization in Java - when is a number not a number?

The Java product I work on is internationalized and localized - well it turns out for the most part. I updated the code some time back to allow the user to type in numbers in their locale so a German speaking user can type 600,25 (notice the comma instead of a decimal point) and we should consider that to be 600.25 in English.

Two problems arose, the masked entry field I wrote handled this just fine allowing user to type in numbers using their locale settings but the code in others areas converted the typed text to a Double using Double.valueOf(text) and it would fail by tossing and exception. I switched the code to NumberFormat.getInstance().parse(text), adjusted to catch the proper exception and everything now works. This code area allows users to enter custom property values.

One thing I found out, NumberFormat returns a Number. That might be a Double or a Long. If you parse 85 you get a Long. If you parse 85.43 you get a Double. You can ask the Number for its doubleValue if you always want the double. I was getting a typecast error on occasion until I figured this out. If you send in an empty string you get a parse error. You may want to check for that before you parse to assign a default value of Double.MAX_VALUE to indicate empty or 0 if you want empty strings to equal a zero value.

Second problem came from the advanced search area where we allow users to search for previously entered data. We used the same masked entry control but never converted the output to a number. The server takes the search statement as a string so there seemed to be no need. Of course there is a need. The code looks a bit silly but I take the text, convert to a number and convert back to text so it will be in English format to send to the server.
String numOne = numberFieldOne.getText();

// We convert to a number then back to text for i18n reasons
// All numbers set to server in English format, this forces that rule
   numOne = NumberFormat.getInstance().parse(numOne).toString();
catch (ParseException e)
   numOne = numberFieldOne.getText();

Everything is up and running again. The company has a big push toward international expansion so it was critical that we solved these issues. I must say Eclipse pop-up help on methods is very handy. I viewed the pop-up for Integer.valueOf and it suggested using NumberFormat instead. I love it when you are handed the answer without needing to do a web search right from the IDE.

Converting existing code to i18n can be painful, making it i18n from the start and keeping it that way can be a big help. I will add this discovery to my i18n toolbox. Seems pretty rare for users to type in floating point values but it does happen and you need to account for it.

Monday, September 27, 2010

Why does Java paint different under different Mac browsers?

I understand there are differences between Java on a PC vs. Mac vs. Linux. We have code in place to check for each. Even some code for OS subsets such as some special code for Win7 and Vista vs. older Windows flavors. They added fancy pants painting to the combobox in Vista so my custom control paint needed to reflect those changes.

What gets me is I can run our applet on my PC under Chrome, Firefox, IE, Safari or Opera and it looks the same. All the colors match, buttons look identical, my custom controls paint exactly the same. I can see no differences.

Today I get a few bugs about things not painting correctly on the Mac. No big deal, I grab the development team's laptop, update the OS, update Java and install latest versions of Safari, Firefox, Opera and Chrome. Run Chrome as my testbed and fix the items reported by QA. Just an hour or so of pretty easy work. Then I decided to run the software to see if I spotted any new issues and I found some with toolbar button painting. I resolved those under Chrome then ran it in Safari. Background is a lot darker over the main toolbar but buttons are readable. Then I run it under Firefox and when you have a toggle button on the toolbar you can not tell which button is toggled. It gets a special outline and color in Chrome, Safari and Opera just not Firefox.

Safari on Mac
Firefox on Mac

The three right most green buttons are a toggle group, only one will be selected. They are fit to screen, fit to width and fit to height. On Safari you can clearly tell you are in fit to screen mode. Under Firefox you have no idea.

According to the Java console window that pops up as I run Java in each browser I am running JDK 1.6 update 20 in each one. I am not using any special paint code for this button, just using standard JToggleButton. I did not touch code in this area for my other bug fixes. I run an older version of our applet and it still looks bad in Firefox. Why does the JToggleButton paint differently in a JToolBar between browsers? Why is the browser controlling the background color of the toolbar in some cases? This is not how WORA is supposed to work. Of course I know WORA does not work between OS vendors or versions but I did not expect the browser to mess me up.

My other Mac bug was about things painting outside the custom control. On the PC in Java if you set a clip region outside the control you are currently painting it still gets auto clipped to your control. It was a simple fix, I just did an intersection between the current clip and the rectangle I was about to paint thus if it was out of bounds on the Mac I did not paint where I should not be painting. No Mac check, worked fine on PC with the intersection check. I did add a comment as to why the clipping is there and really it is the most legal way to handle things but it was the Mac that forced the work back on the developer, not saying the Mac was wrong, just the PC Java was friendlier.

We need to test more often on the Mac. It is an important platform. We have clients using it. Stinks that I have to dig down this deep to fix things and now I have a new problem between browsers that I am not sure how to even fix. Has anyone else run into the JToggleButton paint issue?

Wednesday, September 22, 2010

Two Java rotates - one works one does not (sometimes)

Why does this code not always work?
        g2.translate(translate.width, translate.height);
        g2.rotate((myRotate * Math.PI) / 180, 0, 0);
        g2.drawImage(image, 0, 0, null);

This code appears to work in all our test situation

        AffineTransform trans = AffineTransform.getTranslateInstance(translate.width, translate.height);
        trans.rotate((myRotate * Math.PI) / 180);
        g2.drawImage(image, 0, 0, null);

This came up as a client issue. I did not write the original code but I was asked to help track down and resolve this rather annoying issue. When I run the old code on my machine it runs just fine. When we run the old code on a VM on another machine it works fine but running it as a servlet under Tomcat and it screws up and does not generate a rotated image. You get an empty rectangle instead.

The problem is now fully fixed but it just seems odd that the AffineTransform works where the standard rotate does not. You don't get any errors / exceptions. You just don't get a rotated image. We are going to run some timing tests between the two calls as we are curious which is faster. Of course faster and broken is broken so we will not switch back to the original code but we want to make sure server performance is not impacted massively with the new code in place. If this was client side processing we would be less worried but you still want things to run as fast as possible.

Tuesday, September 21, 2010

When all else fails upgrade the JRE

Another team was having issues with some image manipulation so they asked me to help out. They had traced it down to some code doing an image rotation. Code was very simple so no obvious problem. The code was happening in the servelet, get a TIFF, convert to PNG, scale it down and rotate it if the rotation flag on original TIFF was set.

Special TIFF (aren't they all?) so we use the 3rd party library from Acordex to load them and same them as a PNG. Everything there was working fine so I took the code out of the servlet and made a stand alone Java project. It worked perfectly. I wrote out the images to a temp directory at various stages.

I then created a JAR file with the test code so we could run it on the VM using same set up as the Tomcat based servlet. JAR did not run because I cheated to pull the 3rd party code from another JAR. Grabbed FatJar for Eclipse and built a new JAR with all the stuff I needed.

Worked like a champ on the machine of the developer I was helping. Put it on the customer identical VM and it did not work. Everything up to the rotate was fine but the rotate produced nothing for an image. Both I and the developer running JDK 1.6 update 21, the customer VM was update 6. Updated the customer VM to update 21 and it ran just fine. Did some searching for known rotate issues but did not find any. Figured the we have a fix for the customer so might as well let it go at that.

Update 6 is pretty old, don't think the custom is going to fight the upgrade. Anything below 19 is pretty suspect due to security issues anyway. I hate to blame the JRE first, always figure it has to be my code at fault especially when I am not doing anything out of the ordinary. Best be is to create a small test program if possible to narrow things down. Glad this one is off the books.

Monday, September 20, 2010

People will always use the tools they know

My son's school sends out a weekly PDF document of activities. I thought it looked a little odd but was not too worried about it. This week it came as a MS publisher file because they said the scanner was broken. From that I deducted the following steps were happening each week:

1) Create the newsletter in MS Publisher
2) Print it
3) Scan it as a PDF
4) Email it

Not everyone can open a publisher file, the PDF format is the way to go as the reader is free. Same reason I sent out our Christmas letter in PDF format. The oddness came from the PDF I got being scanned. I knew it looked grainy but was not sure if that was a look they intended. Some like the whole retro thing.

I sent the principal a note that they can just get a free printer driver allowing you to print from any program directly into a PDF skipping steps 2 and 3 plus giving you a much nicer looking final product for the email. He just responded that he downloaded the program and it worked like a champ so they will start doing things that way from now on.

Happy to be able to help the school out as they do so much for my kid and all the children that attend.

It always amazes me to what extremes people will go with the tools they have. Not every fix involves a download of something either. Just knowing a different formula in Excel can save hours of manual labor.

I photoshopped a picture for my son's birthday cake. They said bring in the picture, I asked can I bring in a CD or a USB key. I was told they can only scan images so I had to bring in a hard copy picture. I have a feeling that is not really how it has to work but I gave up and printed the picture and gave them that. The cake came out fine, a printed image slapped on icing is going to look fuzzy anyway but I have a feeling there is a way to pull this off without a scanner. Silly image ends up as a JPG in there somewhere why not just start out with that as the source?

Not that I have never done the same sort of thing, taken way too many steps to do a simple process when someone that is an expert in that area could have trimmed it down to two mouse clicks. I bet I did a lot wrong during my photoshop session with the picture. Happens when you don't do something very often but as so as I have to repeat a process the first thing I think is "Computers are meant to handle repeating tasks, I will figure out a way to bend a computer to my will" and I usually do. Sometimes you give up totally, other times you give up and then one day read something on the internet that reminds you of how stupid your process is and you fix it.

Monday, September 13, 2010

Android - too early or too late?

I really want an Android phone so I can write some Java code for it. Is it too early or too late to do that? Tech moves so fast you hate to get stuck with a $500 device that is outdated in a few weeks.

Too early - they keep updating the OS. 2.2 is out now, talks of 3.0 and a "new way of doing things" on the way. Will all 2.1 and earlier phones be left out in the dark? I think the talk of fragmentation is a bit overboard but I still worry. I can get a PC and update the OS pretty much at will. Seems like you are partially held hostage by your phone vendor. When will Samsung release 2.2 for the Galaxy S series? Will they fix the WiFi vs. 3G issues? How long before they abandon this phone series totally?

Just when I am about to pull the trigger I start to do some research on the Galaxy series and see it has various WiFi issues. It will stay connected if plugged in but not if on battery. Wants to hit 3G when you have WiFi. Look I am pretty cost thrifty. I would not even get 3G service, I want the phone to be a phone, do texting, play some games and let me write some code for it but I don't want to pay for 3G. I am around a WiFi network 95% of the time. I would buy the phone outright and not do a service place which I hope means I will not get hassled at purchase time.

My wife has a Blackberry without a data service plan, she uses the calendar part of it for everything and the keyboard for texting. There are times a little 3G access would do her some good, she calls me and has me look up stuff on the internet a few times a month, but is it worth an extra $30 a month to avoid that? Everything in life is just another $10 here and $30 there so you have to draw the line. Guess that is why I don't play WoW, adding another monthly expense and the fear of addiction keep me at bay.

Too late - lots have already bought them. Are my programming ideas too late to the party to be worth anything? Coding for a mobile device seems to be the wave of the future though. Having that programming experience has to pay off. Probably better to get on board now rather than totally miss the boat.

I have downloaded the Android SDK and Eclipse plug-in more than once and have installed it on my main machine at home and a laptop I use from time to time. I know I can start coding against the emulator but that thrill may run dry quickly if I can't run it on a real phone. I would not want to write something and release it in the wild without testing it on actual hardware. If I am to get into the game I need to buy the equipment. It is a $500 investment in my future. I could sit down and write code to see what I think of the SDK and then when my first game is done I will have to buy a phone right?

Second worry is the wife will play with the phone and want one too. They have a special going now if you rent to own one you get one free. We are doing a "no plan" deal now to save money, the only way to get a "free" one is to go onto a 2 year plan. Would I get back that difference by being on a plan? I wont if they force you to a 3G data plan. There is no doubt she uses more features of the phone than I do and I bet she would prefer this over her Blackberry. Not looking to spend $1,000 outright to get two with no plan.

I have an iTouch at home. It gets a lot of use for quick and easy web lookups. Instant on is wonderful, being able to use it nearly anywhere in the house is perfect. We keep it by the bed at night so we can check on the weather when we wake up so we know how to dress the kids for school. I was watching football updates on it yesterday. My son uses it for homework, easier than a laptop when you are sprawled out on the floor. The Android would add to that experience as it appears to be a very similar device. Not that we fight over time on the iTouch.

For now I am going to follow the Galaxy forms to see if Samsung fixes the issues with the 2.2 update or some other patch if it is a firmware or driver issue. I need to sit down and write some code in the emulator too and get myself all pumped up for owning one.

Friday, September 10, 2010

Win7 Taskbar - I like it but they forgot things

To speed up my C# development process I pinned the EXE of our project to the Taskbar of Win7. How does this help? When I press the (>) run button or hit F5 in the IDE it does another build process to make sure all the stuff it needs is in place. Waste of time when all I did was make simple code changes I want to test and am pretty darn sure there is no debugging involved. I can always attach to the process if I want to debug anyway.

So I pin it, easy to do, but it has the ugly generic icon. I could go and change the icon in the code to solve that but we have a deal with our UX team, no icon before its time. If it is ugly and generic or it is a standard [?] image then everyone knows UX has not designed and approved an image. Company rule, I just follow it.

Next step, Windows has always allowed you to assign any icon you like to a program. A lot of programs, MS Office comes to mind, have a number of icons included in their main EXE. I try all sorts of clicking on the taskbar to try and get to a properties so I can change the icon. No luck. Hit Google and search the web and find out you need to navigate to the following directory (with your user name of course):

C:\Users\kpeck\AppData\Roaming\Microsoft\Internet Explorer\Quick Launch\User Pinned\TaskBar

Then you can right click on the shortcut and adjust the properties there. Dang MS, why the heck is this such a pain in the behind? I like the other changes to the Taskbar but this is about as old school as you can get. Hate to explain to my mom how to change an icon on a very visible part of the user interface.

Next I had to go find a suitable icon so I found one of Bender from Futurama. Sure I went from a generic icon to one that has no association to my application and spent 15 minutes doing it. What else do you expect from a programmer? Sometimes you just have to stop and figure out a solution to a problem even if the end result is close to pointless. My guess is the info will come in handy in the future, this sort of knowledge almost always does.

Tuesday, September 7, 2010

Why Java beats C++ and C# when you really want to be productive

I have programmed in a lot of languages over time and the one I always come back to when I want quick productivity, notice I did not necessarily say quick run time, is Java. Why would that be?

First off you can just start typing your ideas and get the program running quickly. In C++ every time you write a few lines of code you have to think about writing the anti-lines too. Create it and clean it up. C# is a dead tie with Java here usually. The one are that gets a little annoying is being in the Dialog editor, clicking on a control, click on "OnClick" event and having it pop you back into editor to write the code. There are a lot of times I know I want "OnClick" events for 5 buttons on a dialog, I don't want it switching to the editor over and over. I want to stay on the Dialog until all 5 stubs are in place then I will do my code editing.

I have done a lot of code reviews. When we reviewed C++ code you could take a single CPP file and find all sorts of issues - potential memory leaks - unnecessary string conversions - etc. Reviewing Java code means looking and how multiple objects interact. Basically the language eliminates the chances of making a lot of stupid mistakes. It cleans up memory usage, there is only one String class. This allowed us to look at the architecture instead of just the syntax. I was not doing C# when I was doing C++ vs. Java code reviews but I have a feeling it would be very similar to Java.

If I need to do a simple dialog box to say open a file, read in settings and allow a user to change settings and save them back I use C# / WinForms. The only reason for this is WinForms makes it so easy to lay out a dialog box. Not that Java is super hard but you have to think about what layouts to use, how to lay them out in relationship to each other and write all the code to create the controls and panels. I do it all day long but that does not mean I enjoy it. WinForms is a clear winner in this area for me most of the time. There are odd anchoring situations that WinForms can just not handle where a GridBagLayout of MigLayout in Java are coded with ease.

When you get into C# / WPF you are basically back in the Java world. Sure there is an editor but it is not the most friendly thing in the world. Add to this you are looking in two files, XAML and CS, to keep it all tied together and you lose a little bit to Java side as a programmer. I know the XAML split makes it much easier if you have a designer and developer working in tandem. In the end it is probably the correct way to split the presentation from the code and data.

C++ has a Dialog editor of course but it stinks when you need to resize and move controls about. Then you have to deal with MFC on the back side which is really a terrible thin wrapper over the Win32 API and it is not object oriented. MFC has a very limited set of controls and they are hard to customize adding to your pain. When I was doing a lot of dialog work with a team in London I would do all the prototypes in C# and after many meetings getting the look hammered out I would convert it to C++ / MFC. This seems to be a great approach as WinForms allowed nearly instant tweaks so I could send a prototype back to them in the middle of the conference call which would have taken too much coding effort to pull off in MFC.

The one huge issue that hits home once a project starts to grow in size is compile time speed. In Java using Eclipse the program is basically always built. You know all the compile time errors instantly and when you hit run it just runs. Even the web project I work on, which takes an extra step to build jars and deploy them to Apache Tomcat, is an ANT script I wrote that takes an average of 8 seconds to build 4 jar files totaling 6.4 meg. That allows me to update code, JAR it and test it in seconds. We have multiple projects that share the same common Java code. I keep them all loaded in Eclipse so I instantly know if any code changes I make in the common areas break other projects.

The C++ project takes 45 minutes to build. We have build errors nightly on that project as people build and test small parts of code but don't build and test the whole thing. Who has time to do that more than once a day? Plus if there is shared code you have to build multiple projects to know if you broke other areas. That pretty much never happens.

The C# project, which is barely functional as we are just getting it off the ground, takes 5 minutes to build. I really feel the wasted time. In Java I stay in my constant coding cycle all day long. I rarely mess with the C++ code. For the C# cycle you get bored waiting on the compile so you check out a blog or other websites while you wait then you forget to check back to see it is done building. Finally you get to test your code if you can remember what you were even trying to fix 10 minutes later. This project is being written in a modular manner with various DLLs and a single EXE tied together using MEF. This adds to the compile time as files due to HD access for all the file copies that are going on. I am sure this could be sped up. Stand alone smaller applications I have worked on in the past seemed to build a lot faster, nearly Java speed.

It can be a wash at the start of a project when you are writing large amounts of code between compiles but let's say you are trying to tweak a small area of fix a little bug where the debugger is just not giving enough info. I ran into this when dealing with the 3rd party license issue with C#. Add two lines of code, build, run, try again. I have done that plenty in Java but it became quickly painful and very unproductive feeling in C#.

Java wins for being the most productive over the life of a product. Plus it runs on multiple platforms and I can use it write stand alone applications or Web apps. It is not the most friendly for building the initial UI or Dialogs but it is very flexible in this area and all your dialogs are resizable for (almost) free allowing for easier internationalization.

C# / WinForms wins for small dialog based products. Quick to layout and quick to build and test. Best used for standalone apps. Harder to internationalize as the localization folks need to touch every dialog. Limited to one OS.

I feel like I have the most control over the look and feel in C# / WPF as you can get very fancy with very little programming effort. Every control is custom draw because even list box elements can be a panel with anything in it you want and data binding is very easy. Can be used for both stand alone and Web apps although you switch to Silverlight with it owns set of special limitations to go that route. I have a feeling all the flexibility will cause things to run slower as the application grows. There is always a penalty to be paid for eye candy.

Expertly written C++ can be the winner for stand alone applications if you want pure speed and want to be able to use every ounce of the OS you are running against. You can talk to every device hanging off your system or network. There are times that needs to happen but those times are getting rarer. You can use QT for cross platform. I don't think many would choose C++ for Web apps. You do pay the price at development time, harder to find and fix bugs, longer compile times and older tools across the board to help you out. Great language for a lot of uses, always handy to know how to read it.

So there you have it, I like Java the best right now. C# / WPF might grow on me if we can get in there and optimize the compile time and delve into all the flexibility with a designer by my side . C# / WinForms seems to have its uses but is not the direction MS is going at this time. C++ still has many uses but is not where I would start to write smaller utilities or to write a fancy pants UI.

Thursday, September 2, 2010

It's Alive

Finally have the DotImage code working so that QA can actually see an image from the nightly build. What a pain. The Atalasoft team was very helpful and between their suggestions and some tweaking on my end we finally have it working today. Took nearly a full week of tinkering which is not very productive and hopefully someone will not accidentally make a change that screws it all up in the future.

On a totally different topic: I don't often buy things just for myself but I just wanted to get the Starsky and Hutch Gran Turino and the original Batmobile from the 60's TV series in 1/18th scale for my computer desk collection. I found them on-line for a reasonable price and they arrived today.

The Gran Turino has the slap on police light on the top, proper paint and rims. I know I bought the glue it together yourself model kit as a kid. They never had the real car as a kit I could find. As close as I got was a Chevy Nova, probably was a Gran Turino out there but I did not know enough to tell the difference at the time. Sure I got it at Alco in Salina. I painted the stripe, I bet it looked like crap, and I remember I painted it across the trunk instead of over the roof. The next week when the show was on I had noticed what a screwup I was and I had to repaint my stupid model. Bet it made it look twice as bad as I just painted right on top of a lousy paint job with a second lousy coat. I know I used masking tape for the job and I am sure I pulled off some paint in the process but I had my Starsky and Hutch car.

The Batmobile is a model I always wanted as a kid and saw at the overpriced hobby store in the mall in Salina every time we went in there. I still have this car in 1/64th scale as a hot wheels car and have always loved it. Just verified it is in the hotwheels case right here in the computer room closet. Cheesy as they come but man I wanted that car in a larger scale. It was my goal to ask Grandma Peck to buy this for me if she ever came to town but it was out of the proper asking for a gift price range. The one there was a 1/24th scale and sat in a special display case. Don't know the price, it was probably around $40.

Every car I have has a story and I just needed to add these stories to my collection. Trevor and Spencer thought they were pretty cool. They also have the Duke's of Hazzard, KITT and the Trans Am from Smokey and the Bandit at the same store, maybe another day.

Thursday, August 26, 2010

3rd party software is a gigantic pain

Third party software is a huge pain. We are using the new imaging software and I can build and run just fine but the rest of the office is hosed. This is all licensing based. I totally understand their need to make money. They only license the developer side, you can distribute all you like which is wonderful. So where is the problem?

We only have a couple of developers who will actually code against this third party library. Everyone else is working on other areas such a search, server communication, project support etc. They can't build and run the system without a license. You can't have a person casually contribute to the product.

Right now I am trying to get some code in place to check for a valid license and basically show them a blank area on the screen if they don't have a license. All the other developers will not be able to view any pages of an documents but will be able to do anything else they like with the system.

This will not affect QA as they will get a build from the nightly build box which will have the license allow the build to be distributed. This is not a long term solution, others need to be able to fully run the product to verify their work.

I really like this product, I just hate the pirates have ruined so many aspects of coding that I have to put up with a license system that makes sense for small shops where every touches the same areas of the code but not for larger places where people work in isolated small parts of a bigger system.

Monday, August 23, 2010

Have you ever won anything from a website or web survey?

I get a lot of e-mails to do surveys for various computer sites / web magazines. The promise of a $100 GC or maybe an iPad is always attached. I fill them out from time to time if I think I have any input on the subject at hand but I have never won anything. Some promise 10 or more people will win something. Has anyone ever won something off one of these deals? I would guess they have to be on the up and up but who sees the list of winners?

NewEgg at least will post the winners after a graphics card give away. I just want to win one so I can have a reason to upgrade the rest of my computer. "Sorry honey but I just won a $400 graphic card but I don't have the proper slot on my motherboard to use it, time to upgrade to take advantage of the free thing I got!"

I would also love to win an Android phone. Don't see contests for that. I have a Samsung phone that has a keyboard for text messages but the keys tend to double bounce and it does not auto start a new sentence after you hit SPACE twice like the BlackBerry did. I liked the BlackBerry keyboard, did not have issues with double letters or missed letters. Wife took over that phone. Don't do wireless contracts so I would have to buy an Android outright. They keep changing them around so I keep hesitating as I really want 2.2 OS at a minimum and I want a phone I can upgrade the OS on later. Hate to get locked down. One day I will pull the trigger.

Thursday, August 19, 2010

3rd party gets big quick

We have one 3rd party package right now for our C# project. It is 12.1m is size. The entire Java product is 7.5m in size. Ouch. This means without any support code, just a base library, we are already at almost double the size.

Part of the plan was to have the C# product on the Silverlight side be faster than the Java product. While I have always felt they will be similar in performance especially when most of the speed is related to data coming across the network, I now feel that things can easily be much slower if we have the initial download hit that becomes 4x the size of our Java product.

When I asked some buddies about this they stated they have never seem lean and mean C# libraries. Not sure why the code is not as tight, too much XAML? That should compress nicely but it is rather wordy.

Tuesday, August 17, 2010

How much 3rd party software should you use?

We program in three main languages: C++, Java and C#. The C++ project uses a number of third party controls and you hear a lot of complaints from that team about them. We get fixes from time to time and have to upgrade. Some items are never fixed and we just have to tell clients "That is just the way it is".

On the Java side we did our best to get 3rd party usage to a minimum. We use one for viewing images, so many formats to deal with it was just easier. We do run into bugs with them from time to time especially with threading issues. We used more controls at one point in time but I pretty much rewrote them from scratch so we have full control over how they paint and interact. I have written the following controls in Java for our product: Spinning hotdogs progress indicator, masked entry field, Checkbox list, font chooser dialog, color picker combobox, date selection combobox, Gradient panel, Link Label, Sizable toolbar (shows >> when buttons don't fit), Status view port (show status message when the table held is empty), Find panel (like those used in browsers), extended combobox with images and indenting support, spinbar, custom property grid with multiple level support.

That is a hodgepodge of stuff you probably would not find in a single collection of controls from another vendor which means you would have multiple JAR files and licences to deal with. Of course that list has grown over time and I have gotten pretty quick at writing controls. I have written them since the Win 3.0 days when it was one per DLL in C. Still they can be a bear to maintain and that is why there are companies out there that specialize in them instead of depending on one guy at their company to do the work in their spare project time. Since the C++ team already has a tool set any time the Java team needs one I just have to whip it up as part of my assigned task.

Now we are working on C# and we have to decide if we write our own or license some libraries. I really want to write our own as we have been bitten so many times in the past by 3rd party glitches but when you talk C# we have two areas: WPF and Silverlight. That could end up being a nightmare. It takes time to write them and it could mean we get a library to start and then write just the ones we use out of the library at a later time. Plus we are new to the language which slows you down even more. To make a lot of quick progress and get to demo stage we will probably have to go 3rd party. I hope it does not burn us too hard.

Thursday, August 12, 2010

Why don't developers care about warnings or code consistency?

Maybe I am just one of those oddball anal developers but I don't care for warnings in my code and I want all the code to be consistent. Consistent code makes it so much easier for another developer to start on a project. As we add more developers at work, and it could be that a number of them are straight out of college, we are getting a very lax attitude on programming.

When I first started here there were over 8,000 warnings in the code base I was assigned to work on. Over time I got that down to zero then turned on even more warnings in Eclipse until I was happy with how clean the code was and we have kept it at zero. New full time developers on the project have been told zero warnings are the normal and since there were zero warnings on the day they started what could they argue?

We have a standard set of warnings which is even easier to do now that Eclipse 3.6 is out and you can export that part of the workspace. I have a webpage with full screen shots of our warnings on the internal Wiki page. Takes a little time to set up but once you do you just keep in lock step with everyone else. If you start a project with no warnings then any warnings that appear are very obvious and usually very easy to fix. I did the hard work and cleaned them up, at least others could play nice and keep it that way. When there were piles of warnings they were easy to ignore, now there are not but people still seem to be able to ignore them.

The second piece of annoyance for the day is people who write new code and don't follow any of the patterns of the existing code. When we write a boolean to the server it is written as a string either "1" or "0". All of our code is i18n friendly but of course those two strings are not kept in a string table. We have a method to write a boolean value called sendBool(bool value) that writes the "1" or "0" as needed. So the developer does not use the helper method that is used by all the other messages but instead puts in the string with an if statement and does not flag the strings with  //$NON-NLS-1$ and thus the warnings.

Even after I sent a note about configuring Eclipse for the warnings and a code review stating you need to use the utility method all they did was use the comment to kill the warning. My code review was totally ignored. I know this is not the right thing to do but I just fixed the code myself. I still think there are other issues with the code that need to be raised so I will have to find a nice way to bring those up.

This has been repeating over and over as they add "casual" developers to the project. People that are not on the project full time but are "helping out" by changing a server message and the associated Java code. At this point they are not helping and for every one added to a project I go through the same steps over again even though I have sent out various development team wide emails on the issue. Easy to get ignored if your are not the architect or a manager I guess.

What is the stance on warnings in the code where you work?

Monday, August 9, 2010

Faking data from log files

Our C# server team is behind schedule. Without server data it is rather hard to get a whole lot of front end work in place. I was putting in little fake files and opening them and reading strings to simulate the server call. As I was just about to do that again I thought about how stupid it was to open the log file, tear out a snippet of data and copy it to temp file again and again. Why not just read directly from the log file?

With our system you can turn on logging. It logs out each request with parameters and response from the server in plain ASCII text. You don't get binary data for pages and thumbnails but that is such a small part of the server calls I am dealing with now I can get around it. I wrote our log parser that helps you diagnose the log file for problems so I had code to steal.

I wrote a Server Log Data provider that allows you to send a message to the server by rolling through the log file looking for the same message tag with the same parameter list and it will return you the data from the file. Works really slick and is allowing me to get various singleton caches in place with some real data.

You have to use our main clients and perform all the steps, such as opening an image and selecting annotations, that you want written to the log file. You can then replay that by making same server calls, in any order, into your C# code.

I say replay but it is not really a replay of the log file like some testing tools use. Did not want that as I have not set up the code to handle all the messages as of yet. Plus this is a request / response type system so just shoving data at the application does not make much sense.

I have even found some redundant data issues caused by our server. I am adding key = value pairs to a C# Dictionary collection. You can't add duplicates. The collections we use in Java and C++ just replace the value and don't really care if you use a duplicate key. C# throws an exception. This issue has been reported to the server team. If they fix the issue it will save bandwidth so this tool is already starting to pay for itself.