Re: variable declaration, was RE: moving to the next line

From: Chris Devers (cdevers_at_pobox.com)
Date: 12/17/04

  • Next message: Charles K. Clarkson: "RE: variable declaration, was RE: moving to the next line"
    Date: Fri, 17 Dec 2004 12:06:36 -0500 (EST)
    To: Paul Johnson <paul@pjcj.net>
    
    

    On Fri, 17 Dec 2004, Paul Johnson wrote:

    > On Fri, Dec 17, 2004 at 09:17:05AM -0500, Chris Devers wrote:
    >
    > > On Thu, 16 Dec 2004, Charles K. Clarkson wrote:
    > >
    > > > Don't declare all your variables at the beginning
    > > > of the script. It works in other languages, but not
    > > > in perl. Declare them as you go.
    >
    > I suppose that depends on your definition of "works".
    >
    > > Out of curiosity, why this rule?
    >
    > Locality of reference.

    Meaning... declare it where you use it, QED ?

    The counterargument to that might be "spagetti code, QED".

    That is, if you declare everything at the last possible line, then
    there's no clear organization of what data is being tracked in a given
    segment of code. On the other hand, if you cluster the declarations a
    bit -- not globally, but lexically -- then to my thinking things are
    clearer.

    This isn't something I feel strongly about one way or the other. I just
    find it striking that the advice given out on this list differs so
    starkly with the practice that I have been taught (and have seen other
    people doing in their code) in the past.

    -- 
    Chris Devers
    

  • Next message: Charles K. Clarkson: "RE: variable declaration, was RE: moving to the next line"

    Relevant Pages

    • Re: New to Perl: Need help with a script
      ... It might take some getting used to (you'll need to declare your variables, ... >sub usage() { ... You might want to use a here-doc (perldoc perldata) instead, ... pointing to the same array reference. ...
      (comp.lang.perl.misc)
    • Re: Excel Automation
      ... Declare a conditional compilation constant at the start of your module: ... #If EarlyBinding Then ... Dim xlApp As Excel.Application ... When you are ready to distribute the app, remove the reference, change the ...
      (microsoft.public.access.formscoding)
    • Re: Question about OO programming in Ada
      ... when I declare a procedure ... Both the Ada Rationale and the Guide for C/C++ programmers say that you have ... The Ada 95 Reference says that the "all" attribute provides read-write ... Does that help to avoid casting as well? ...
      (comp.lang.ada)
    • Re: CreateObject("Word.Application") fails though Word session starts
      ... I absolutely agree that 1004 isn't a useful error code -- but it's ... The 'objWordApp' object is declared with a "Public Const gobjWordApp ... The idea of a missing reference is interesting. ... How did you declare gobjWordApp? ...
      (microsoft.public.excel.programming)
    • Re: Public variable not seen by all controls on a Page
      ... User Control, so you must reference it through the User Control. ... Also note that you have the property declared as "quickAdd" but you are ... Is there a place in the page where I can declare a variable (maybe ...
      (microsoft.public.dotnet.framework.aspnet)