git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH/RFC] Documenation update: use of braces in if/else if/else chain

From
Leila <muhtasib@gmail.com>
Date
Jun 10, 2012, 20:52 UTC
Message-ID
<CAA3EhHLepTC2WThDvAWk5WPcMPQapqo=D7KhpdCESy9D9JO4vg@mail.gmail.com>
In-Reply-To
<20120610202205.GA2052@burratino>
On Sun, Jun 10, 2012 at 4:22 PM, Jonathan Nieder <jrnieder@gmail.com> wrote:
Show 9 quoted lines
> Also true.  But:
>
>        /* correct */
>        if (bla) {
>                x = 1;
>                ...
>        } else
>                x = 2;
>

According to a discussion on my patch, this was cited (not in ref to my code): Junio C Hamano <gitster@pobox.com> a écrit :

Two points on style (also appear elsewhere in this patch):
       if (!"applying") {
               ...
       } else {
               state->rebase_in_progress = 1;
       }
 - "else" comes on the same line as closing "}" of its "if" block;
 - if one of if/else if/else chain has multiple statement block, use {}
  even for a single statement block in the chain.

So I opened this documentation patch to gain consensus around this issue, and update the docs accordingly. Depending on the agreement reached, I can modify the wording of the patch. I don't need to site the linux Kernel part, I can just say what is supported in this project.

I think we should still keep this part of the patch:
+    And "else"
+   should come on the same line as the closing "}" of its "if" block.
Show 19 quoted lines
> And:
>
> If you have a long "if" with a one-line "else", consider whether you
> are needlessly keeping the reader in suspense about something simple.
> It might be more pleasant to read with the exceptional case up front:
>
>        if (!bla) {
>                x = 2;
>        } else {
>                x = 1;
>                ...
>        }
>
> This is especially true when the exceptional case returns or exits.
>
>        if (bla && no_bla)
>                return error("--blah and --no-blah cannot be used together");
>        x = 1;
>        ...
Agreed!

Thanks, Leila

Previous: Jonathan Nieder
Message 3 of 3 in “Documenation update: use of braces in if/else if/else chain”
  1. Documenation update: use of braces in if/else if/else chainLeila Muhtasib, Jun 10, 2012
  2. Jonathan NiederJun 10, 2012
  3. LeilaJun 10, 2012

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.