Skip to content

Variable naming

Variable Naming Convention in Wized: Keeping it Simple and Descriptive

When it comes to variables in Wized, simplicity and clarity are key.

Wized projects typically involve a small number of variables, but it’s still a good idea to stick to a naming convention. This will ensure readability and easy understanding of each variables purpose by anyone who opens your project.

Summary/Cheat Sheet

When working with variables in Wized, we recommend sticking to the following guidelines:

Iteration Variables:

  • For rendering a list, use the iterator variable conventionally named i (v.i) to keep track of the current item being iterated upon.
  • It's safe to reuse the i variable for multiple lists on a page, as long as they are not nested.
  • For nested lists, introduce additional iterator variables like j, k, and so on (r.1.d[i].column[j]) to maintain clarity and avoid conflicts.

Descriptive and Straightforward Names:

  • Use snake_case to separate words in variable names for improved readability.
  • Choose descriptive names that clearly indicate the purpose or content of the variable.
  • Avoid generic names like x and opt for explicit names like product_count or user_name.
  • Descriptive names contribute to the understanding of variable content and help maintain clarity within your project.

Iteration Variables: i, j, k, and Beyond

Rendering a list (i)

The most common use-case for variables in Wized is loops.

Whenever you render a list of items on your page, Wized is essentially looping through each item in the array.

To keep track of the current item being iterated upon, Wized uses an iterator variable conventionally named i. This variable can be accessed within the loop using v.i. Here, "v" references the variable object, and "i" is the name of our variable. If you want to then set a heading for each item rendered from your first request, you can do something like this:


Can I use the same iterator variable for multiple lists on a page?

Yes, you can.

The variable is only available to the scope of the loop. Meaning it can only be accessed by items within the array that’s being rendered.

This means that you can safely use the same iterator i for every list on your page, as long as the lists are not nested.

Nested lists (j,k,l…)

But what if we’re rendering a list within a list?

You can not simply stick to the name i, because this variable is already used for keeping count of the outer loop.

This is where you’d want to create another variable called j.

To give an example, let’s say you’re receiving data from a table. r.1.d is the array that contains all of your table rows, and each row has nested columns.

So to loop through the rows, you would use r.1.d[i]

But if you wanted to render a list within your list, you would use j as your iterator variable, and then you would use r.1.d[i].column[j]

If you need an additional level of nesting you would use k.

By following this convention, it becomes easier to understand the purpose of each iteration variable and track the nested levels of iteration.

Descriptive and Straightforward Names

In addition to iteration variables, which contain only a single letter, variables used in Wized should be named in a descriptive and straightforward manner.

This helps ensure that the purpose and contents of the variables are clear to anyone reviewing the project.

We have two main guidelines for naming variables in Wized:

  • Use snake_case: Separate words with underscores for improved readability.
  • Be descriptive: Choose names that clearly indicate the purpose or content of the variable. For example, instead of a generic name like x, opt for something more explicit like product_count or `user_name.

Here's an example showcasing these guidelines:

product_count = 10

user_name = "John Doe"

user_is_admin = true

product_categories = [”shirts”, “pants”, “hats”, “shoes”]

chart_data = {}

With these descriptive variable names, it becomes apparent what each variable represent.

Keep it Compact and Intuitive

In Wized projects, the focus is on clarity and simplicity.

Keep variable names concise while still conveying their meaning.

Avoid unnecessarily long names or excessive use of abbreviations.

Strike a balance that makes the variable names both informative and easy to work with.

Remember, while variables are not heavily used in Wized, using a naming convention will still make your project easier to manage, and maintain.