emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
From: Max Nikulin <manikulin@gmail.com>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: emacs-orgmode <emacs-orgmode@gnu.org>
Subject: Re: [PATCH] org-macs.el: Do not compare wall time and file modification time
Date: Fri, 13 May 2022 19:28:16 +0700	[thread overview]
Message-ID: <4518ff60-3d55-8727-e948-fc6131245931@gmail.com> (raw)
In-Reply-To: <1b78bf4b-386a-b240-2f2f-585064ce3ba4@cs.ucla.edu>

On 13/05/2022 05:52, Paul Eggert wrote:
> On 5/12/22 09:55, Max Nikulin wrote:
> 
>> +    (unless (file-exists-p file)
>> +      (error "File to tangle does not exist: %s" file))
>> +    (when (file-newer-than-file-p file tangled-file)
>>        (org-babel-tangle-file file ...
> 
> file-newer-than-file-p succeeds only if FILE exists, so in that case 
> it'd be a bit more efficient to avoid testing FILE's existence again, e.g.:
> 
>     (cond
>       ((file-newer-than-file-p file tangled-file)
>        (org-bable-tangle-file file ...))
>       ((not (file-exists-p file))
>        (error "File to tangle does not exist: %s" file)))

My opinion is that performance improvement is negligible while negative 
impact related to code readability is noticeable. Maybe it is just 
because elisp is not my favorite language.

Feel free to commit your variant though, I will not object, but I am not 
going to update my patch in this way as well.

P.S. Since I believe it should be fixed in the bugfix branch, I tried to 
keep changes as minimal as possible.

I am not sure which kind of code I would prefer to see. I do not like 
`cond' with 2 branches. Even nested ifs are a bit better while still to 
"heavy"

     (if (not (file-newer-than-file-p file tangled-file))
         (unless (file-exists-p file)
           (error ...))
       (org-babel-tangle-file ...)) ; intentionally put below to the 
else branch

Maybe I would prefer something like file-target-is-up-to-date-p 
predicate that returns nil if target does not exist. For some reason 
`org-babel-tangle-file' silently ignores missed file neither signalling 
a error nor returning a special value. Delegating error handling to 
`org-babel-tangle-file' would allow to get consistent error messages.

In the previous version of the patch (with inline implementation of file 
modification time comparison) the suggested optimization was quite 
natural, with `file-newer-than-file-p' it is trade off with code 
readability.



  reply	other threads:[~2022-05-13 12:45 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-04-27  6:37 master 4a1f69ebca 2/2: Use (TICKS . HZ) for current-time etc Mark Barton
2022-04-27  7:20 ` Po Lu
2022-04-27  7:39 ` Paul Eggert
2022-04-27 16:55   ` Stefan Monnier
2022-04-28 22:27     ` Paul Eggert
2022-04-29 14:22       ` Max Nikulin
2022-04-29 18:10         ` Paul Eggert
2022-04-30 10:56           ` Max Nikulin
2022-05-06 16:56             ` [PATCH] org-macs.el: Do not compare wall time and file modification time Max Nikulin
2022-05-11 12:28               ` Max Nikulin
2022-05-11 16:24                 ` Paul Eggert
2022-05-12 16:55                   ` Max Nikulin
2022-05-12 22:52                     ` Paul Eggert
2022-05-13 12:28                       ` Max Nikulin [this message]
2022-05-13 18:00                         ` Paul Eggert
2022-10-02  3:49                     ` Ihor Radchenko
2022-10-09  8:18                       ` [PATCH v2] " Max Nikulin
2022-10-21  3:27                         ` Ihor Radchenko

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=4518ff60-3d55-8727-e948-fc6131245931@gmail.com \
    --to=manikulin@gmail.com \
    --cc=eggert@cs.ucla.edu \
    --cc=emacs-orgmode@gnu.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.
Code repositories for project(s) associated with this public 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).