git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Jeff King <peff@peff.net>
To: Johannes Schindelin <Johannes.Schindelin@gmx.de>
Cc: Johannes Sixt <j6t@kdbg.org>, Junio C Hamano <gitster@pobox.com>,
	git@vger.kernel.org
Subject: Re: What's cooking in git.git (Jan 2017, #02; Sun, 15)
Date: Mon, 16 Jan 2017 17:00:14 -0500	[thread overview]
Message-ID: <20170116220014.bwi5xi2br56lyqsw@sigill.intra.peff.net> (raw)
In-Reply-To: <alpine.DEB.2.20.1701161746200.3469@virtualbox>

On Mon, Jan 16, 2017 at 06:06:35PM +0100, Johannes Schindelin wrote:

> >      And I think that would apply to any input parameter we show via
> >      error(), etc, if it is connected to a newline (ideally we would
> >      show newlines as "?", too, but we cannot tell the difference
> >      between ones from parameters, and ones that are part of the error
> >      message).
> 
> I think it is doing users a really great disservice to munge up CR or LF
> into question marks. I *guarantee* you that it confuses users. And not
> because they are dumb, but because the code violates the Law of Least
> Surprise.

I'm not sure if you realize that with stock git, the example from your
test looks like this (at least in my terminal):

  $ git.v2.11.0 rev-parse --abbrev-ref "$(printf 'CR/LF\r\n')" >/dev/null
  ': unknown revision or path not in the working tree.
  Use '--' to separate paths from revisions, like this:
  'git <command> [<revision>...] -- [<file>...]'

The "\r" causes us to overwrite the rest of the message, including the
actual filename. With my patch it's:

  $ git rev-parse --abbrev-ref "$(printf 'CR/LF\r\n')" >/dev/null
  fatal: ambiguous argument 'CR/LF?': unknown revision or path not in the working tree.
  Use '--' to separate paths from revisions, like this:
  'git <command> [<revision>...] -- [<file>...]'

I am certainly sympathetic to the idea that the "?" is ugly and
potentially confusing. But I think it's at least a step forward for this
particular example.

I'll snip liberally from the rest of your response, because I think what
JSixt wrote covers it.

> > > While at it, let's lose the unnecessary curly braces.
> > 
> > Please don't. Obviously C treats the "if/else" as a single unit, but
> > IMHO it's less error-prone to include the braces any time there are
> > multiple visual lines. E.g., something like:
> > 
> >   while (foo)
> > 	if (bar)
> > 		one();
> > 	else
> > 		two();
> > 	three();
> > 
> > is much easier to spot as wrong when you would require braces either
> > way (and not relevant here, but I'd say that even an inner block with a
> > comment deserves braces for the same reason).
> 
> There is no documentation about the preferred coding style.

Documentation/CodingGuidelines says:

 - We avoid using braces unnecessarily.  I.e.

        if (bla) {
                x = 1;
        }

   is frowned upon.  A gray area is when the statement extends
   over a few lines, and/or you have a lengthy comment atop of
   it.  Also, like in the Linux kernel, if there is a long list
   of "else if" statements, it can make sense to add braces to
   single line blocks.

I think this is pretty clearly the "gray area" mentioned there. Which
yes, does not say "definitely do it this way", but I hope makes it clear
that you're supposed to use judgement about readability.

-Peff

  parent reply	other threads:[~2017-01-16 22:08 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-16  1:51 What's cooking in git.git (Jan 2017, #02; Sun, 15) Junio C Hamano
2017-01-16  6:56 ` Johannes Sixt
2017-01-16  7:48   ` Junio C Hamano
2017-01-16 12:52   ` Johannes Schindelin
2017-01-16 16:04     ` Jeff King
2017-01-16 17:06       ` Johannes Schindelin
2017-01-16 20:33         ` Johannes Sixt
2017-01-16 21:44           ` Jeff King
2017-01-17 19:17             ` Junio C Hamano
2017-01-18  6:50               ` Johannes Sixt
2017-01-18 19:12                 ` Junio C Hamano
2017-01-19 16:12                   ` Johannes Schindelin
2017-01-16 22:00         ` Jeff King [this message]
2017-01-16 22:08           ` [PATCH] CodingGuidelines: clarify multi-line brace style Jeff King
2017-01-17 19:39             ` Junio C Hamano
2017-01-17 20:05               ` Jeff King
2017-01-17 21:41                 ` Junio C Hamano
2017-01-17  1:33           ` What's cooking in git.git (Jan 2017, #02; Sun, 15) Jacob Keller
2017-01-17  7:52             ` Jeff King
2017-01-17 19:20           ` Junio C Hamano
2017-01-17 19:36             ` Jeff King
2017-01-17 20:32               ` Junio C Hamano
2017-01-17 20:51                 ` Jeff King
2017-01-16 11:28 ` Johannes Schindelin
2017-01-17 19:45   ` Junio C Hamano
2017-01-18 13:54     ` Johannes Schindelin
2017-01-16 11:40 ` Johannes Schindelin
2017-01-18  1:05 ` [PATCHv3 4/4] unpack-trees: support super-prefix option Stefan Beller

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170116220014.bwi5xi2br56lyqsw@sigill.intra.peff.net \
    --to=peff@peff.net \
    --cc=Johannes.Schindelin@gmx.de \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=j6t@kdbg.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).