Variable Naming Conventions?

I’m a developer, so I’m anal by definition. I’d like to come up with a good convention for naming variables, and I figured I’d ask here because surely other people have already thought this through.

Some things to consider:

  • Variables that I’d consider “local” to a macro, i.e. I don’t care if they get reused in another macro for something else.

  • Variables that I’d consider “global” to a macro, i.e. they shouldn’t be reused by other macros.

  • Variables that are used as “parameters” to be passed to a subroutine-like macro, and also possible returned from said macro.

Any thoughts on this? Thanks.

Great question!

I too like to use naming conventions.
Here is what I do:

  • Local
  • No special convention
  • just name to reflect usage
  • All "local" variables are deleted at end of macro (see my macro below)
  • Global
  • The only sense of "global" is have is if I need to reuse the contents of a variable in either another execution of the same macro, or by other macros
  • For these variables, I use a prefix of "DND__", meaning "Do Not Delete".
  • But you could just was well use "g__" for Global.
  • There are two underscores at the end of the prefix. This is so that if I use it in a "Prompt for Input" Action, the prefix does NOT show in the label.
  • But if you want to specify use for a particular macro (or set of macros), then you could use a prefix that denotes that macro.
    • For example, suppose I have a macro that uses an author list for scripts I clip. I might name the author selection list "SCPT__Author_List"
  • Parameters
  • Not using anything special now (maybe I should)
  • The "parameter" variable is deleted at the end of the main macro
  • IF I did have a prefix, it would be "p__", again with two underscores at the end.
  • Since you can pass a parameter with KM7, you may not need a special parameter variable.
    .

I use this sub-macro at the end of my main macro to delete all variables:

I also have posted this macro to "clean out" your current, not needed, variables:

Good luck, and please feel free to provide any feedback on my thoughts, as well as to post your final decision on naming conventions.

Thanks for the thoughts!

Thanks for sharing this, JMichael! I’ve downloaded the macro and really like the variable naming conventions as well as the idea of deleting them. I have to clean up a bunch of variables from old projects but have been afraid to wipe out ones that I’ll still need. The DND__ is a great idea as well as the 2 underscores trick