all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: Drew Adams <drew.adams@oracle.com>
To: "Clément Pit-Claudel" <cpitclaudel@gmail.com>, emacs-devel@gnu.org
Subject: RE: 31395511: "Don’t attempt to modify constant strings"
Date: Fri, 5 Jun 2020 10:01:08 -0700 (PDT)	[thread overview]
Message-ID: <636e4f34-aa10-4e3b-9d61-af6fa6e8d723@default> (raw)
In-Reply-To: <94615cb2-9eda-7c1d-e55c-f89e007cac80@gmail.com>

> > I don't think this matters much, since string
> > literals shouldn't have text properties.
> 
> Really? I've used the reader syntax for propertized
> strings a few times — it's pretty convenient.

+1.

And not just using reader syntax, i.e., not just
#("whatever" ...).  

"String literals shouldn't have text properties"
is an unhelpful and unlispy mantra.  It, in
effect, marginalizes the use of propertized
strings. And to what end - what's the gain that
offsets the loss?

"String literals appearing in code shouldn't be
implemented as constants" is a better mantra,
if we need a blanket point of view - hopefully
we don't.

Privileging byte-compiler optimizations such as
treating literal strings in code as constants,
over Lisp flexibility, is counter-productive
and not worth it.  What's lost is greater than
what's gained (presumably some space or speed).

Just as a (global) symbol is an _object_, with
properties, so can an Elisp string be.  That's
a powerful construct (missing in other Lisps).

Expecting users to use `make-string' or some
such, to avoid constant-string modification -
a la using `cons' or `list' to avoid modifying
constant list structure (e.g. quoted lists),
isn't very lispy, helpful, or reasonable.

This is true whether or not this has long been
problematic (accidentally or intentionally).

Users should be able to propertize a string
written literally in code, and change the
properties dynamically, over and over, without
inviting trouble.  They already know to use
`copy-sequence' when they need to ensure a new
string and not bother an existing one.  That
should be about all they ever need to do.

We should favor use of Elisp by Emacs users.
In general, we  shouldn't toss out flexibility
and convenience in an attempt to achieve
general-programming language features such as
high  performance.

It's OK to offer high performance if there's
no cost in convenience or flexibility, or if
that cost is really worth it.  And it's OK to
offer it optionally, where the sacrifice is an
intentional trade-off (by a user).

If you go the other way on this, then we at
least need to provide a simple way to
manipulate strings with properties - something
simpler than fiddling with `make-string' and
`copy-sequence' as often as we need to use
`cons', `list', and their backquote-comma
equivalents to avoid the gotcha of modifying
a quoted list.

If I use `copy-sequence' once, to ensure that
I don't bother an existing string, I should
be able to modify my new string over and over,
especially its text properties.

A quoted list that gets modified is bad enough
as a gotcha.  Many users never modify list
structure, and the doc makes clear when some
function does that.  And we try to document
that modify-quoted-list gotcha explicitly.
Not perfect, but we do try to help users with
that gotcha.

Modifying _symbol_ properties isn't a problem
because there is only ever one symbol with a
given name interned in a given obarray, and
the properties are separate from the obarray.
The obarray just holds the symbol identifier.

Modification of string properties needs to be
dealt with and documented reasonably, somehow.
Currently we can't rely on something like an
obarray, as we do with symbols.  And probably
more users will modify string properties than
list structure, so we need a solution that is
at least as good as the way we handle the list
gotcha.

Modifying the _chars_ in a string might be a
different story.  It's string properties I'm
mostly concerned about here.

We should look for a reasonable solution that
helps Emacs users, and not just favor compiled
code performance.

I know that more than the compiler is involved.
There's also the reader.  I'm asking for a
solution that makes modifying string properties
less, not more, problematic.

And barring any advance in the direction I'm
suggesting, let's at least try to give users
good, clear doc about whatever gotchas do exist
for modifying string text properties.  That's
not the best solution, but it's a necessary
fallback if nothing is improved in this regard
in the code.

Just one opinion.  +1 for propertized strings,
a wonderful Emacs-Lisp feature.



  parent reply	other threads:[~2020-06-05 17:01 UTC|newest]

Thread overview: 40+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-03 21:52 31395511: "Don’t attempt to modify constant strings" João Távora
2020-06-03 22:41 ` Paul Eggert
2020-06-03 22:52   ` Pip Cet
2020-06-03 23:20     ` Paul Eggert
2020-06-03 23:20     ` Basil L. Contovounesios
2020-06-03 22:41 ` Pip Cet
2020-06-03 23:08   ` Basil L. Contovounesios
2020-06-03 23:31     ` Basil L. Contovounesios
2020-06-03 23:48   ` João Távora
2020-06-04  0:43     ` Paul Eggert
2020-06-04  1:19       ` Paul Eggert
2020-06-04  7:26         ` Pip Cet
2020-06-04 11:11           ` Basil L. Contovounesios
2020-06-04 19:46             ` Paul Eggert
2020-06-04 20:25               ` João Távora
2020-06-04 20:29                 ` Paul Eggert
2020-06-04 21:21                   ` Drew Adams
2020-06-04 20:43               ` Pip Cet
2020-06-04 21:27                 ` Stefan Monnier
2020-06-04 21:42                   ` Pip Cet
2020-06-04 23:10                 ` Paul Eggert
2020-06-05  2:09                   ` Clément Pit-Claudel
2020-06-05  6:44                     ` Paul Eggert
2020-06-05 12:44                       ` Stefan Monnier
2020-06-05 17:01                     ` Drew Adams [this message]
2020-06-05  9:48                   ` Pip Cet
2020-06-05 18:37                     ` Paul Eggert
2020-06-04 22:33               ` Basil L. Contovounesios
2020-06-05 15:25       ` João Távora
2020-06-05 17:14         ` Dmitry Gutov
2020-06-05 23:19           ` João Távora
2020-06-05 23:32             ` Dmitry Gutov
2020-06-06  1:34               ` FW: " Drew Adams
2020-06-06  0:23             ` Drew Adams
2020-06-06  1:43             ` Paul Eggert
2020-06-06  4:06               ` Richard Stallman
2020-06-06 11:41               ` João Távora
2020-06-06 11:47                 ` João Távora
2020-06-04  4:38     ` Pip Cet
2020-06-04  9:31       ` João Távora

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

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

  git send-email \
    --in-reply-to=636e4f34-aa10-4e3b-9d61-af6fa6e8d723@default \
    --to=drew.adams@oracle.com \
    --cc=cpitclaudel@gmail.com \
    --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 external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.