preventing "duplicate" variable definitions

R

Roedy Green

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
 
G

Gordon Beaton

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
 
T

Tom N

Gordon said:
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).
 
H

Hemal Pandya

Gordon said:
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.
 
I

iamfractal

Gordon said:
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.


(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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top