From: Konstantin Kharlamov <hi-angel@yandex.ru>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: 35062@debbugs.gnu.org
Subject: bug#35062: [PATCH v3 2/3] constify a bit of xterm.c
Date: Sat, 20 Apr 2019 04:09:19 +0300 [thread overview]
Message-ID: <1555722559.16908.0@yandex.ru> (raw)
In-Reply-To: <1f700b05-16a8-1159-e2e3-61f9699981a1@cs.ucla.edu>
В Пт, апр 19, 2019 at 17:31, Paul Eggert <eggert@cs.ucla.edu>
написал:
> I'd rather not use 'const' on locals. Let me tell you a story as to
> why.
>
> I once worked with someone who insisted on using the 'register'
> keyword on every C local variable that was never taken the address
> of, on the grounds that this meant the reader could easily see that
> the variable could never be modified indirectly via a pointer and
> that this made the code easier to read because you didn't need to
> worry about aliasing.
>
> I disagreed then, and still disagree. Saying 'register' nearly all
> the time clutters up the code, and the cost is not worth the benefit
> in C. It's pretty easy for a human reader to determine whether a
> local variable is taken the address of somewher in its function. (If
> it's hard, then write an Elisp function that will tell you. :-) In
> hindsight, perhaps C should have been designed so that 'register' was
> the default for local variables, and that one needed a special word
> to say "watch out! this variable might have its address taken!"; but
> the ship has sailed.
>
> 'const' is like 'register' in this respect. Putting 'const' nearly
> everywhere clutters C code. It's pretty easy for a human reader to
> determine whether a local variable is modified.
"const" is only similar to "register" in a way of having an additional
word. Sure it's easy for a human to find whether variable was modified,
but this requires to go through the whole function highlighting
variable usages. Now imagine if visibility scope has lots of variables?
This is especially relevant for the old C89 style where every variable
was declared at the beginning of a function.
And btw, current workflow with searching through the body doesn't work
well in vanilla Emacs. While other editors allow you to highlight
matches by putting a caret over a symbol, Emacs requires either
manually making it highlight/unhighlight, or installing a separate
package highlight-symbol.el which is a bit buggy and wasn't updated
since 2016. That is to say, having non-modified things declared with
"const" may help an average Emacs developer.
> (if it's hard, write an Elisp function :-)
But situation in there is similar: declaring a local variable requires
to use (let…), which means that even if you use variable once in the
end of a function, the variable will be visible to everything else. And
it's not like you can can make it immutable either.
> In hindsight, perhaps C should have been designed so that 'const'
> was the default for local variables; but the ship has sailed there
> too.
Yeah… FWIW, there's an "REmacs" effort on rewriting Emacs from C to
Rust, Rust has everything "const" by default. I'm sure emacs-devel
would largely disagree on integrating it because Rust isn't stable yet
(despite being widely deployed) and there's no GCC backend (LLVM only),
which are reasonable points. Still, I'm hoping at some point it will
change :)
next prev parent reply other threads:[~2019-04-20 1:09 UTC|newest]
Thread overview: 69+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-03-31 22:36 bug#35062: Patches: trivial cleanups Konstantin Kharlamov
2019-03-31 22:37 ` bug#35062: [PATCH 0/4] Trivial code cleanups Konstantin Kharlamov
2019-03-31 22:37 ` bug#35062: [PATCH 1/4] Remove redundant comparison Konstantin Kharlamov
2019-03-31 22:37 ` bug#35062: [PATCH 2/4] constify a bit of xterm.c Konstantin Kharlamov
2019-03-31 22:37 ` bug#35062: [PATCH 3/4] min_cols/rows is always 0, don't check for it Konstantin Kharlamov
2019-04-01 22:37 ` Noam Postavsky
2019-04-02 0:09 ` Konstantin Kharlamov
2019-04-02 14:46 ` Eli Zaretskii
2019-04-02 20:54 ` Konstantin Kharlamov
2019-04-03 4:45 ` Eli Zaretskii
2019-04-02 0:23 ` bug#35062: [PATCH v2] min_cols/rows is always 0, remove noop actions Konstantin Kharlamov
2019-04-05 7:05 ` Eli Zaretskii
2019-04-05 22:18 ` Konstantin Kharlamov
2019-04-06 7:09 ` Eli Zaretskii
2019-04-07 2:03 ` Konstantin Kharlamov
2019-04-07 2:45 ` Eli Zaretskii
2019-04-06 7:25 ` Michael Albinus
2019-03-31 22:37 ` bug#35062: [PATCH 4/4] don't compare unsigned to less-than-zero Konstantin Kharlamov
2019-04-01 4:37 ` bug#35062: [PATCH 0/4] Trivial code cleanups Eli Zaretskii
2019-04-01 13:27 ` Robert Pluim
2019-04-01 13:35 ` Konstantin Kharlamov
2019-04-01 13:41 ` Konstantin Kharlamov
2019-04-01 13:43 ` Robert Pluim
2019-04-01 13:51 ` Konstantin Kharlamov
2019-04-01 14:34 ` Eli Zaretskii
2019-04-01 15:04 ` Robert Pluim
2019-04-01 17:37 ` Eli Zaretskii
2019-04-02 20:49 ` bug#35062: [PATCH] Remove redundant multiplication of ch and cw Konstantin Kharlamov
2019-04-05 7:16 ` Eli Zaretskii
2019-04-07 2:13 ` bug#35062: [PATCH v3 1/3] Remove redundant comparison Konstantin Kharlamov
2019-04-07 2:13 ` bug#35062: [PATCH v3 2/3] constify a bit of xterm.c Konstantin Kharlamov
2019-04-13 8:15 ` Eli Zaretskii
2019-04-13 11:30 ` Konstantin Kharlamov
2019-04-13 11:36 ` Eli Zaretskii
2019-04-20 0:31 ` Paul Eggert
2019-04-20 1:09 ` Konstantin Kharlamov [this message]
2019-04-20 1:17 ` Konstantin Kharlamov
2019-04-20 6:53 ` Eli Zaretskii
2019-04-20 10:31 ` Konstantin Kharlamov
2019-04-20 11:01 ` Eli Zaretskii
2019-04-20 11:23 ` Konstantin Kharlamov
2019-04-20 11:25 ` Konstantin Kharlamov
2019-04-20 11:47 ` Konstantin Kharlamov
2019-04-20 11:58 ` Konstantin Kharlamov
2019-04-20 6:28 ` Eli Zaretskii
2019-04-07 2:13 ` bug#35062: [PATCH v3 3/3] don't compare unsigned to less-than-zero Konstantin Kharlamov
2019-04-13 8:11 ` Eli Zaretskii
2019-04-13 8:06 ` bug#35062: [PATCH v3 1/3] Remove redundant comparison Eli Zaretskii
2019-04-13 18:19 ` Konstantin Kharlamov
2019-04-13 18:24 ` Eli Zaretskii
2019-04-13 18:28 ` Konstantin Kharlamov
2019-04-13 19:19 ` Eli Zaretskii
2019-04-15 3:38 ` Richard Stallman
2019-04-15 6:49 ` Konstantin Kharlamov
2019-04-15 14:32 ` Eli Zaretskii
2019-04-15 15:01 ` Konstantin Kharlamov
2019-04-15 15:21 ` Eli Zaretskii
2019-04-15 17:03 ` Konstantin Kharlamov
2019-04-15 17:16 ` Eli Zaretskii
2019-04-15 17:29 ` Konstantin Kharlamov
2019-04-15 18:21 ` Eli Zaretskii
2019-04-15 18:14 ` Richard Stallman
2019-04-15 18:39 ` Eli Zaretskii
2019-04-15 14:25 ` Eli Zaretskii
2019-04-16 21:27 ` Richard Stallman
2019-04-17 2:40 ` Eli Zaretskii
2019-04-17 20:52 ` Richard Stallman
2019-06-23 18:07 ` bug#35062: Patches: trivial cleanups Lars Ingebrigtsen
2019-06-23 18:34 ` Constantine Kharlamov
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=1555722559.16908.0@yandex.ru \
--to=hi-angel@yandex.ru \
--cc=35062@debbugs.gnu.org \
--cc=eggert@cs.ucla.edu \
/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.