On 08/19/21 09:38, Ranier Vilela wrote:
>> 2. Declarations are closer to the actual usage. This is advised by the
>> "Code Complete" book [2] and has the following advantages:
>>    a. This limits variable scope to what is necessary. Which in turn makes
>> the mental model you have to keep of a function when reading the code
>> simpler.
>>    b. In most cases it allows you to see the the type of a variable
>> without needing to go to the top of the function.
>> 3. You can do input checking and assertions at the top of the function,
>> instead of having to put declarations in front of it. This makes it clear
>> which invariants hold for the function.  (as seen in the example above and
>> the changes for pg_file_rename[3])

I'm in sympathy with all of those points. I've never believed that the
arbitrary separation of declaration from use that was forced by C < 99
made anything more readable. If the project were started now from scratch,
I would be all in favor of declaring at first use.

But I think Tom's concern about backpatching hazards may carry a lot
of weight in practice.

>> It uses a Perl regex to search and replace! (obligatory jokes at the
>> bottom of the email)

However, even if such an idea were to get the green light, I think I would
take the obligatory regex jokes seriously, and instead use something like
srcML [0] and do the analysis and modification on proper parse trees.

Regards,
-Chap


[0] https://www.srcml.org/about.html


Reply via email to