REQ: variable name suggestion plugin
I thought it would be useful, escpecially for new programmers, if there was a plugin that would suggest variable names. I thought it would be nice to press some key combination that asks you what your variable is and then gives you a variable name based on Hungarian notation. What does everyone think? Would it be useful?
Please sign in to leave a comment.
charles decroes wrote:
IDEA already does that. Have you tried to press Ctrl-Space right after
the class name in the variable declaration statement?
/kesh
That is ok but it just creates a very generic name. For a JComboBox is suggests box, jComboBox ect. I was thinking more of a popup that says what is this? I type in First Name and it suggest fstNm; based on hungarian notation.
From How To Write Unmaintainable Code ["http://mindprod.com/unmain.html"]
"Hungarian Notation is the tactical nuclear weapon of source code obfuscation techniques Due to the sheer volume of source code contaminated by this idiom nothing can kill a maintenance engineer faster than a well planned Hungarian Notation Attack."
I don't really care what notation is used. Hungarian is just the most common (in my experience)
IMHO I would rather see hungarian than
JComboBox box;
JComboBox box1;
JComboBox box2;
...
so any type of notation is fine, just something that takes an english phrase like Customers First Name and turns it into a decent variable name
fstNm is not Hungarian notation for First Name, at least
in my understanding. Hungarian notation would prefix the
variable name with a type specific prefix, strFirstName
for example.
In IDEA you can define prefixes for class members and
static variables (I use _ and s_) and then Ctrl+Space
will suggest properly prefixed names based on context.
See: IDE Settings / Code Style / General / Naming
A plugin could define prefixes for all the basic types
and then Ctrl+Space would apply that prefix, no need
for a dialog box.
The Hungarian notation does have some merits but I
agree that its overall benefits are questionable.
Marius
charles decroes wrote:
Also I guess I was thinking of some form of hungarian. I don't really like the type_ect stuff but some variation of it.
A little OT, but why bother with Hungarian or any other ShortCutarian
notation when identifier can be any length ?
Why write
String ClntFrstNm = ..
when all you need is
String ClientFirstName = ..
?
Alain
That is a very good point. The thing I run into is stuff like PhysicianPrescribedPointOfSaleDailyCoPayMax so the getters and setters get even larger. I find I need to shorten them so how so I try to remove vowels and abbreviate. All of this takes time to do which is why I thought a plugin might work. Maybe it's just a bad idea?
It sounds like a "namespace" issue. From your example, it would suggest that you can't refer to the variable as maximum, because it would clash with some other "maximum" value. This then occurs all the way up the chain, until you have a number of semantic qualifiers, leading to long names.
To me this smells as if the object structure needs to be revisted. Make your namespaces (object heirarchy) more succinct and impart actual meaning to the objects contained within instead of encapsulating so many fields into one object.
If thats not possible, IMO, getUserDefinedScreenWidthMaximum() is still preferable to getUsrDefScrWidMx()
Actually that is a single dollar amount variable, not a hierarchy at all :)
"charles decroes" <spam@decroes.com> wrote in message
news:29336482.1056488232550.JavaMail.itn@is.intellij.net...
You might think the getter would be called
"getPhysicianPrescribedPointOfSaleDailyCoPayMax()", but in IDEA, it's called
"getPhy +]]>" :)
So don't worry about the long names...
There have been a few instances where I've been teaching someone to write
some code for a program they'd never seen before, using a language they've
never used (Java) and an IDE they've never heard of (IDEA). It's amazing how
many times I answer their questions with " + + ]]>", for
example:
Them: "Hmmm... how do I convert foo to an integer?"
Me: "foo dot control shift space"
When there is no 'hierarchy', or dependency, I sometimes introduce one,
just for the sake of clarity, and create a simple 'Person' - for example
- inner class :
If you introduce a 'PointOfSale' (inner)class, you can then rewrite :
PhysicianPrescribedPointOfSaleDailyCoPayMax
into
PointOfSale pos = ...
pos.maxDailyPhysicianPrescribedCoPay
You'd have to balance the cost and clarity of both versions in your
code, though. This is surely no silver bullet.
Alain
Yes, IDEA helps a lot with typing, but then there
is the readability issue as well.
Which of the following two sets is easier to
distinguish:
getPhysicianPrescribedPointOfSaleDailyCoPayMax()
getPhysicianPrescribedPointOfSaleDailyCoPayMin()
or
getMax()
getMin()
How about:
getPhysicianPrescribedPointOfSaleDailyCoPayMax()
getPhysicianPrescribedPointOfCareDailyCoPayMax()
I do prefer longer names, but there is a point where they
become too long. Can you imagine the long method name
mentioned above used in an expression where there are
a few other names just as long?
Marius
Erik Hanson wrote:
>>That is a very good point. The thing I run into is stuff like
>>PhysicianPrescribedPointOfSaleDailyCoPayMax so the getters
>>and setters get even larger. I find I need to shorten them so
>>how so I try to remove vowels and abbreviate. All of this
>>takes time to do which is why I thought a plugin might work.
>>Maybe it's just a bad idea?
"Marius Scurtescu" <mscurtescu@healthmetrx.com> wrote in message
news:3EF8D33A.8050002@healthmetrx.com...
>
>
>
>
>
>
>
Sure:
int max = getPhysicianPrescribedPointOfSaleDailyCoPayMax();
int min = getPhysicianPrescribedPointOfSaleDailyCoPayMin();
int actual = getActualField().intValue();
if ( ( actual <= max ) && ( actual >= min ) )
rethreadFluxCapacitor();
I don't mind using more generic names in a very limited scope like above.
[Of course, a little refactoring would make it even clearer:
Range range = getPhysicianPrescribedPointOfSaleDailyCoPayRange();
if ( range.contains( getActualField() ) )
rethreadFluxCapacitor();
Or:
PointOfSale pos = getPhysicianPrescribedPointOfSale();
if ( pos.dailyCoPayRangeContains( getActualField() ) )
rethreadFluxCapacitor();
]
I don't think I'm being clear
PhysicianPrescribedPointOfSaleDailyCoPayMax
is an attribute on an InNetwork object. So this is a single instance variable within a class.