Going With Xcode’s Code Style Flow

Other

If there’s one thing I’ve spent way too much time thinking about, it’s the way I format code (bracing and spacing). I know eventually I could get used to any reasonable style, so the time I spend reformatting Xcode’s generated code is useless busy work. All I really want is Apple to tell me “this is the way we want you to do it.” While Apple’s example projects don’t really have a consistent style, the code that Xcode generates for file templates and autocompletion does — the one true brace style.

So my style has evolved from something like this when I started working for myself last September:

- (void) myMethod: (id) sender
{
    for( int i; i < 10; 1++ )
    {
        printf( @"%d", i );
    }
}

To something more like Allman style:

- (void)myMethod:(id)sender
{
    for (int i; i < 10; i++)
    {
        printf(@"%d", i);
    }
}

And finally to K&R / 1TBS

- (void)myMethod:(id)sender
{
    for (int i; i < 10; i++) {
        printf(@"%d", i);
    }
}

So braces for method and function definitions go on the next line, everything else goes on on the same line. Are there practical reasons this style is better or worse than others? I’m sure. The style I was using before going independent spaces everything out a lot, so whatever reason to like it or not, there’s a lot of reformatting that’s going to occur, so moving to the second style was mostly to avoid that.

Always putting braces on the next line didn’t always work well either though, particularly with blocks. I just couldn’t find a way to make blocks look passably decent or work with Xcode’s auto-indenting while putting their opening brace on the next line.

Xcode’s autoindenting turns what would be this:

dispatch_async(dispatch_get_main_queue(), ^{
    // do something here
});

Into this:

dispatch_async(dispatch_get_main_queue(),
               ^{
                   // do something here
               });

But the biggest reason for making this switch is that’s the closest thing to a supported-style Xcode has — all of the file templates lay method definitions out this way, and so does autocomplete. I’m not working against my tools anymore, I don’t need to waste time reformatting, and that becomes time I can spend getting real work done.

Prioritizing Active Transportation in the United States

Other

I live in Portland Oregon, a place that’s often referred to as the Cycling Mecca of the United States. Indeed, it is relatively easy to get around by bike here compared to other cities I’ve lived in, but even here there seems to be a feeling by some that good enough is good enough, and it’s not. The fact that we have gotten as far as we have in Portland has more to do with the demand of the people who live here than anything else. You only need to compare pictures of bike roads in Amsterdam and compare it to a street heavily trafficked by bikes in Portland to see that. In one bikes are treated as equal and separated from cars, in the other we’re expected to take back streets, usually ride in traffic, and in all cases end up very close to cars. In the best cycling city in America, cyclists are second class citizens. Where does that put everywhere else in the country?

I do not believe there is anything inherently different about cities in the United States that mean we can’t do as good as countries in Europe — I think we lack political will. Prioritizing more motor vehicle infrastructure over cycling (and public transit) is short term thinking: we are running out of fossil fuels, we do have an obesity epidemic and we are destroying the environment. If you prioritize building infrastructure to encourage active transportation in the United States — and de-prioritize single occupant motor vehicle traffic — it helps all these things. There’s no reason to believe Americans inherently hate biking or walking — I think it’s just that only the very motivated one’s will to do it if it means riding next to cars in traffic.

What got me thinking about this was an article on the Bike Portland website about a woman who was hit by a car on her bike and could have easily died:

Indeed, I was lucky. Others, like Hank Bersani, have not been. And what is our government doing to prevent these tragedies? What has been done to protect our health and safety? A sharrow here or there, bike lanes that end randomly and traverse road debris and metal sewer grates, a few bike lights and yield signs… nothing of substance. Nothing that actually treats people, not vehicles, as a vested interest.

All of what she said is true. In the best bike city in the country we don’t have bike lanes on most major streets, and where they do exist they’re rarely — if ever — physically separated from motor vehicle traffic. How is that supposed to encourage anyone but the bravest and most confident cycles to get on a bike as a main form of transportation?

The author goes on quote a study which laid out the relative economic cost to society — through lowering costs of health care, infrastructure and road maintenance — of motor vehicle traffic vs bicycle traffic.

Bike infrastructure costs less to build and less to maintain than car infrastructure. There is a reduction in healthcare costs associated with regular cycling, and a recently reported study showed an equivalent $0.42 economic gain for every mile biked compared to a $0.20 economic loss for every mile driven. Supporting and encouraging citizens to bike is an investment that pays off, all while leaving extra funds for education and other basic services.

Who wouldn’t want to fight obesity (the Surgeon General estimates 300,000 people who die each year may be attributable to obesity), help the environment and save money that can be used elsewhere?

The article ends by calling out who’ve called building bike infrastructure frivolous, by bringing up the death of a local cyclist:

And even in these tight times, the funding is there. We just choose to do nothing. We choose to treat the loss of Hank Bersani, the devastation of his family and friends, and preventing the torment of the next family who will receive a similar solemn phone call as a “waste” of taxpayer resources.

The idea that doing things which can save lives, and also pays off economically, would be called frivolous or a waste by anyone is hard for me to get my head around.

I’m not a hippie, I’m not an environmental activist and I know that motor vehicles cannot be entirely replaced by biking and public transit. I’m a realist, and the more I think about this the more I see treating alternative forms as equal — and preferable when possible — is the kind of investment we’d all like to make, and that as a society we should make: low risk and high payout. We can do better.

A 2008 Ad From Portland Mayor Sam Adams

Other

Sam Adams is the person who isn’t running for mayor again due to having a consensual relationship with an adult. He was nice enough to once let me hang out with him and his colleagues without knowing me when I first moved here, and has responded to me directly on Twitter before to answer questions about the city.

Watching this ad from 2008, I can’t help but feel he still represents what Portland is about, and that we’re better for having him. Sad to see him go so soon.

http://blip.tv/play/Aar6HAI.html?p=1

http://a.blip.tv/api.swf#Aar6HAI

The Verge: “Next iPhone to Be Weirdly Proportioned”

Other

The 4 inch iPhone 5:

Colin’s idea was to keep the shorter side of the iPhones screen the same, i.e. 640 pixels at 1.94 inches. With that in mind how much would the longer side need to increase so the that diagonal measurement was 4 inches. The answer, derived using simple algebraic rearrangement of Pythagorus’s theorem, 1152 pixels and 3.49 inches. That leaves the the diagonal length measuring a little over 3.99 inches, I’m sure Apple PR could round this 4.

An iPhone proportioned this way would be weirdly tall — and Apple is not known for making things that are badly proportioned. This Colin person pulled this out of his ass, and I don’t know why The Verge would bother publishing an article about it.

Boosh. Called It.

Other

Simpsons creator explains Springfield reference:

Simpsons creator Matt Groening revealed to Smithsonian magazine which Springfield the Simpsons’ Springfield is named after.

(Via The Loop)

It was Springfield Oregon all along. Suck it every other state. Another interesting fact is that pretty much everything you know from The Simpsons is named after something in Portland — Matt Groening grew up here with his father Homer, mother Margaret, and sisters Lisa and Maggie.

Just Bought QuickCursor

Other

A bit behind the curve on this, but just bought a copy of QuickCursor, and I don’t know why I waited so long. What it does is let you set up global key commands for your favorite text editors on your Mac, send whatever’s in the current text field to them, and then when you close the document window the original text is replaced with your edited version. It’s awesome if you want to avoid having to type into a text box on a web page, or find yourself switching between text editors frequently.