Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.c > #139338

Re: [Solved] Need some help getting to my feet

From rbowman <bowman@montana.com>
Newsgroups comp.lang.c
Subject Re: [Solved] Need some help getting to my feet
Date 2019-01-01 15:55 -0700
Message-ID <g929cvFm1bU1@mid.individual.net> (permalink)
References (10 earlier) <gzwWD.177487$le.59699@fx14.iad> <RZwWD.201178$%55.76713@fx10.am4> <slrn3s3kq2nf0p.iod.ike@iceland.freeshell.org> <g91vueFt63lU1@mid.individual.net> <lntvisksqz.fsf@kst-u.example.com>

Show all headers | View raw


On 01/01/2019 01:49 PM, Keith Thompson wrote:
> rbowman <bowman@montana.com> writes:
>> On 01/01/2019 12:14 PM, Ike Naar wrote:
>>> On 2018-12-31, Bart <bc@freeuk.com> wrote:
>>>> There are quite a few issues with having declarations scattered
>>>> anywhere, such as having to locate the declaration for name (which will
>>>> involve scanning every line backwards to the top of a function).
>>>
>>> Often those declarations are not "scatterd anywhere", they are
>>> just a few lines above the point where the name is used so
>>> there is no need to scroll back to the top of the function.
>>
>> At times when I'm modifying existing code I will put the new
>> declarations in the block where they are used. It's a signal to future
>> maintenance programmers that the block wasn't original functionality and
>> was added for some reason. We use Subversion so they can easily do 'svn
>> blame' to find the bug reference.
>
> I don't see how that signals that the code was added later.  Why wouldn't
> it have been written that way in the first place?
>

Because it wasn't :) I'll admit it is a special case but we have several 
hundred thousand lines of code going back over 20 years. The convention 
was, and still is for new functions, to declare all variables at the top 
of a function. A block with variable declarations stands out.

Obviously it would be meaningless if the stylistic convention was to 
declare variables in the blocks.

The arguments one way or the other do seem a little weak. I use Vim so 
if a variable suddenly appears # tracks it down pretty rapidly.

Again a special case and not C, but I chiefly use C++ with ESRI 
ArcObjects. It's COM based, depends heavily on smart pointers for 
interfaces, and tends to be verbose. Declaring the smart pointer at the 
point where you're going to magically say something like 'pFWS = pWS;' 
helps.

What I'm really saying is do what makes sense in the particular instance 
rather than saying 'Thou shalt declare all variables at the top.'

If I were writing the commandments there would be a 'Thou Shalt Not 
write 'float a, b, c, d, *e ,f ....'  That is as good a way to hide the 
variable you're looking for as any.

Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Re: [Solved] Need some help getting to my feet Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-05-04 13:31 +0000
  Re: [Solved] Need some help getting to my feet luser droog <luser.droog@gmail.com> - 2018-05-04 17:19 -0700
  Re: [Solved] Need some help getting to my feet Tim Rentsch <txr@alumni.caltech.edu> - 2018-05-18 21:55 -0700
    Re: [Solved] Need some help getting to my feet already5chosen@yahoo.com - 2018-05-21 03:26 -0700
      Re: [Solved] Need some help getting to my feet Tim Rentsch <txr@alumni.caltech.edu> - 2018-06-14 03:00 -0700
        Mixing declarations and statements in C code (Was: [Solved] Need some help getting to my feet) gazelle@shell.xmission.com (Kenny McCormack) - 2018-12-26 06:43 +0000
      Re: [Solved] Need some help getting to my feet Anton Shepelev <anton.txt@g{oogle}mail.com> - 2018-12-26 19:02 +0300
        Re: [Solved] Need some help getting to my feet Jorgen Grahn <grahn+nntp@snipabacken.se> - 2018-12-31 18:01 +0000
        Re: [Solved] Need some help getting to my feet Richard Damon <Richard@Damon-Family.org> - 2018-12-31 17:16 -0500
          Re: [Solved] Need some help getting to my feet Bart <bc@freeuk.com> - 2018-12-31 22:44 +0000
            Re: [Solved] Need some help getting to my feet Ike Naar <ike@iceland.freeshell.org> - 2019-01-01 19:14 +0000
              Re: [Solved] Need some help getting to my feet rbowman <bowman@montana.com> - 2019-01-01 13:14 -0700
                Re: [Solved] Need some help getting to my feet Keith Thompson <kst-u@mib.org> - 2019-01-01 12:49 -0800
                Re: [Solved] Need some help getting to my feet rbowman <bowman@montana.com> - 2019-01-01 15:55 -0700
                Re: [Solved] Need some help getting to my feet Keith Thompson <kst-u@mib.org> - 2019-01-01 16:05 -0800
                Re: [Solved] Need some help getting to my feet rbowman <bowman@montana.com> - 2019-01-01 22:17 -0700
              Re: [Solved] Need some help getting to my feet Bart <bc@freeuk.com> - 2019-01-01 20:25 +0000

csiph-web