Monday, June 1, 2015

How Not to Crash #7: Dealing With Nothing

Brent Simmons:

With some OS X release (10.5, I think) Apple changed the format for crash logs on disk. I think they had been one file per app, and Apple switched to one file per crash. I had to write new code to handle the new format.

I made the change. It went to beta testers, who used the app extensively. Weeks passed. All good.

Then, on the day I released this version, I got a ton of reports from people who said, “It’s crashing on launch! But it works fine after launching it again.”

Update (2015-06-02): Mark Berstein:

If you do find yourself writing lots of if(thing)... tests, though, you might be better off passing a Null Object -- a subclass of the expected class that does nothing, and does it quickly.

[…]

So, instead of checking, Tinderbox initializes views with an instance of NoLayoutPolicy. If a view is being constructed and isn't quite ready to do real work, we can still call Prepare() in perfect safety. If we’re about to disassemble a window, we can replace its layout policy with a fresh NoLayoutPolicy, confident that if someone tries to refresh the window we’re demolishing, there will be a NoLayoutPolicy standing read to do nothing.

Comments RSS · Twitter

Leave a Comment