[solved] Behavior/functions variable best practice?

What’s the best way to use/name variables in functions and behaviors so you don’t risk conflicting with the calling projects variables? I’ve seen the use of a double colon in between the function name and variable like “circles::x” but I haven’t seen any mention of the double colon in any documentation.

You can make properties in behaviors hidden. Should I use nothing but properties in behaviors instead of variables?

Underscores or CamelCase are your best bet.
In behavior you can mix both properties and variables is perfectly fine.
Use properties when you see that a variable is repeating a lot in your code so maybe is best to turn that variable into a property.

thanks. I just had a problem between my own similar functions that was being caused by the same variable. Luckily, I found it fairly quickly. What about the double colon like box::width ? What are they designed for?

The double colon is referred to as a scope resolution operator. It allows you to access properties or methods/functions of a class (or behaviour in this case).

1 Like