Take the 2-minute tour ×
Geographic Information Systems Stack Exchange is a question and answer site for cartographers, geographers and GIS professionals. It's 100% free, no registration required.

Not sure if this is really that important, but I'm wondering if there is a list of "common variable names" for different ArcMap objects... for instance, sometimes you see:

IMxDocument mxdoc = ArcMap.Application.Document as IMxDocument
IMxDocument mxDocument = ArcMap.Application.Document as IMxDocument
IMxDocument pMxDocument = ArcMap.Application.Document as IMxDocument

Then for IMap it could be:

IMap map = mxdoc.FocusMap
IMap pMap = mxdoc.FocusMap

Etc. etc. etc. I'm just curious to know if there is a list of commonly used variable names (ie use mxDoc for IMxDocument, use map for IMap, etc.)

share|improve this question
3  
What purpose would such a list serve? I don't think that ArcObjects being involved really matters. More important are the general programming conventions used in your organization and consistency with those conventions. –  blah238 May 31 '13 at 1:44
1  
+1 When working with a group of people on the same codebase, it would be useful to have such a list to improve readability. –  Kirk Kuykendall May 31 '13 at 3:12
add comment

2 Answers

up vote 2 down vote accepted

From my experience I have not seen a list defining common interface variable names, however more emphasis on the following:

  • use lowercase prefix characters (e.g. 'p' = pointer , 'm_' or 'g_' local or global scope, 'str' or 'int' for common variable types (strings or integers)...etc)
  • use combination of lower and upper case characters between prefix and interface variable names to increase readability
  • spell out full interface variable names for increased readability (e.g. pMap, or pMxDocument)

Here are a couple links that go over these bullets:

http://resources.arcgis.com/en/help/arcobjects-net/conceptualhelp/index.html#//000100000nq6000000

https://www.e-education.psu.edu/geog489/node/2084

share|improve this answer
2  
I woudn't take ESRI's word as gospel. Hungarian notation is discouraged in the .NET Framework Design Guidelines‌​. I think it makes it less readable and is pretty pointless when you have things like Intellisense and compile-time type checking. Yes you will find that style in most of ESRI's samples and related materials but personally I find it to be pretty "messy" and I don't think you'll see that style much outside of old ESRI samples which were largely ported from C++/VB6. –  blah238 May 31 '13 at 6:09
    
@artwork21 Thanks for the links very useful !! –  Sunil May 31 '13 at 6:15
1  
Note for GIS folks just getting into programming: usually "global" variables have nothing to do with globes. –  Kirk Kuykendall Jun 3 '13 at 14:26
1  
I will not downvote because this largely a subjective issue, but I would personally advise against each and every point. –  Petr Krebs Jun 5 '13 at 13:04
add comment

This is one area where I think ESRI could do with changing their examples and coding conventions. As @blah238 has mentioned in the comments, hungarian notation is generally frowned upon these days, and has been for a number of years. I'm not sure why ESRI insists on sticking to its usage.

One of the best ways of ensuring your .net code follows industry standards is to use something like Microsoft's StyleCop. This automates the checking of the layout and style of your code. You can turn on/off recommendations if you want so you can be as strict as you want to be. It also gets round the need to write (and get people to read and enforce) separate coding standards (e.g. ESRI's).

You can also go one further and look at FxCop which can analyse assemblies to look for design, performance, security, etc improvements.

I think the question of what the actual variables names are is less important. As long as the names you choose are sensible, and the code in general is easy to read and understand, then job done.

share|improve this answer
    
+1 I agree with this in principle. In practice though, unless you have an intern, going back and updating legacy code to match new standards sure isn't much fun. Also, one of the main motivations behind moving away from hungarian notation is that modern IDE's (like Visual Studio) tell you the type when you hover over the variable. What about readability of code posted on a forum though? See also Microsoft's Naming Guidelines. –  Kirk Kuykendall Jun 5 '13 at 14:04
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.