unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: Emanuel Berg <incal@dataswamp.org>
To: emacs-devel@gnu.org
Subject: Re: how to speed up Lisp devel time
Date: Fri, 09 Aug 2024 15:54:40 +0200	[thread overview]
Message-ID: <87a5hl4x9b.fsf@dataswamp.org> (raw)
In-Reply-To: 86ed6xlx9r.fsf@gnu.org

Eli Zaretskii wrote:

>>> This is rather unusual, and you should expect to have some
>>> more-than-normally complicate code in that case.
>> 
>> What do you mean? It is the same for `forward-line'
>> 
>> C-u   M-x forward-line RET
>> C-u 4 M-x forward-line RET
>
> No, it isn't. forward-line accepts a numeric argument, and
> that's all. All you need to do to support that is use the
> corresponding 'interactive' code.

Okay, bad example.

What about this one, then?

C-u C-u a
aaaaaaaaaaaaaaaa 

C-u 17 a
aaaaaaaaaaaaaaaaa

>>> Also, someone pointed out that you could write this in
>>> just 83 characters.
>> 
>> Really? Well, well, let's see the code then!
>
> It was posted, I just counted the characters.

Here is the original code [last], I said it was 402 chars but
excluding the initial whitespace every line it is 376 chars.

One can make it shorter here and there, but to write that in
83 chars of Elisp - well, let's see it.

BTW that interface isn't complete/optimal I see now, there
are more stuff, also uncontroversial as you will see, that
I can add. Maybe later.

Right now - conceptually, not thinking about the details - it
supports

* Interactive use with M-x, including C-u M-x and C-u x M-x.

* Default values, for the _function_, not the interfaces.

* Verification of all args, again for the _function_ and not
  for any particular interface.

>>> That usually makes little sense in Emacs. Interactive and
>>> non-interactive uses have different semantics.
>> 
>> Same default for any kind of call makes little
>> sense. Usually!
>> 
>> I OTOH thinks that is the first policy I can think of.
>
> Then your code is unlikely to be accepted into Emacs.

The default values I speak of here isn't the default of any
particular _interface_, it is values for which _the function_
- regardless of interface - can fall back upon if the value
is unset.

I know that isn't at all any kind of radical or original
thought, it is a very basic idea and I don't care if you -
based on how it is done in Emacs - disagree.

>>> That happens, but very rarely. Well-designed clean code
>>> should avoid that.
>> 
>> It is better if everyone, well-designers or not, could use
>> a clean interface to do that. Then one could simply use it
>> and not having to rely on people writing great Elisp
>> for everything.
>
> Code doesn't write itself. Good design is always needed for
> elegant code.

The Emacs design in this case isn't good. In fact it is
a mess. The interactive and non-interactive stuff are both
tangled up sometimes and parallel sometimes.

The functions should not be branching mid-way based on that
and there shouldn't be a separate set of functions for this or
the other interface. "This is for interactive use" and all.

Interactive/non-interactive should _only_ matter in setting up
and executing _the interface_, after that the functions should
run the same based on the present data, regardless of how that
data is obtained.

Just imagine if we were to add a third interface? Would be
branch on that mid-way into functions as well, and have
a third set of functions, just for that interface?

But be that as it may, the way you do it with the
`interactive' format string still isn't good - not powerful
enough, which is way so often people have to use Lisp instead.
And, too cryptic in that tiny string which makes it
error-prone to write, and difficult to read.

[code]

(interactive (if (numberp current-prefix-arg)
                 (list current-prefix-arg)
               current-prefix-arg))
(unless end
  (setq end 73))
(unless step
  (setq step (min 10 (max 2 (/ end 10)))))
(unless i
  (setq i 0))
(unless (and (numberp i)    (<= 0 i)
             (numberp end)  (<  0 end)
             (numberp step) (<  0 step))
  (error "Bogus indata"))

-- 
underground experts united
https://dataswamp.org/~incal




  reply	other threads:[~2024-08-09 13:54 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-08-09  7:16 how to speed up Lisp devel time Emanuel Berg
2024-08-09  7:24 ` Eli Zaretskii
2024-08-09  7:39   ` Emanuel Berg
2024-08-09 10:43     ` Eli Zaretskii
2024-08-09 11:18       ` Emanuel Berg
2024-08-09 12:02         ` Eli Zaretskii
2024-08-09 13:54           ` Emanuel Berg [this message]
2024-08-09 14:58             ` Eli Zaretskii
2024-08-09 16:03               ` Emanuel Berg
2024-08-09 16:16                 ` Emanuel Berg
2024-08-09 17:54                   ` Eli Zaretskii
2024-08-09 18:56                     ` Christopher Dimech
2024-08-09 21:57                       ` Emanuel Berg
2024-08-09 21:47                     ` Emanuel Berg
2024-08-09 17:27                 ` Yuri Khan
2024-08-09 21:21                   ` Emanuel Berg
2024-08-10  2:14                   ` Emanuel Berg
2024-08-10  6:01                     ` Yuri Khan
2024-08-10  6:08                       ` Emanuel Berg
2024-08-10  6:44                         ` Yuri Khan
2024-08-10  7:22                           ` Emanuel Berg
2024-08-10  7:51                             ` Emanuel Berg
2024-08-10  4:32                   ` Emanuel Berg
2024-08-10  5:58                     ` Eli Zaretskii
2024-08-09 14:59             ` Eduardo Ochs
2024-08-09 16:19               ` Emanuel Berg
2024-08-09 18:00                 ` Eli Zaretskii
2024-08-09 18:54                   ` Christopher Dimech
2024-08-09 22:17                     ` Emanuel Berg
2024-08-09 22:00                   ` Emanuel Berg
2024-08-09  8:24   ` Emanuel Berg
2024-08-09 10:36     ` Christopher Dimech

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.gnu.org/software/emacs/

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

  git send-email \
    --in-reply-to=87a5hl4x9b.fsf@dataswamp.org \
    --to=incal@dataswamp.org \
    --cc=emacs-devel@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.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).