March 2009

You are currently browsing the monthly archive for March 2009.

I’m retired

After 12 years of training cheerleading, I retired yesterday. I soft retired last year, but I found myself really missing it and wanting to get back involved. I joined the CheerGyms.com open team and cheered for them throughout the season. While I enjoyed cheering for the team, the logistics of the situation didn’t work out for me. The team originally said they would be splitting time between both gyms. One in San Jose and the other in Concord. San Jose was 30 minutes away, Concord was about an 70 minutes away. I decided to do the team anyway. The drive meant that I was up before 8 most Sundays. I couldn’t go out late with friends on Saturday for fear of being to too tired at practice. On top of the cheering aspect I coached a local high school. Coaching would take up Friday nights with football games, which meant that I really didn’t have a weekend.

So, I’ve made a decision, and this time I’m going to try to keep to it. I’m going to retire from cheering myself. I’m still going to coach. I don’t think I’ll ever be removed from the sport completely, but for now I’m a coach and not a cheerleader. I feel I can be a better coach then cheerleader as this point. If it ever comes back to the point where I feel in shape enough to cheer and find a team convenient enough to be on, I’ll revisit it. For now, however, stick a fork in me, I’m done.

We went up to Napa this past Saturday. On the way back, after the majority of the car had consumed a significant amount of wine, we stopped off at Taylor’s Refresher for a burger before the drive home. One member of our crew decided that we should get a full bottle of wine. Just so we are clear, I don’t really drink, I had a few tastings that day, but had already consumed more than I had wanted to, so I was out on the bottle. The three remaining members decided to attack a bottle of red wine in one lunch sitting.

The wine of choice, something interesting, called “The Climber”. A nice red, with a mix of various different types of wine. Sounded interesting, so they got it. Once we got it to the table, we realized, with some shock, that the wine was made by Cliff. The same company that does the amazing Clif energy bars. Needless to say, after they were thoroughly “happy” off their wine, the bottle was rinsed and the cork was wrapped and packed along for the trip home.

I’m going to write a post soon on The Brand Gap: Expanded Edition, but one interesting part of the book talks about the relevance of products used to extend a brand. I’m not sure that wine has a strong correlation to the core clif bar business, but if my friends are any indication of the clif consumer, they were ecstatic when they found the bottle and this might just work.

Note: I did not actually try this wine, by this point I was done drinking, so I cannot comment on the taste. Those who were drinking it said they somewhat enjoyed the taste, but that the novelty of the item might have had an impact on that enjoyment.

I’m not much of a PHP guy, but I chose WordPress for this blog because I feel it is the most stable, well refined, yet easy to use blogging tool out there. Once the platform was decided I started looking for themes that worked well. I finally found something that I really liked when I stumbled on Ciaran Walsh’s blog. The theme is called JustSimple.

It’s a great theme, and I enjoy it on my site, but there areas where it has come up short. Mostly in styles for certain elements. I started a simple github project for my changes to JustSimple Project. One such change I’ve made is to add support for Definition Lists. Terms are bold and definitions are padded left.

If you want, you can download the theme from github (with a shameless use of the definition list):

Zip Format
Zip File
Tar Format
Tar File

Almost two months ago I went to a CocoaHeads meeting during Macworld. They had Mike Lee talk. His presentation was about “Pimping Your App”. There were a bunch of interesting points, but one thing really stuck in my head. Mike was talking about how is a messy person in his life. His car is messy. His room is messy. His desk is messy. Everything is messy, except his code. HIs code is crystal clean, squeaky even. As a programmer you need to make sure your code is consistent and clean. Ever since I have been thinking about standardizing the way I write code. This is the first post in hopefully a stream of posts about quality code.

Yesterday, there was a discussion in the office about code quality. There were many points discussed, topics like line length, white space, and my personal favorite “if” statements. I have a track record of being incredibly inconsistent with my “if” block. The basic if block is the following:

if(foo) {
  //...
}

The “if” statement by itself is really not that big of a deal. It’s when you start adding “else if” and “else” clauses that it becomes complicated. The problem for me is twofold. Firstly, I’m inconsistent. The type of blocks I use on larger sections of code is different from the blocks I use on smaller sections of code. Secondly, my desire for consistency is at odds with my crazy, cooky desire to have code look aesthetically pleasing.

The Condensed If Block

I sometimes use the following style of the if statement:

if( foo ) {
   //...
} else if( bar ) {
   //...
} else {
   //...
}

This block is very condensed. You throw the braces for each clause on it’s own line. I feel that it this type of statement makes it clear and easy to really make the if statements a smaller part of the code. On trivial if blocks, I really like this approach. Where it suffers is in more complex if statements. If the ifs and else ifs fit really just blend into the code, sometimes making it easy to miss them. Okay, so if I’m looking at the code in detail, not a big ideal, but if I’m just giving it a quick glance over I might miss something. Also, if the “if” statement line is long enough, it could easily blend into the line below it.

The Almost Condensed If Block

This one is a take on the Condensed If block. It is actually just really poorly formatted “if” statements, but I often find myself using this one:

if( foo )
{
   //...
} else if( bar ) {
   //...
} else {
   //...
}

All we are doing here is moving the opening brace from the end of the if statement to the next line. The rest of the code follows the condensed. So, I really like this approach because the first “if” block is clearly separated from the rest of the code. It’s clear that we are are entering an “if” statement line. The remainder of the statements don’t take up too much space. The closing brace, the else if/else, and the following opening brace are all on the same line.

The downside of this approach is that it looks inconsistent. Why does the initial “if” statement get one extra return, and all the subsequent lines statements get jammed into one line? It’s not functionally different, and it might in general be more appealing to me, but consistency is also important. I have started to shift away from using this style.

The Intermediate If Block

This one has more white space:

if( foo ) {
   //...
}
else if ( bar ) {
   //...
}
else {
   //...
}

This approach has gives you a little bit more separation of the control statements from the code. For some reason, though, I just feel it looks weird to write the close brace on its own line but then incorporate the opening brace on the same line as the control statement. Still feels inconsistent.

White Space Heaven If Block

The following block is the last if style I’m going to talk about:

if( foo )
{
   //...
}
else if( bar )
{
   //...
}
else
{
   //...
}

This block takes up a very large amount of space, everything gets its own line. It is probably the clearest of all the examples above, but the trade off is that your code is now three lines longer for each else statement. This extra space means that you can theoretically fit less code in the same amount of screen space.

Additional Concerns

There are a couple of additional concerns when working with if blocks. For example, if you are chaining “if” blocks, how much space should you provide.

// What I don't like
if(foo)
{
   //...
}
if(bar)
{
   //...
}

// What I prefer
if(foo)
{
   //...
}

if(bar)
{
   //...
}

I have run into some people who prefer the first option above with no space between each block. The reason I dislike this so much is that depending on the method of “if” syntax you use, you second if block could look identical to your else blocks. As your code gets large and complex, it is important to make it as easy to discern different control paths that might be executed, and in this case, white space is really your friend.

Another concern is the ternary operator. This operator is basically a simple “if/else” block which fits on one line.

double number;
if(foo)
    number = 3.1415;
else
    number = 2.71828183;

// As opposed to
double number = foo ? 3.1415 : 2.71828183;

Ternary operators are great for doing assignments as in the one line above, but be careful with trying to do too much in one line. My general rule is the line is getting really long, or I’m doing multiple clauses in my condition I tend to shift away from ternary operator.

Conclusion

The problem with all of this is that my mind changes depending on where I am in, what I’m working on and what I plan to be doing with my code. I’m learning towards using the condensed form of the “if” block in the future for the simple reason that I can fit more lines of code in less space (not to mention that some pointed out it was the K&R way, too). Bottom line, whatever method you choose, you should really stick to it as best you can for each project. If you open up a file in a project that was edited by someone else, you should probably follow their precedence.

Today I made my first post to Vimeo. I found this old video of my gymnastics. It’s old, not completed, but was fun to find and fun to post. Enjoy


Partial Sampler 2006 from Zachary Cohen on Vimeo.

In an amazing post on Daring Fireball John Gruber quotes the technology directory for a public school in Massachusetts:

However, even iLife has its drawbacks in an educational setting. It simply hands so much to the students that they struggle with software (whether Windows, Linux, or even pro-level software on the Mac) that isn’t so brilliantly plug and play. Yes, iLife rocks in many ways, but the level of spoonfeeding it encourages actually makes me think twice about using it widely, especially at the high school level.

To which Gruber responds

So the problem with Apple’s iLife apps is that they’re too good, and kids never learn that they need to struggle with technical issues before using software to express themselves creatively.

I agree with Gruber. However, I don’t think we should limit the discussion to just creative Apps. Modern day software is built on complexity. A consultant at my company once said that if we made the software too easy to use, then the consultants would be out of work; our product wouldn’t sell because it would to be too easy to use. I don’t necessarily agree with the argument, but the fear is common, and not unique to my current company.

Would easier software put people out of work?

I don’t think so. I think it would change the focus. If we started designing our software with a greater attention to user experience, the access time could be spent on further improving that experience, instead of support calls. Apple’s iLife wasn’t easy to create. Each of the apps has had millions of reviews, UI meetings, discussions, arguments and refinements. This wondrous amount of work has lead to an incredibly intuitive suite of tools. It would be fantastic if we could switch our focus (as an industry), from simply providing more tools, to providing better tools. Perhaps than our software will “too easy” for them to teach in school.