D style guide

H. S. Teoh hsteoh at quickfur.ath.cx
Mon Jun 17 13:09:56 PDT 2013


On Mon, Jun 17, 2013 at 12:58:08PM -0700, Ali Çehreli wrote:
> On 06/17/2013 12:09 PM, Joseph Rushton Wakeling wrote:
> 
> > On 06/17/2013 05:36 PM, Ali Çehreli wrote:
> >> I want that space. It is very common in most C++ guidelines as well.
> >
> > Any particular reason?  It's not something that had ever occurred
> to me as being
> > important one way or the other.
> 
> I have no idea why that style have evolved but I like it. :) The
> reason may be to distinguish from function calls:
> 
>     foo(expr)
> 
>     if (expr)
> 
> I can't think anything else.
[...]

Yeah, I find this distinction very helpful in distinguishing between a
function call and a built-in construct. Writing if(expr) without a space
just *feels* wrong.

One thing that *may* change my mind is in the unlikely event that D
adopts the (arguably questionable) convention of allowing a delegate
final argument to be placed outside of the closing parenthesis, i.e.:

	func(expr) {
		doSomething();
	}

is equivalent to:

	func(expr, { doSomething(); });

And:

	func(var; expr) {
		doSomething(var);
	}

is equivalent to:

	func(expr, (var) { doSomething(var); });

But I'm not sure this idea will ever fly, so for now, my stance is to
always use a space after "if". :-)


T

-- 
Prosperity breeds contempt, and poverty breeds consent. -- Suck.com


More information about the Digitalmars-d-learn mailing list