emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Nicolas Goaziou <mail@nicolasgoaziou.fr>
To: Mario Frasca <mario@anche.no>
Cc: emacs-orgmode@gnu.org
Subject: Re: [PATCH] may we focus on readability?
Date: Sun, 14 Jun 2020 21:32:48 +0200	[thread overview]
Message-ID: <871rmhe93z.fsf@nicolasgoaziou.fr> (raw)
In-Reply-To: <ad6ef4b1-a59d-0c1c-7ac3-a7f93f8333dc@anche.no> (Mario Frasca's message of "Sun, 14 Jun 2020 11:47:31 -0500")

Hello,

Mario Frasca <mario@anche.no> writes:

> I'm rewriting a complicated construction where there's an equality
> test on the length of the list of non matching elements, with a
> simpler cl-some invocation.  The replacing code is self explanatory.
>
> Subject: [PATCH] lisp/org-plot.el: reducing complexity of test.
>
> * lisp/org-plot.el (org-plot/gnuplot): readability of test, looking
> for some non satisfying elements.
>
> I'm rewriting a complicated construction where there's an equality
> test on the length of the list of non matching elements, with a
> simpler cl-some invocation.  The replacing code is self explanatory.
> ---
>  lisp/org-plot.el | 19 ++++++-------------
>  1 file changed, 6 insertions(+), 13 deletions(-)
>
> diff --git a/lisp/org-plot.el b/lisp/org-plot.el
> index a23195d2a..f50ad09a9 100644
> --- a/lisp/org-plot.el
> +++ b/lisp/org-plot.el
> @@ -312,22 +312,15 @@ line directly before or after the table."
>        ;; Check for timestamp ind column.
>        (let ((ind (1- (plist-get params :ind))))
>  	(when (and (>= ind 0) (eq '2d (plist-get params :plot-type)))
> -	  (if (= (length
> -		  (delq 0 (mapcar
> -			   (lambda (el)
> -			     (if (string-match org-ts-regexp3 el) 0 1))
> -			   (mapcar (lambda (row) (nth ind row)) table))))
> -		 0)
> +	  (if (cl-some (lambda (el)
> +			 (not (string-match org-ts-regexp3 el)))
> +		       (mapcar (lambda (row) (nth ind row)) table))
>  	      (plist-put params :timeind t)
>  	    ;; Check for text ind column.
>  	    (if (or (string= (plist-get params :with) "hist")
> -		    (> (length
> -			(delq 0 (mapcar
> -				 (lambda (el)
> -				   (if (string-match org-table-number-regexp el)
> -				       0 1))
> -				 (mapcar (lambda (row) (nth ind row)) table))))
> -		       0))
> +		    (cl-some (lambda (el)
> +			       (not (string-match org-table-number-regexp el)))
> +			     (mapcar (lambda (row) (nth ind row)) table))))
>  		(plist-put params :textind t)))))
>        ;; Write script.
>        (with-temp-buffer

OK. Note you can go even further: nested `if' should be replaced with
a `cond'.

Also, further nit: (not (cl-every ...)) will apply `not' only once.

In any case, it would be better if refactoring happens while introducing
unit tests *hint*.

Regards,
-- 
Nicolas Goaziou


  parent reply	other threads:[~2020-06-14 19:33 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-14 16:47 Mario Frasca
2020-06-14 17:24 ` tomas
2020-06-14 19:28   ` Nicolas Goaziou
2020-06-14 19:30     ` tomas
2020-06-14 19:32 ` Nicolas Goaziou [this message]
2020-06-15 14:49   ` Mario Frasca
2020-06-15 20:52     ` Mario Frasca
2020-06-16 16:56       ` Nicolas Goaziou
2020-06-16 17:26         ` Mario Frasca
2020-06-28  6:47           ` Nicolas Goaziou
2020-06-28  6:46       ` Nicolas Goaziou
2020-06-16 15:29     ` Nicolas Goaziou

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: https://www.orgmode.org/

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

  git send-email \
    --in-reply-to=871rmhe93z.fsf@nicolasgoaziou.fr \
    --to=mail@nicolasgoaziou.fr \
    --cc=emacs-orgmode@gnu.org \
    --cc=mario@anche.no \
    --subject='Re: [PATCH] may we focus on readability?' \
    /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

Code repositories for project(s) associated with this inbox:

	https://git.savannah.gnu.org/cgit/emacs/org-mode.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).