preventing "duplicate" variable definitions

Discussion in 'Java' started by Roedy Green, Jul 14, 2005.

  1. Roedy Green

    Roedy Green Guest

    Consider this scenario.

    You type a variable name and discover that it is undefined. You think
    to yourself, "that name is correct, I must have forgotten to define
    it".

    You then insert the definition.

    However, unbeknownst to you there are now TWO variable with very
    slightly different names e.g.

    filename and fileName or

    firstGismoOnBlock vs firstGismoInBlock.

    The compiler sometimes will not detect the error.

    I have found the Eclipse reordering helps avoid this sort of problem.
    The two variants will soon be pulled side by side whence the problem
    becomes obvious. It can only hide if the two definitions are in
    different parts of the class file.

    The various outline views constantly expose the bare variable and
    method names to view so that problems with naming or even two
    legitimate similar variables warn you to rename to avoid ambiguity.

    Some will smack me down saying, just be more careful. Don't make
    mistakes. Deming, the father of quality control, points out such
    exhortations are absolutely useless in achieving higher quality. You
    need to change the environment of the worker to reduce errors.

    Some would say, what sort of slob needs such a tool? Not a slob, a
    perfectionist, who does not want even the slightest chance of an error
    leaking through that could in theory be detected by automation.


    --
    Bush crime family lost/embezzled $3 trillion from Pentagon.
    Complicit Bush-friendly media keeps mum. Rumsfeld confesses on video.
    http://www.infowars.com/articles/us/mckinney_grills_rumsfeld.htm

    Canadian Mind Products, Roedy Green.
    See http://mindprod.com/iraq.html photos of Bush's war crimes
     
    Roedy Green, Jul 14, 2005
    #1
    1. Advertising

  2. On Thu, 14 Jul 2005 12:38:36 GMT, Roedy Green wrote:
    > Consider this scenario.
    >
    > You type a variable name and discover that it is undefined. You think
    > to yourself, "that name is correct, I must have forgotten to define
    > it".
    >
    > You then insert the definition.
    >
    > However, unbeknownst to you there are now TWO variable with very
    > slightly different names


    You have described a downside to the "declare your variables right
    where you use them" school (next door neighbour to the school that
    doesn't want to declare any variables at all). I have a long
    background in C, and still like to declare variables at the top of the
    method (or the class), so in your scenario I would have seen the other
    declaration at that point.

    However I use emacs and am a true fan of symbol completion, using it
    almost constantly as I type. I type about 2-3 letters, then hit M-/
    (i.e. dabbrev-expand) to complete the name. I know immediately whether
    the symbol exists or not, and I never end up misspelling names or
    getting the case wrong.

    I realize you are learning a new tool, but honestly: asking it to
    reorder your code so you can manually scan it for similar looking
    near-duplicate symbols sounds to me like a technique from the dark
    ages.

    /gordon

    --
    [ do not email me copies of your followups ]
    g o r d o n + n e w s @ b a l d e r 1 3 . s e
     
    Gordon Beaton, Jul 14, 2005
    #2
    1. Advertising

  3. Roedy Green

    Tom N Guest

    Gordon Beaton wrote:

    > However I use emacs and am a true fan of symbol completion, using it
    > almost constantly as I type. I type about 2-3 letters, then hit M-/
    > (i.e. dabbrev-expand) to complete the name. I know immediately whether
    > the symbol exists or not, and I never end up misspelling names or
    > getting the case wrong.


    JBuilder has symbol completion.

    According to the Eclipse community page, "Editor Enhancements plug-in" provides symbol completion like
    Emac's dynamic abbrev expansion.
    TextComplete provides simple text completion .
    I'm not an Eclipse user so I don't know if these work but I'd be very surprised if someone hadn't done a usable
    symbol completion plugin (or else it is built-in).
     
    Tom N, Jul 14, 2005
    #3
  4. Roedy Green

    Hemal Pandya Guest

    Gordon Beaton wrote:
    > On Thu, 14 Jul 2005 12:38:36 GMT, Roedy Green wrote:
    > > Consider this scenario.
    > >

    [....]
    > >
    > > However, unbeknownst to you there are now TWO variable with very
    > > slightly different names

    [....]
    >
    > However I use emacs and am a true fan of symbol completion, using it
    > almost constantly as I type. I type about 2-3 letters, then hit M-/
    > (i.e. dabbrev-expand) to complete the name. I know immediately whether
    > the symbol exists or not,


    I second that. dabbrev rocks. Eclipse offers a "more intelligent"
    completion which can be used in this case. As an aside, I would like to
    mention that I actually prefer the emacs' "dumb" completion using which
    I can complete a prefix in comment with a variable name.

    > and I never end up misspelling names


    That depends on the definition of misspelling :). I have in past had
    to globally replace messageCoutner with messageCounter. But at least it
    reduces compile time errors and also duplicate variable error you Roedy
    refers to.
     
    Hemal Pandya, Jul 14, 2005
    #4
  5. Roedy Green

    Guest

    Gordon Beaton wrote:
    > On Thu, 14 Jul 2005 12:38:36 GMT, Roedy Green wrote:
    > > Consider this scenario.
    > >


    Snip.
    >
    > However I use emacs and am a true fan of symbol completion, using it
    > almost constantly as I type. I type about 2-3 letters, then hit M-/
    > (i.e. dabbrev-expand) to complete the name. I know immediately whether
    > the symbol exists or not, and I never end up misspelling names or
    > getting the case wrong.
    >


    >
    > /gordon



    (Braincrash! Switching to back-up ...)

    (Stunned.)

    I've been using Emacs for 2 years and am a religious non-reader of
    manuals.

    M-/ has completely blown my socks off.

    To you, gordon, I say: I thaaaank you.

    ..ed

    --
    www.EdmundKirwan.com - Home of The Fractal Class Composition.
     
    , Jul 15, 2005
    #5
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Replies:
    2
    Views:
    487
    Jerry III
    Aug 11, 2003
  2. Darrel
    Replies:
    5
    Views:
    827
    darrel
    Dec 6, 2004
  3. mathieu
    Replies:
    4
    Views:
    396
    mathieu
    Dec 18, 2007
  4. johkar
    Replies:
    0
    Views:
    1,891
    johkar
    Dec 16, 2009
  5. Jeff Johnson

    Duplicate class definitions

    Jeff Johnson, Jan 12, 2007, in forum: ASP .Net Web Services
    Replies:
    2
    Views:
    295
    Shailen Sukul
    Jan 15, 2007
Loading...

Share This Page