Category Archives: programming

Mobile Development

I’ve been excited for the past year or so about RubyMotion, and I was even more excited when they announced support for Android.

Then I went to WWDC.

I already felt like PhoneGap was too much of a disconnect.  Mobile web and PhoneGap are good in a pinch, and there are things that are more easily done in a web form.  However, I’ve had a growing feeling that if you have the ability to make a native app then that is the right answer.  Anything short of making a native app is a shortcut that you’ll eventually regret.

You already don’t control the ecosystem, but if you’re depending on someone’s abstraction of the native implementation then you’re one step removed from the metal.  More importantly, being as close as possible to the metal gives you a more intimate feel for the nuances of that platform.

iOS 8 doesn’t look all that different compared to the bold new look of iOS 7.  But everything is different.  Just slightly enhanced or extended.  Apps can work together seamlessly.  User interfaces are adaptive.  Everything changes, but ever so slightly.

If you’re not right up against that cutting edge, then how can you fully take advantage of everything the operating system gives you?

Leave a Comment

Filed under Android, iOS, programming

iOS Map Comparison

We experiment with a lot of things at work.  Tools.  Technologies.  Workflows.  Recently we were discussing an effective way to do native iOS development with the team.  I love RubyMotion.  I think it makes it faster and easier to create a native iOS app.  There is a learning curve, though.

We are considering doing a project where the app is native, and written is XCode, but the guts of the app are just web views fed by a Rails app.  But before we could really consider that as an option, we needed to know how it would handle mapping.

So I whipped up a quick and dirty RubyMotion app to see.  I used Leaflet for the HTML version, and had the webpage be served from as a resource in the app.

Choose your adventure
Choose your adventure
« 1 of 3 »

I didn’t see anything that scared me off.  You lose the native feel, but I’m not crazy about the MMMapView and it’s annotations.  I’d much rather work with Leaflet and use markers.

So it looks promising.

Here’s a link to the project: https://github.com/barrettclark/MapCompare

Leave a Comment

Filed under iOS, programming, ruby

Android vs Google Glass LocationManager

I’ve played around with location a lot in the past year at Sabre Labs, and also in my previous job at Geoforce.  I find it very interesting and fun to work with.  Recently in The Lab we took on a Google Glass project.  The Glass is an interesting animal.  It runs Android, but it’s ever so slightly different.   One area that tripped me up was location.

So, here is a comparison of LocationManager in Android vs LocationManager in Google Glass.

Android:


// Android-flavored location
locationManager = (LocationManager) getSystemService(Context.LOCATION_SERVICE);
locationManager.requestLocationUpdates(LocationManager.NETWORK_PROVIDER, 35000, 10, this);
locationManager.requestLocationUpdates(LocationManager.GPS_PROVIDER, 35000, 10, this);
Criteria criteria = new Criteria();
provider = locationManager.getBestProvider(criteria, false);

Google Glass:


// Google Glass-flavored location
locationManager = (LocationManager) context.getSystemService(Context.LOCATION_SERVICE);
Criteria criteria = new Criteria();
List<String> providers = locationManager.getProviders(criteria, true);
for (String provider : providers) {
    Log.d(TAG, provider);
    location = locationManager.getLastKnownLocation(provider);
    if (location != null) {
        this.onLocationChanged(location);
        // one location is probably sufficient
        break;
    } else {
        // probably don't need regular updates, but if we miss a last known location we might
        locationManager.requestLocationUpdates(provider, 35000, 10, this);
    }
}

You’ll note that there is an extra context. before the getSystemService call in the Glass example. That’s because I put the LocationManager in a separate singleton class, so I get the app’s context first.

I wanted to have a lot of utility classes off the main UI thread, and I only needed location to support a subset of API calls that I fire off to our service. HTTP requests have to be done asynchronously, so I had a good clean line of delineation between the view layer and object models.

Leave a Comment

Filed under Android, programming

Ruby Attr Antipattern

Recently I’ve seen a good handful of something that I’ve never seen before in the Ruby world, and it mystifies me. I’ve been going through exercises on Exercism (http://exercism.io), and in the Ruby exercises I’ve seen several people using private attr_accessor. What?

The argument, so far, has been that it’s the same as doing it the long way so why not?

It’s weird. That’s why not. It’s not expressive. That’s why not. It’s a lazy shortcut that still didn’t buy you anything. That’s why not.

An example:

class Demo
  def initialize(something)
    @something = something
  end

  def based_on_something
    something * 2
  end

  private
  attr_reader :something
end

So, I am all for the use of attr accessors, and I am all for tucking implementation details away in private methods. The use of a private attr does nothing for the latter. You’ve simply added more obscure code that doesn’t tell future you or future maintainers anything about what you intended or thought might happen. If you think the implementation might change or evolve, then go ahead and write the extra 2 lines to define the method explicitly. Otherwise just use the ivar.

Now, it’s entirely possible that I’m just being grumpy old man and shaking my cane. If there is a good reason that’s come along that I haven’t picked up on yet I would love to understand it. For now, though, I’m maintaining that this is a weird antipattern.

2 Comments

Filed under programming, ruby

IRB Benchmark Helper Method

Quick and dirty ruby benchmarking helper that you can stick in your .irbrc:

require 'benchmark'
def benchmark(n, &block)
  Benchmark.bm do |x|
    x.report do
      n.times { block.call }
    end
  end
end

Then call it like so:

str = "2013-01-21"
benchmark(10) do
  Date.parse(str)
end
benchmark(10) { Date.strptime(str, "%Y-%m-%d") }

Simples!

Leave a Comment

Filed under programming, ruby