Terminal widths, and coding style... My 0.00000002c worth (was 0.02c, share market just "corrected" my net value)...

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Terminal widths, and coding style... My 0.00000002c worth (was 0.02c, share market just "corrected" my net value)...

sur-behoffski
G'day,

Some miscellaneous ramblings about the list's meanderings over the
last week or so:

1. WELL, by setting my terminal's font point size to 1.5, I managed
to get a terminal width over 1000 characters!!!  SO THERE!!! (Pity
that I can't read any of the text.);

2. I abhor Hungarian notation, but I use CamelCase for identifiers,
and I've adopted one snippet that relates to the "give pointers
their own type"... I don't do that, but do this instead (somewhat
influenced by the "declaration mimics use" ethos that was used
when typeless "B" became typed "C" all those years ago):

         int Width;
         int *pWidth;
         int **ppWidth;

Using the "p" prefix, balancing the level of indirection, leads to
code like:

         Width = *pWidth;
         ppWidth = &pWidth;

3. I agree with 8-column indentation, using strictly spaces as a
canonical representation, as this fits in with content-based
version control systems such as Git with strict whitespace
controls enabled.  I strongly agree with the fact that such a
wide step quickly makes you run out of space, especially with an
80-column limit, and that, as the mind's limit to handle nested
concepts/abstractions is limited, a lot of indentation is a very
strong signal that the code is becoming too complex to be easily
understood, and that refactoring/other reworking is worthwhile;

4. I've adopted "?? " as a general-purpose TODO: or REVIEWME:
marker:  It is a trigraph, which most people don't like, but the
space after the question marks makes it harmless.  Some people may
dislike it for another reason:  The question mark meta-character
is often an integral part of pattern matching (e.g. regular
expressions in various incarnations).  This is valid, but sadly,
it's too ingrained in my style for me to abandon it now; and

5. I've adopted a shorthand for "Number" suggested by one of the
most influential coders+hardware designers that I encountered
during my younger days:  Use the slightly-Germanic-style "Nr" as
a contracted version, prefix or postfix, for "Number", "Num",
etc, e.g.

        unsigned NrPrimes;
        unsigned Candidate;

         /* ?? A sanity check on Limit versus "unsigned" type
            would be appropriate here, but left out for brevity.  */

         /* Count how many primes are in the range [2..Limit], as
            this gives us a baseline for the main algorithm.  */
         NrPrimes = 0;

         /* Treat 2 separately, as it is the only even prime; this
            reduces the candidates we need to test in the main loop
            below.  */
         if (Limit >= 2) {
                 NrPrimes++;
         }

         /* Look for more primes in the range [3..Limit].  */
         for (Candidate = 3; Candidate <= Limit; Candidate += 2) {
                 if (IsPrime(Candidate)) {
                         NrPrimes++;
                 }
         }

         printf("NrPrimes: %u\n", NrPrimes);

cheers,

sur-behoffski
programmer, Grouse Software

Reply | Threaded
Open this post in threaded view
|

Re: Terminal widths, and coding style... My 0.00000002c worth (was 0.02c, share market just "corrected" my net value)...

Gerhard Sittig-2
On Wed, 2018-02-07 at 19:38 +1030, sur-behoffski wrote:

>
> 2. I abhor Hungarian notation, but I use CamelCase for identifiers,
> and I've adopted one snippet that relates to the "give pointers
> their own type"... I don't do that, but do this instead (somewhat
> influenced by the "declaration mimics use" ethos that was used
> when typeless "B" became typed "C" all those years ago):
>
>         int Width;
>         int *pWidth;
>         int **ppWidth;

It's funny.  But have you noticed that this _is_ Hungarian
notation?  In the very sense which the original article suggested
it could be.  Not in the unfortunate way which is so popular yet
so not useful.  It's not the idea which was bad, it's those who
found a rule to cling to without getting the point of it who gave
it a bad smell.


virtually yours
Gerhard Sittig
--
     If you don't understand or are scared by any of the above
             ask your parents or an adult to help you.