[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] may we focus on readability?
From: |
Nicolas Goaziou |
Subject: |
Re: [PATCH] may we focus on readability? |
Date: |
Sun, 14 Jun 2020 21:32:48 +0200 |
User-agent: |
Gnus/5.13 (Gnus v5.13) Emacs/26.3 (gnu/linux) |
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