Re: [PATCH v3 01/38] sequencer: avoid unnecessary curly braces

4 messages, 4 authors, 2017-01-16 · open the first message on its own page

Re: [PATCH v3 01/38] sequencer: avoid unnecessary curly braces

From: Junio C Hamano <hidden>
Date: 2017-01-12 18:35:45

Johannes Schindelin [off-list ref] writes:
quoted hunk
 
-	if (!commit->parents) {
+	if (!commit->parents)
 		parent = NULL;
-	}
 	else if (commit->parents->next) {
 		/* Reverting or cherry-picking a merge commit */
 		int cnt;
The result becomes

	if (...)
		single statement;
	else if (...) {
		multiple;
                statements;
        }

which is not quite an improvement.  

The preferred style is for all arms in if/elseif/else cascade to
either use or not use brace pairs, so I think a fix toward that goal
would be more like:

	if (!commit->parents) {
		parent = NULL;
-	}                
-	else if (commit->parents->next) {
+	} else if (commit->parents->next) {
		/* Reverting ...

Re: [PATCH v3 01/38] sequencer: avoid unnecessary curly braces

From: Johannes Schindelin <hidden>
Date: 2017-01-14 18:04:06

Hi Junio,

On Thu, 12 Jan 2017, Junio C Hamano wrote:
Johannes Schindelin [off-list ref] writes:
quoted
 
-	if (!commit->parents) {
+	if (!commit->parents)
 		parent = NULL;
-	}
 	else if (commit->parents->next) {
 		/* Reverting or cherry-picking a merge commit */
 		int cnt;
The result becomes

	if (...)
		single statement;
	else if (...) {
		multiple;
                statements;
        }

which is not quite an improvement.  
Yet, this used to be the coding style of Git, and your statement comes
quite as a surprise to me.

Ciao,
Johannes

Re: [PATCH v3 01/38] sequencer: avoid unnecessary curly braces

From: Jeff King <hidden>
Date: 2017-01-14 18:05:58

On Sat, Jan 14, 2017 at 06:57:13PM +0100, Johannes Schindelin wrote:
On Thu, 12 Jan 2017, Junio C Hamano wrote:
quoted
Johannes Schindelin [off-list ref] writes:
quoted
 
-	if (!commit->parents) {
+	if (!commit->parents)
 		parent = NULL;
-	}
 	else if (commit->parents->next) {
 		/* Reverting or cherry-picking a merge commit */
 		int cnt;
The result becomes

	if (...)
		single statement;
	else if (...) {
		multiple;
                statements;
        }

which is not quite an improvement.  
Yet, this used to be the coding style of Git, and your statement comes
quite as a surprise to me.
Yeah, I thought we were OK with:

  if (cond)
	single statement;
  else {
	multiple;
	statements;
  }

but not the other way around:

  if (cond) {
	multiple;
	statements;
  } else
	single statement;

I don't know if the "else if" changes that or not, but I certainly have
written things like your patch does.

-Peff

Re: [PATCH v3 01/38] sequencer: avoid unnecessary curly braces

From: Jacob Keller <hidden>
Date: 2017-01-16 04:11:08

On Sat, Jan 14, 2017 at 10:05 AM, Jeff King [off-list ref] wrote:
On Sat, Jan 14, 2017 at 06:57:13PM +0100, Johannes Schindelin wrote:
quoted
On Thu, 12 Jan 2017, Junio C Hamano wrote:
quoted
Johannes Schindelin [off-list ref] writes:
quoted

- if (!commit->parents) {
+ if (!commit->parents)
          parent = NULL;
- }
  else if (commit->parents->next) {
          /* Reverting or cherry-picking a merge commit */
          int cnt;
The result becomes

    if (...)
            single statement;
    else if (...) {
            multiple;
                statements;
        }

which is not quite an improvement.
Yet, this used to be the coding style of Git, and your statement comes
quite as a surprise to me.
Yeah, I thought we were OK with:

  if (cond)
        single statement;
  else {
        multiple;
        statements;
  }

but not the other way around:

  if (cond) {
        multiple;
        statements;
  } else
        single statement;

I don't know if the "else if" changes that or not, but I certainly have
written things like your patch does.

-Peff
Personally, I am of the faith that if any branch of the
if-then-else-if-then-else blocks needs braces, then all branches
should use braces. However, I think that

if (condition)
  <line>
else {
  <block>
}

is reasonably close to this, as the main part can still clearly see
the if condition pretty well.

Thanks,
Jake
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help