How 'terse' is too terse? -- Practical guidelines for expressing as much intent in as few characters

Posted by Christopher Altman on Stack Overflow See other posts from Stack Overflow or by Christopher Altman
Published on 2010-04-17T12:27:27Z Indexed on 2010/04/17 12:33 UTC
Read the original article Hit count: 281

Filed under:
|

First, I love writing as little code as possible. I think, and please correct me, one of the golden rules of programming is to express your code in as few of character as possible while maintaining human readability.

But I can get a little carried away. I can pack three or four lines into one statement, something like

$startDate = $dateTime > time() ? mktime(0,0,0,date('m',time()-86400),date('d',time()*2),2011) : time();
(Note: this is a notional example)

I can comprehend the above code when reading it. I prefer 'mushing' it all together because having less lines per page is a good thing to me.

So my question: When writing code and thinking about how compact or terse you can express yourself, what are some guidelines you use? Do you write multiple lines because you think it helps other people? Do you write as little as possible, but use comments? Or do you always look for the way to write as little code as possible and enjoy the rewards of compact statements?

(Just one slightly off topic comment: I love the Perl one-liners, but that is not what I am talking about here)

© Stack Overflow or respective owner

Related posts about best-practices

Related posts about advice