Hi Collin,

> Thanks! I got most of them in Coreutils, inspired by your changes [1].

Nice to see the coreutils becoming more readable too (by today's code
style habits).

> Semi-related, but did pre-standard C not allow initialize variables upon
> declaring them?
> 
> See this code copied from Coreutils src/basename.c:
> 
>     static void
>     remove_suffix (char *name, char const *suffix)
>     {
>       char *np;
>       char const *sp;
>     
>       np = name + strlen (name);
>       sp = suffix + strlen (suffix);
>     
>       [...]
>     }

Already in pre-standard C, one could write

     static void
     remove_suffix (char *name, char const *suffix)
     {
       char *np = name + strlen (name);
       char const *sp = suffix + strlen (suffix);
     
       [...]
     }

But if the programmer later wanted to add a statement between
the declarations, they couldn't write

       char *np = name + strlen (name);
       if (!suffix)
         suffix = ".txt";
       char const *sp = suffix + strlen (suffix);

because that would mix declarations and statements. They would
have had to write

       char *np = name + strlen (name);
       if (!suffix)
         suffix = ".txt";
       {
         char const *sp = suffix + strlen (suffix);

But reindenting a block of code was not easy at that time:
  - The editors were line oriented, not block-oriented.
  - Additionally, GNU source code used tabs for indentation all
    over the place.
Nowadays, people can use Emacs with M-x indent-rigidly, but
that was not commonplace before ca. 1990-1995.

And so the programmers settled on the "declare all local variables up-front"
coding style.

Bruno




Reply via email to