Variables Naming Conventions

Do you find it helpful to put a “v” as the first letter of all of your variables? What about virtual devices, the same thing?

I find myself wanting do this because years ago I was taught to do this with database coding, and I find it hard to shake the habit.

But I’m not sure if there is much need to do this with Rule Machine.

I do that too in SQL code... Usually :slightly_smiling_face:. But for that I think the general idea is to be able to distinguish between parameters passed into a stored procedure and variables. There is less of a need in RM... Though perhaps one use of that approach, which now that I think about it I used, was to put a prefix on global variables (GV_) to distinguish those from local variables in a rule.

1 Like

I have done this …

Variables started with var.
Virtual switches start with vs.
Sensors start with xc. for contacts, xm. for motion, etc

Personally, I don't; there are limited contexts in which they can be used where they could possibly be confused with a device, so I don't see a reason to. A descriptive name is all I care about, while still making it short enough to use (or see) easily.

I do name some virtual devices starting with "virtual," especially if they don't really serve a single real-world device (but for an example that does: my switches like "Timed Kitchen Fan," a virtual device that turns the kitchen fan on for a half hour or so before turning it back off). This helps distinguish them easily from physical devices, whether in device lists or with misheard voice control commands and whatnot.

3 Likes

That is where I was heading with my comment too, there is more context provided when working with variables in RM, or any app for that matter, you are typically performing an action that is acting on or using a variable verses a device, and the even if there are similar concepts between local and global variables you can typically indicate the different purpose simply through the terms used rather than a prefix.

2 Likes

I have a lot of rules, but for the most part, I haven’t used prefixes to define the types of variables or devices. This hasn’t been an issue.

I do however prefix device names by the name of the room they’re in and that has been very useful.

2 Likes

I use an ! to group all the variables together and put them at the very top of the list.