• 0

Using non-descriptive variable names...


Question

on another note your lectures

the word "amt" is not descriptive and is very poor programming

he/she should have used the fullword "amount" as I did.  short hand variable make it difficult to read

We use 'amt' very often at work. Everybody knows what it means.

It would be bad programming to use 'a', but 'amt' equals amount in everyone's (who'll have to look at the actual code) mind so I would consider it a descriptive variable.

I would also consider using 'amt' in a 'banking' application as being a descriptive variable too. I would be surprised to find anyone going through a bank app. code to not know what amt would mean. Especially in a method called deposit()!

Granted, amt could mean something else, and it would be bad programming to use a amt variable to mean something else. But then, most complete words have multiple meanings too.

So I think that u can't say that using an abbreviation for a variable name is "very poor programming".

Just my 2 cents.

*edit: Now that I checked, I could add that java.sun.com often uses abbreviations for variable names in their examples. 'num', 'rect', 'fps', etc.

Edited by Mouton
Link to comment
Share on other sites

Recommended Posts

  • 0

Side-note: Eclipse does the same thing in Java. Auto-completion, mouseover, plus CTRL-Click sends u the the variable or method definition (quite handy).

Link to comment
Share on other sites

  • 0
Plus, with VS.Net 2003, if you hover the mouse over a variable, it tells you its type and whether it's local, a parameter or a class-level variable in a tooltip.

Aaaand if you want this a step further you should try a plugin called "Visual Assist". Beware though, it's commercial. You can use it for free for 30 days IIRC - well worth paying for anyway. Extremely nice. In my opinion at least, your mileage may vary.

Link to comment
Share on other sites

  • 0
Aaaand if you want this a step further you should try a plugin called "Visual Assist". Beware though, it's commercial. You can use it for free for 30 days IIRC - well worth paying for anyway. Extremely nice. In my opinion at least, your mileage may vary.

584720258[/snapback]

I've used that, and it's OK. I just started using ReSharper and I totally love it. It's by the guys that write IntelliJ IDEA. Quite nice. I think it blows the doors off of Visual Assist.

http://www.jetbrains.com/resharper/

Link to comment
Share on other sites

  • 0
I think using "amt" is fine as well.  As long as it's fairly obvious what it means and what the variable contains, it shouldn't be a problem.  If you use comments throughout the code, it should be easy to work out what everything means.

Why?  Hungarian notation (which is what this is) is the spawn of the devil.  Microsoft no longer recommends its use for .NET programming.  What happens if you decide to change the type of one of your variables (say from an integer to a long)?  And it's usually perfectly clear from the context in which the variable is used what type it is (and you can always scroll up to check).

More on Hungarian notation/variable prefixes here and here.

584705374[/snapback]

Well I don't use the hungarian notation in a strict sense at all. I never used to prefix the variable with the type...just where I work does it so I got into the hang of it. If I change the type of the variable, then the variable name is going to change...and if you're using vs.net its so easy to go through code and adjust the name. Plus, functions/methods shouldn't be overly long anyway so there shouldnt be too many occurences of the variable name. (hehe but there's always some of those massive functions lying around). Anyway, if you change the data type of a variable, you're most likely going to have to change code anyway, such as casts.

in one subject at uni, we had to use a notation where you put an i infront of a variable if it was an input variable, o infront of it if it was output...and then i think also the type. Now that was a crap notation.

I personally find the prefixing messy if used with primitives such as double, int etc.

however prefixing large object I find makes it a little eaiser to read... like

frmMain - an instance of TForm called main

tblAbout - an instance of TTable called about

still

MainForm and AboutTable is easier to read than the above

584709505[/snapback]

To me, frmMain/tblAbout is easier to read than MainForm and AboutTable, but thats most likely because its what i am used to....i could easily adapt to MainForm etc...

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.