Variable Naming Convention

General discussions about Automagic and automation in general

Moderator: Martin

Post Reply
Vyza
Posts: 11
Joined: 07 Feb 2013 02:03

Variable Naming Convention

Post by Vyza » 01 Mar 2013 02:50

It would be most helpful if you include the rules for naming variables.

saherr1969
Posts: 27
Joined: 01 Dec 2012 08:13

Re: Variable Naming Convention

Post by saherr1969 » 02 Mar 2013 19:09

From the documentation you can use almost any word as a variable. The only exceptions to that are the keywords that are listed in the documentation and the variable names already associated with the various components. Also, remember that variables that begin with global_ are global in scope so all flows can see them and the survive application/device restarts.

Vyza
Posts: 11
Joined: 07 Feb 2013 02:03

Re: Variable Naming Convention

Post by Vyza » 03 Mar 2013 00:40

The documentation does not include any rules that are typically specified within the naming convention. Such as:
Allowable characters?
Disallowed characters?
Whether lower case is differentiated from upper case?
Must first character be a letter?
Maximum length?

User avatar
Martin
Posts: 4468
Joined: 09 Nov 2012 14:23

Re: Variable Naming Convention

Post by Martin » 04 Mar 2013 07:50

The naming follows the same rules used by java. The language is case sensitive. A variable name must start with a letter, a currency symbol (such as "$") or a connecting punctuation character (such as "_") but no digit. The rest of the variable name can also contain digits.
I generally use US-ASCII lowercase letters and underscore characters for the variables supplied to flows (for example dock_state, battery_percentage etc.).
The length of a variable name is not artificially limited.

I will update the documentation accordingly.

For historical reasons, almost all valid strings can be used as a variable name using the functions getValue and setValue, but I discourage the use of this feature.

kkoolpatz
Posts: 3
Joined: 05 Apr 2013 19:10

Re: Variable Naming Convention

Post by kkoolpatz » 05 Apr 2013 19:50

Vyza wrote:Naming variables.
I am still a very new user, But this is what i use. Do you have any background in programming. I have named my variable such as this

D.GetWifiState (where D is fake Device class just for funn, and GetWifiStatus is like a method implemented. This helps me remember and reuse the variables)
global_D.RingerState
SMS triggers like D.SetWifiOff would trigger a flow called "D.SetWifi" and upon getting sms keyword "D.SetWifi" and execute on or off depending upon what follows.

Post Reply