From: Kyle Meyer <kyle@kyleam.com>
To: Ihor Radchenko <yantar92@gmail.com>
Cc: piem@inbox.kyleam.com
Subject: Re: [PATCH] piem-am: Order attached patches by file name prefix
Date: Sat, 09 Jul 2022 12:56:49 -0400 [thread overview]
Message-ID: <87czee6x7y.fsf@kyleam.com> (raw)
In-Reply-To: <87fsjaspkl.fsf@localhost>
Ihor Radchenko writes:
> I only have some minor comments on the code.
Thanks for the feedback.
>> (defun piem-gnus-am-ready-mbox ()
>> "Return a function that inserts an am-ready mbox.
>> +
>> If the buffer has any MIME parts that look like a patch, use
>> -those parts' contents (in order) as the mbox. Otherwise, use the
>> -message itself if it looks like a patch."
>> +those parts' contents as the mbox, ordering the patches based on
>> +the number at the start of the file name. If none of the file
>> +names start with a number, retain the original order of the
>> +attachments.
>> ...
>> (defun piem-notmuch-am-ready-mbox ()
>> "Return a function that inserts an am-ready mbox.
>> +
>> If the buffer has any MIME parts that look like a patch, use
>> -those parts' contents (in order) as the mbox. Otherwise, use the
>> -message itself if it looks like a patch."
>> +those parts' contents as the mbox, ordering the patches based on
>> +the number at the start of the file name. If none of the file
>> +names start with a number, retain the original order of the
>> +attachments.
>
> There is certainly some code duplication going on here (;
For the two repeated blocks of the docstrings, I'm okay with a bit of
repeated documentation in this situation. Another option would be to
put something about the attachment order in the docstring of
piem-am-ready-mbox-functions, but that moves it farther from the
relevant context. (Or to just not document it at all.)
If you're commenting more generally on the _code_ of
piem-gnus-am-ready-mbox and piem-notmuch-am-ready-mbox, I'm open to
suggestions for extracting out any remaining shared bits, but my hunch
is that most directions would obscure things.
>> + (when (listp handle)
>> + (let ((type (mm-handle-media-type handle))
>> + (filename (mm-handle-filename handle)))
>> + (and (or (member type '("text/x-diff" "text/x-patch"))
>> + (and filename
>> + (equal type "text/plain")
>> + (string-suffix-p ".patch" filename t)))
>> + (with-temp-buffer
>> + (mm-display-inline handle)
>> + (cons
>> + (string-to-number filename)
>> + (buffer-substring-no-properties (point-min) (point-max))))))))
>
> Why using (and ...)? It feels like (when ...) is more appropriate in
> this context.
I like the (very soft and fuzzy) style guideline of using `and` to
signal the return value is the primary thing of interest and `when` to
signal the code is executed for side effects. I'm not sure who I first
saw describe this convention [*], when I started to share the
preference, or how consistent I am in how I apply it.
Due to indentation, nesting, and/or grouping, I think there are cases
where it's more readable to use `when`, such as the top-level `when`
above. Perhaps on a different night I would have felt the same about
the `and` you mentioned and flipped it to a `when`.
Is there a particular reason you prefer `when` in the above case?
[*] I'm not sure how widely this preference is shared among Elisp
coders. Perhaps it mostly comes from elsewhere, like Common Lisp
(<https://www.cs.cmu.edu/Groups/AI/html/cltl/clm/node84.html>):
As a matter of style, `when` is normally used to conditionally
produce some side effects, and the value of the `when` form is
normally not used. If the value is relevant, then it may be
stylistically more appropriate to use `and` or `if`.
I recall seeing Nicolas state it several times in reviews on the Org
list. Some examples:
- https://list.orgmode.org/?q=f%3Anicolas+AND+nq%3Awhen+ADJ+nq%3Aside
- https://list.orgmode.org/87d23sdtod.fsf@nicolasgoaziou.fr/
next prev parent reply other threads:[~2022-07-09 16:56 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-07-09 3:11 [BUG] Patch order is not respected for sequence of patches like [PATCH X/Y] Ihor Radchenko
2022-07-09 6:45 ` [PATCH] piem-am: Order attached patches by file name prefix Kyle Meyer
2022-07-09 7:38 ` Ihor Radchenko
2022-07-09 16:56 ` Kyle Meyer [this message]
2022-07-10 9:59 ` Ihor Radchenko
2022-07-10 14:25 ` Kyle Meyer
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://git.kyleam.com/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=87czee6x7y.fsf@kyleam.com \
--to=kyle@kyleam.com \
--cc=piem@inbox.kyleam.com \
--cc=yantar92@gmail.com \
/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://git.kyleam.com/piem/
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).