All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Verma, Vishal L" <vishal.l.verma@intel.com>
To: "joe@perches.com" <joe@perches.com>,
	"Williams, Dan J" <dan.j.williams@intel.com>,
	"Jiang, Dave" <dave.jiang@intel.com>,
	"Busch, Keith" <keith.busch@intel.com>,
	"Weiny, Ira" <ira.weiny@intel.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"dan.carpenter@oracle.com" <dan.carpenter@oracle.com>,
	"linux-nvdimm@lists.01.org" <linux-nvdimm@lists.01.org>
Subject: Re: [PATCH 11/13] nvdimm: Use more common logic testing styles and bare ; positions
Date: Thu, 12 Sep 2019 03:52:49 +0000	[thread overview]
Message-ID: <706f6af6a6571a3bb2d35ec332fa572a990cbc48.camel@intel.com> (raw)
In-Reply-To: <d6aa5b66936f2e0f132e893e10494aae6b74e886.1568256708.git.joe@perches.com>

On Wed, 2019-09-11 at 19:54 -0700, Joe Perches wrote:
> Avoid using uncommon logic testing styles to make the code a
> bit more like other kernel code.
> 
> e.g.:
> 	if (foo) {
> 		;
> 	} else {
> 		<code>
> 	}
> 
> is typically written
> 
> 	if (!foo) {
> 		<code>
> 	}
> 

A lot of times the excessive inversions seem to result in a net loss of
readability - e.g.:

<snip>

> diff --git a/drivers/nvdimm/region_devs.c
> b/drivers/nvdimm/region_devs.c
> index 65df07481909..6861e0997d21 100644
> --- a/drivers/nvdimm/region_devs.c
> +++ b/drivers/nvdimm/region_devs.c
> @@ -320,9 +320,7 @@ static ssize_t set_cookie_show(struct device *dev,
>  	struct nd_interleave_set *nd_set = nd_region->nd_set;
>  	ssize_t rc = 0;
>  
> -	if (is_memory(dev) && nd_set)
> -		/* pass, should be precluded by region_visible */;

For one, the comment is lost

> -	else
> +	if (!(is_memory(dev) && nd_set))

And it takes a moment to resolve between things such as:

	if (!(A && B))
	  vs.
	if (!(A) && B)

And this is especially true if 'A' and 'B' are longer function calls,
split over multiple lines, or are themselves compound 'sections'.

I'm not opposed to /all/ such transformations -- for example, the ones
where the logical inversion can be 'consumed' by toggling a comparision
operator, as you have a few times in this patch, don't sacrifice any
readibility, and perhaps even improve it. 

>  		return -ENXIO;
>  
>  	/*
_______________________________________________
Linux-nvdimm mailing list
Linux-nvdimm@lists.01.org
https://lists.01.org/mailman/listinfo/linux-nvdimm

WARNING: multiple messages have this Message-ID (diff)
From: "Verma, Vishal L" <vishal.l.verma@intel.com>
To: "joe@perches.com" <joe@perches.com>,
	"Williams, Dan J" <dan.j.williams@intel.com>,
	"Jiang, Dave" <dave.jiang@intel.com>,
	"Busch, Keith" <keith.busch@intel.com>,
	"Weiny, Ira" <ira.weiny@intel.com>
Cc: "linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"dan.carpenter@oracle.com" <dan.carpenter@oracle.com>,
	"linux-nvdimm@lists.01.org" <linux-nvdimm@lists.01.org>
Subject: Re: [PATCH 11/13] nvdimm: Use more common logic testing styles and bare ; positions
Date: Thu, 12 Sep 2019 03:52:49 +0000	[thread overview]
Message-ID: <706f6af6a6571a3bb2d35ec332fa572a990cbc48.camel@intel.com> (raw)
In-Reply-To: <d6aa5b66936f2e0f132e893e10494aae6b74e886.1568256708.git.joe@perches.com>

On Wed, 2019-09-11 at 19:54 -0700, Joe Perches wrote:
> Avoid using uncommon logic testing styles to make the code a
> bit more like other kernel code.
> 
> e.g.:
> 	if (foo) {
> 		;
> 	} else {
> 		<code>
> 	}
> 
> is typically written
> 
> 	if (!foo) {
> 		<code>
> 	}
> 

A lot of times the excessive inversions seem to result in a net loss of
readability - e.g.:

<snip>

> diff --git a/drivers/nvdimm/region_devs.c
> b/drivers/nvdimm/region_devs.c
> index 65df07481909..6861e0997d21 100644
> --- a/drivers/nvdimm/region_devs.c
> +++ b/drivers/nvdimm/region_devs.c
> @@ -320,9 +320,7 @@ static ssize_t set_cookie_show(struct device *dev,
>  	struct nd_interleave_set *nd_set = nd_region->nd_set;
>  	ssize_t rc = 0;
>  
> -	if (is_memory(dev) && nd_set)
> -		/* pass, should be precluded by region_visible */;

For one, the comment is lost

> -	else
> +	if (!(is_memory(dev) && nd_set))

And it takes a moment to resolve between things such as:

	if (!(A && B))
	  vs.
	if (!(A) && B)

And this is especially true if 'A' and 'B' are longer function calls,
split over multiple lines, or are themselves compound 'sections'.

I'm not opposed to /all/ such transformations -- for example, the ones
where the logical inversion can be 'consumed' by toggling a comparision
operator, as you have a few times in this patch, don't sacrifice any
readibility, and perhaps even improve it. 

>  		return -ENXIO;
>  
>  	/*

  reply	other threads:[~2019-09-12  3:53 UTC|newest]

Thread overview: 68+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-12  2:54 [PATCH 00/13] nvdimm: Use more common kernel coding style Joe Perches
2019-09-12  2:54 ` Joe Perches
2019-09-12  2:54 ` [PATCH 01/13] nvdimm: Use more typical whitespace Joe Perches
2019-09-12  2:54   ` Joe Perches
2019-09-12 12:17   ` Christoph Hellwig
2019-09-12 12:17     ` Christoph Hellwig
2019-09-12 15:01     ` Joe Perches
2019-09-12 15:01       ` Joe Perches
2019-09-16  7:07       ` Christoph Hellwig
2019-09-16  7:07         ` Christoph Hellwig
2019-09-12  2:54 ` [PATCH 02/13] nvdimm: Move logical continuations to previous line Joe Perches
2019-09-12  2:54   ` Joe Perches
2019-09-12  2:54 ` [PATCH 03/13] nvdimm: Use octal permissions Joe Perches
2019-09-12  2:54   ` Joe Perches
2019-09-12  2:54 ` [PATCH 04/13] nvdimm: Use a more common kernel spacing style Joe Perches
2019-09-12  2:54   ` Joe Perches
2019-09-12  2:54 ` [PATCH 05/13] nvdimm: Use "unsigned int" in preference to "unsigned" Joe Perches
2019-09-12  2:54   ` Joe Perches
2019-09-12  2:54 ` [PATCH 06/13] nvdimm: Add and remove blank lines Joe Perches
2019-09-12  2:54   ` Joe Perches
2019-09-12  2:54 ` [PATCH 07/13] nvdimm: Use typical kernel brace styles Joe Perches
2019-09-12  2:54   ` Joe Perches
2019-09-12  2:54 ` [PATCH 08/13] nvdimm: Use typical kernel style indentation Joe Perches
2019-09-12  2:54   ` Joe Perches
2019-09-12  2:54 ` [PATCH 09/13] nvdimm: btt.h: Neaten #defines to improve readability Joe Perches
2019-09-12  2:54   ` Joe Perches
2019-09-12  2:54 ` [PATCH 10/13] nvdimm: namespace_devs: Move assignment operators Joe Perches
2019-09-12  2:54   ` Joe Perches
2019-09-12  2:54 ` [PATCH 11/13] nvdimm: Use more common logic testing styles and bare ; positions Joe Perches
2019-09-12  2:54   ` Joe Perches
2019-09-12  3:52   ` Verma, Vishal L [this message]
2019-09-12  3:52     ` Verma, Vishal L
2019-09-12  2:54 ` [PATCH 12/13] nvdimm: namespace_devs: Change progess typo to progress Joe Perches
2019-09-12  2:54   ` Joe Perches
2019-09-12  2:54 ` [PATCH 13/13] nvdimm: Miscellaneous neatening Joe Perches
2019-09-12  2:54   ` Joe Perches
2019-09-12  8:00 ` [PATCH 00/13] nvdimm: Use more common kernel coding style Dan Williams
2019-09-12  8:00   ` Dan Williams
2019-09-12  8:15   ` Joe Perches
2019-09-12  8:15     ` Joe Perches
2019-09-12  8:42     ` Miguel Ojeda
2019-09-12  8:42       ` Miguel Ojeda
2019-09-12 14:00 ` Jeff Moyer
2019-09-12 14:00   ` Jeff Moyer
2019-09-12 14:06   ` Johannes Thumshirn
2019-09-12 14:06     ` Johannes Thumshirn
2019-09-12 14:35     ` Dan Williams
2019-09-12 14:35       ` Dan Williams
2019-09-12 14:21   ` Miguel Ojeda
2019-09-12 14:21     ` Miguel Ojeda
2019-09-12 21:08     ` Joe Perches
2019-09-12 21:08       ` Joe Perches
2019-09-12 21:58       ` Miguel Ojeda
2019-09-12 21:58         ` Miguel Ojeda
2019-09-12 22:15         ` Joe Perches
2019-09-12 22:15           ` Joe Perches
2019-09-12 22:38         ` Joe Perches
2019-09-12 22:38           ` Joe Perches
2019-09-12 23:00           ` Nick Desaulniers
2019-09-12 23:00             ` Nick Desaulniers
2019-09-12 23:07             ` Joe Perches
2019-09-12 23:07               ` Joe Perches
2019-09-12 22:58         ` Nick Desaulniers
2019-09-12 22:58           ` Nick Desaulniers
2019-09-12 23:26         ` clang-format and 'clang-format on' and 'clang-format off' Joe Perches
2019-09-12 23:26           ` Joe Perches
2019-09-15 18:25           ` Miguel Ojeda
2019-09-15 18:25             ` Miguel Ojeda

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

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

  git send-email \
    --in-reply-to=706f6af6a6571a3bb2d35ec332fa572a990cbc48.camel@intel.com \
    --to=vishal.l.verma@intel.com \
    --cc=dan.carpenter@oracle.com \
    --cc=dan.j.williams@intel.com \
    --cc=dave.jiang@intel.com \
    --cc=ira.weiny@intel.com \
    --cc=joe@perches.com \
    --cc=keith.busch@intel.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-nvdimm@lists.01.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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.