Android RegEx bug: ‘null’ replacement with Matcher.replaceAll

Android’s Regular Expressions engine is API compatible with the generic Java implementation, but under the hood uses ICU’s RegEx engine. This usually causes no problems, until it does and then you’re sortof fucked, but not really.

On a recent project, a subtle bug in Android’s Matcher.replaceAll behavior bit me. When replacing values of captured groups ('$1'</code,<code>'$2', etc), Android’s implementation replaced a reference to an empty group with the literal string 'null' instead of just skipping it (aka replacing with empty string ''), which is what most other Java implemetations do. The string 'null' is, I think, never the right behavior. And the inconsistency causes unit tests to pass when run on the desktop JRE to fail when run in Android, which is a major pain.

Fortunately Android is Open Source, and I was able to track down the offending piece of code, and just write myself a simple replacement that has the bug fixed:

You’re welcome. Yay Open Source!

Blogging more often, bye bye Twitter

I’ve been mostly off Twitter for a while now, interacting with it rarely, and only on my Phone. While I’ve had a vague feeling of uneasiness ever since they unveiled their now business friendly developer policies, it really hit home when my favorite Android twitter app, Falcon Pro, hit Twitter’s arbitrary user token limit (and Twitter declined to care). That, plus the Google Reader saga have jolted me out of complacency a bit.

It may be cliche, but “If you are not paying for it, you are the product” rings rather true at the moment.

So I’ll mostly be off Twitter (and Facebook too) now. Identi.ca seems inactive, but I will probably give it a shot too. I’m going to pick up the slack by actually blogging instead. Twitter seems to have completely killed my long form text writing ability. My Nexus 7 and bluetooth keyboard will hopefully help bring it back! Twitter is still good for publicity, so I’ll need to find a way to feed my blog links into Twitter.

Choices

They suck. It’s easy when it is ‘useless test to take’ vs ‘GSoC’. Painful for a lot of other things. Ugh.

Open License everything!

Should have done this a while back. Added a CC BY mark to the blog. Will add a notice to the front page as well, stating that all media I produce (when not bound to someone else’s copyright) is CC BY. I think code is already taken care of, but I’ll add a note here saying that all code I release (unless explicitly licensed otherwise) is CC0 Licensed.

Now to actually produce something of value…

(Thanks to Ironholds for the push)

 

Immortality of Youth

Reading this blog post from Wesley CrusherWil Wheaton reminded me first of my visit to the beach a few hours before Cyclone Nilam hit landfall (at the Thiruvanmiyur Beach). The fact that I couldn’t stand in one place (wind) and was constantly being attacked by sand – it was exhilarating.

The blog post also reminded me of how much I mis-treat my body. I’m surprised I’m not bedridden, immovable and with a host of diseases. Trading health for a wealth of incredible stories.

Immortality of youth, or plain old luck. Hopefully I’ll wisen up before either of them run out.

Worse is Worse

Richard Gabriel’s Worse is Better (falsly attributed to jwz by many), is a piece on how LISP lost out to C, despite being ‘better’.

Jim Waldo’s Worse is Worse notes, quite accurately, that what us geeks consider ‘better’ might not what is, in the context of the universe at large, ‘better’. To quote,

[…] what we see is that better is a complicated notion, and can depend on a variety of different metrics. It may be disappointing to find out that what we geeks think of as better may not be what our customers think is better. But finding this out shouldn’t surprise us too much.

There is also explanations on how on many of the examples used to justify worse as being ‘better’, the wrong criteria was being used.

The original piece has been used to justify people producing shoddy, shitty work quite frequently. Waldo agrees:

My problem with the slogan is that it has become a catch phrase for those who either haven’t read the original article, or have read it and either have forgotten what it really talked about or never understood it in the first place. As a catch phrase, it is often used to justify shoddy design, or following the crowd rather than doing what is right, or as short-hand for the real claim that our customers are too stupid to either appreciate or deserve high quality products. Why spend the time doing things right, this line of reasoning goes, when we all know that worse is better. You are far better off giving the customer something that you know is less than what you could produce, because they (those simple customers) will think that it is better.

The end result of this thinking is sloppy products that don’t work, are hard to use, or are unreliable (or all of the above). We try to convince our customers that this is the way software has to be, and then turn around and convince ourselves that they won’t pay for anything better. But we short-change our customers, and we cheapen our craft, when we put up with this sort of thinking. When the original article was produced, I don’t think that this is what the author had in mind; even if it was, it is time for us to reject the simple-minded interpretation of the slogan, and start putting out software that really is better (on the dimension of goodness that our customers have, not necessarily our own).

I’ve sadly had to personally witness this at a few places. When ‘shit work’ becomes acceptable, it very soon becomes the norm. Eventually people consider that not just the norm, but something to aspire to – as if producing something that is actually shit is, somehow, better than producing something actually better. If you notice that happening to yourself / your project, please step back a bit, trout yourself, and do the right thing.

The Month of Awesome (2012 Edition)

I left Chennai on the 3rd of November. I (will be) leaving Delhi on the 4th of December. That’s a 31 day trip. It taught me to be optimistic. It taught me in very real terms that the world is a large place, and so is life.

A few highlights:

  • Building an app from nothing to workable state in a few days
  • An actual first class train ride in India
  • Running into a bunch of random french people who ended up becoming travel buddies
  • Feeling small, and very temporary being in the ruins of Hampi. Here was a civilization that used to be great, reduced to rubble visited by 2-3 tourists a year. Our Data centers and Washington Monuments will be similar in a few hundred / thousand years. “The one thing a man can not truly have, is perspective” – DA.
  • The best lassi money can buy
  • First train ticket that was confirmed after being waitlisted
  • RAVE!
  • The scenery at the Goa Beaches
  • Learning to float in the ocean. ZOMG THIS IS AWESOME!
  • Pulling a passed out guy out of the ocean, and seeing how other locals react to that.
  • Watching Rob Moen try to negotiate with the local hawkers
  • Stopping at a Pharmacy every time we get into an Auto with Rob Moen
  • Being annoyed at Jon Robson’s eternal optimism,  and then eventually coming to accept that it is a good thing
  • Feeling incredibly unsafe in Aurangabad 2 days after Bal Thackaray’s death, harassed by a bunch of auto men.
  • Being told flat out that I’m not Indian, and having to pull out ID to prove otherwise
  • Being stranded in Aurangabad, with a bus journey out costing about 50 hours
  • An airport (Aurangabad) smelling of pure unadultered human shit.
  • Good things happening
  • Horrible horrible experience in Agra – Taj Mahal surrounded by lots and lots of slums with open sewers. Entire place being pimped out for money. The ‘two India’s in sharp contrast again
  • A 9 year old girl selling pens at traffic signals, speaking to me in a language I could not understand about things that do not need a spoken language to be understood
  • Surprised to find myself a grown up in Delhi

I’m sure I’m missing out a few things (intentionally or unintentionally) – and each of those things would merit a blog post of their own too. Maybe I’ll write them sometime. Maybe I’ll write about my (amazing) last year out too.

Thanks to @rakugojon, @riddems and @flyingclimber for making this awesome.

 

Happiness #1

Happiness is fixing a bug with no obvious cause with a one liner and pushing it out to five million people with wonderful support from a team sitting halfway across the world :-)