[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Emacs-diffs] /srv/bzr/emacs/trunk r109864: Fix minor problems found

From: Jan Djärv
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


4 sep 2012 kl. 10:58 skrev Paul Eggert <address@hidden>:

> 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 via email to

[Prev in Thread] Current Thread [Next in Thread]