Concise Code - Does it make things hard to read?

Some thoughts scribbled down on Monday 07 July 2008 at 07:50 AM

I was using Resharper 4 and noticed some nice code cleanup advise that it gives. One to note it the compression of:

// Create job if quote is won
if (CurrentQuote.Status == "A")
{
    quoteView.FindControl("btnCreateJobCard").Visible = true;
}
else
{
    quoteView.FindControl("btnCreateJobCard").Visible = false;
}

To the one liner (which I prefer)

// Create job if quote is won
quoteView.FindControl("btnCreateJobCard").Visible = CurrentQuote.Status == "A";

I like short succinct code. I think the shortened form is better, but I know some people need to do a double take to see what it's trying to do.

I would love to hear your opinions on this.

Comments

Tue 08 Jul 2008 at 8:53 PM

Cameron Townshend

Eric, good stuff, I'd prefer ...").Visible = (CurrentQuote.Status == QuoteStatus.Active) cause I find enums easier to read and understand and brackets are also simpler but not as succinct.

Permalink

Tue 05 Aug 2008 at 9:55 AM

Eric Phan → http://blog.ericphan.info/

I agree with you there Cameron. Those strings should be enumerations.

Permalink

Tue 05 Aug 2008 at 11:13 AM

Ed Brown

I prefer code to be as readable as possible. Having said that, I do tend to make code as tight as possible inside loops but outside of that I make it easy to read.

Permalink

Post your comment