From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Eli Zaretskii Newsgroups: gmane.emacs.devel Subject: Re: Replace trivial pcase occurrences in the Emacs sources Date: Wed, 24 Oct 2018 18:03:26 +0300 Message-ID: <83ftwvs7y9.fsf@gnu.org> References: <20151216202605.GA3752@acm.fritz.box> <83si2f9ve4.fsf@gnu.org> <56889EC3.3040108@yandex.ru> <877fjrkpdf.fsf@fencepost.gnu.org> <56892334.4000106@yandex.ru> <8760zakb7q.fsf@fencepost.gnu.org> <56892BDA.6060103@dancol.org> <871t9yk98g.fsf@fencepost.gnu.org> <568936F0.3060505@yandex.ru> <87wprqitj5.fsf@fencepost.gnu.org> <56893C8C.3060200@yandex.ru> <87oad2irtd.fsf@fencepost.gnu.org> <5689456A.1010601@yandex.ru> <87egdy8tyz.fsf@fencepost.gnu.org> <56895FDE.4060406@yandex.ru> <8760za8r4a.fsf@fencepost.gnu.org> <87h9iunkcg.fsf@web.de> <87h8hc4xw2.fsf_-_@web.de> <83tvlcsnee.fsf@gnu.org> <87pnw037ar.fsf@web.de> NNTP-Posting-Host: blaine.gmane.org X-Trace: blaine.gmane.org 1540393354 18894 195.159.176.226 (24 Oct 2018 15:02:34 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Wed, 24 Oct 2018 15:02:34 +0000 (UTC) Cc: emacs-devel@gnu.org To: Stefan Monnier Original-X-From: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Wed Oct 24 17:02:30 2018 Return-path: Envelope-to: ged-emacs-devel@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gFKg1-0004nm-DR for ged-emacs-devel@m.gmane.org; Wed, 24 Oct 2018 17:02:29 +0200 Original-Received: from localhost ([::1]:48950 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFKi7-0002uP-Ks for ged-emacs-devel@m.gmane.org; Wed, 24 Oct 2018 11:04:39 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:56400) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFKhA-0002PC-2s for emacs-devel@gnu.org; Wed, 24 Oct 2018 11:03:41 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gFKh4-0001Qy-C0 for emacs-devel@gnu.org; Wed, 24 Oct 2018 11:03:38 -0400 Original-Received: from fencepost.gnu.org ([2001:4830:134:3::e]:48589) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gFKh0-0001Ku-4s; Wed, 24 Oct 2018 11:03:30 -0400 Original-Received: from [176.228.60.248] (port=1085 helo=home-c4e4a596f7) by fencepost.gnu.org with esmtpsa (TLS1.2:RSA_AES_256_CBC_SHA1:256) (Exim 4.82) (envelope-from ) id 1gFKgz-0002as-PJ; Wed, 24 Oct 2018 11:03:30 -0400 In-reply-to: (message from Stefan Monnier on Tue, 23 Oct 2018 14:12:34 -0400) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] X-Received-From: 2001:4830:134:3::e X-BeenThere: emacs-devel@gnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: "Emacs development discussions." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: emacs-devel-bounces+ged-emacs-devel=m.gmane.org@gnu.org Original-Sender: "Emacs-devel" Xref: news.gmane.org gmane.emacs.devel:230630 Archived-At: > From: Stefan Monnier > Date: Tue, 23 Oct 2018 14:12:34 -0400 > > > I think so too, but it seems the majority of developers has a different > > option, at least in this (old) thread. > > So I guess I'm gonna have to try and argue my case. > OK, here are the advantages I see for `cl-case`: FWIW, my main problem is not even with cl-case, it's with 'cond'. It seems like we have some 'pcase' epidemic, whose first symptom is that people stop using 'cond' and start using 'pcase' instead. A few examples: todo-mode.el: (pcase this-param ('edit (todo-edit-item--text)) ('header (todo-edit-item--text 'include-header)) ('multiline (todo-edit-item--text 'multiline)) ('add/edit (todo-edit-item--text 'comment-edit)) ('delete (todo-edit-item--text 'comment-delete)) ('diary (todo-edit-item--diary-inclusion)) ('nonmarking (todo-edit-item--diary-inclusion 'nonmarking)) [...] auth-source-pass.el: (pcase (length matching-entries) (0 (auth-source-pass--do-debug "no match found") nil) (1 (auth-source-pass--do-debug "found 1 match: %s" (car matching-entries)) (car matching-entries)) (_ (auth-source-pass--select-one-entry matching-entries user))))) bs.el: (setq bs-buffer-show-mark (pcase bs-buffer-show-mark (`nil 'never) (`never 'always) (_ nil)))))) calculator.el: (<= inp (pcase calculator-input-radix (`nil ?9) (`bin ?1) (`oct ?7) (_ 999)))) lpr.el: (pcase (count-lines (point-min) (point-max)) (0 "") (1 ": ") (_ ":\n")) My favorite is imap.el, which does something like the above in 3 nested levels. I will spare you the code, you can look it up. Is it because people are too lazy to write (eq a b) as part of 'cond'? Or is there something else I'm missing? You may wonder why I'm bothered by such uses. It's because people are evidently confused by 'pcase's arcane syntax, and therefore produce obfuscated code even in the simple usage. For example: apropos.el: (pcase (car-safe x) ;; (autoload (push (cdr x) autoloads)) (`require (push (cdr x) requires)) (`provide (push (cdr x) provides)) (`t nil) ; Skip "was an autoload" entries. ;; FIXME: Print information about each individual method: both ;; its docstring and specializers (bug#21422). (`cl-defmethod (push (cadr x) provides)) (_ (push (or (cdr-safe x) x) symbols)))) (Quick: what's the difference between `require and 'require in this case?) easy-mmode.el: (pcase keyw (`:group (setq group (nconc group (list :group (pop keys))))) (`:global (setq keys (cdr keys))) (_ (push keyw extra-keywords) (push (pop keys) extra-keywords)))) (Aren't keywords supposed to be self-quoting? then why they are explicitly quoted?) We have dozens of such fragments in our codebase, which just makes the sources harder to read, especially for people who aren't fluent with 'pcase' (which seems to be the case with many of us). So I think we should begin by rewriting all of such uses as simple 'cond', and ask contributors not to use 'pcase' where a simple 'cond' will do.