unofficial mirror of emacs-devel@gnu.org 
 help / color / mirror / code / Atom feed
From: "Jan Djärv" <jan.h.d@swipnet.se>
To: Paul Eggert <eggert@cs.ucla.edu>
Cc: "emacs-devel@gnu.org" <emacs-devel@gnu.org>
Subject: Re: [Emacs-diffs] /srv/bzr/emacs/trunk r109864: Fix minor problems found by static checking.
Date: Tue, 4 Sep 2012 12:25:49 +0200	[thread overview]
Message-ID: <644FCDD6-1590-477B-A0AF-B418446D6FD8@swipnet.se> (raw)
In-Reply-To: <5045C2CB.90506@cs.ucla.edu>

Hello.

4 sep 2012 kl. 10:58 skrev Paul Eggert <eggert@cs.ucla.edu>:

> On 09/04/2012 01:31 AM, Jan Djärv wrote:
> 
>> Given that Emacs have quite a lot of functions that are more than a
>> couple of hundred lines long, it is not typically easy.  For smaller
>> functions, it can be, but small functions sometimes becomes big.
> 
> No doubt our styles differ, but I don't find it that hard.
> 
> For example, on my screen right now I have lib/mktime.c.  It has a
> function __mktime_internal that is a couple of hundred lines long.  As
> I understand it, you're proposing that almost all of its dozens of
> local variables should be decorated with 'const'.  That is, something
> like this:
> 
>  int min = tp->tm_min;
>  int hour = tp->tm_hour;
>  int mday = tp->tm_mday;
>  int mon = tp->tm_mon;
>  int year_requested = tp->tm_year;
>  int isdst = tp->tm_isdst;
> 
> would be changed to something like this:
> 
>  const int min = tp->tm_min;
>  const int hour = tp->tm_hour;
>  const int mday = tp->tm_mday;
>  const int mon = tp->tm_mon;
>  const int year_requested = tp->tm_year;
>  const int isdst = tp->tm_isdst;
> 
> I dunno.  To me those 'const's would take up valuable screen real
> estate, and they would slow me down when I read the code, and it's
> really not worth the trouble.

Unless you have very narrow frames, this does not take up more screen estate, just whitespace estate.

If some variable is not const and then a pointer to it is passed into another function, you have to lookup that also. Or find the documentation if the source is not close by.

>  If I want to know whether mday is
> modified later, I can just search for 'mday'; that's fast.  And in the
> typical case where I'm not interested in that particular detail, the
> 'const's would be wasting my time.

I read "const X" as fast as "X". I mostly program in C++, I guess const is more used there.

    Jan D.


  reply	other threads:[~2012-09-04 10:25 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
     [not found] <mailman.503691.1346667442.854.emacs-diffs@gnu.org>
2012-09-03 15:35 ` [Emacs-diffs] /srv/bzr/emacs/trunk r109864: Fix minor problems found by static checking Eli Zaretskii
2012-09-03 18:54   ` Stefan Monnier
2012-09-03 19:37   ` Paul Eggert
2012-09-03 20:44     ` Eli Zaretskii
2012-09-03 22:29       ` Paul Eggert
2012-09-04  3:41       ` Stefan Monnier
2012-09-04  5:29         ` Jan Djärv
2012-09-04  5:45           ` Paul Eggert
2012-09-04  8:31             ` Jan Djärv
2012-09-04  8:58               ` Paul Eggert
2012-09-04 10:25                 ` Jan Djärv [this message]
2012-09-04 14:29             ` Jason Rumney
2012-09-04 19:19               ` Stefan Monnier
2012-09-04 18:51             ` Wojciech Meyer
2012-09-04 18:22         ` Wojciech Meyer
2012-09-04 14:26   ` Jason Rumney
2012-09-04 14:33     ` Andreas Schwab
2012-09-04 16:52       ` Eli Zaretskii
2012-09-04 18:36         ` Wojciech 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://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=644FCDD6-1590-477B-A0AF-B418446D6FD8@swipnet.se \
    --to=jan.h.d@swipnet.se \
    --cc=eggert@cs.ucla.edu \
    --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).