mavoweb / mavo

Create web applications entirely by writing HTML and CSS!
https://mavo.io
MIT License
2.85k stars 177 forks source link

Lift restrictions on property names by using a pair of characters around identifiers (only when necessary) #1008

Open LeaVerou opened 10 months ago

LeaVerou commented 10 months ago

While using Coda, I noticed something quite nice about its formula syntax. They allow names to contain any character, and just reserve a pair of characters ([] in Coda) to surround identifiers that contain special characters. They obscure these in the UI, but you can see them by copying a formula and pasting it as plain text.

For example, here's a formula to calculate time spent on a project, in a time tracker:

[Time tracker].Filter(Activity = thisRow).[Time spent].sum()

and here’s how it’s shown in the UI:

image

Note that they only use the brackets when necessary: Activity or thisRow do not need any.

We know from our user studies that restrictions around identifiers are a very common pain point, especially for non-technical users (like the ones that tried Lifesheets).

I think it would be pretty easy technically to implement something like this, the question is what pair of characters to use.

Non-viable options

Potentially viable options

The example above with each of these options:

[Time tracker].Filter(Activity = thisRow).[Time spent].sum()
{Time tracker}.Filter(Activity = thisRow).{Time spent}.sum()
[[Time tracker]].Filter(Activity = thisRow).[[Time spent]].sum()
|Time tracker|.Filter(Activity = thisRow).|Time spent|.sum()
#(Time tracker).Filter(Activity = thisRow).#(Time spent).sum()
id(Time tracker).Filter(Activity = thisRow).id(Time spent).sum()
`Time tracker`.Filter(Activity = thisRow).`Time spent`.sum()
joyously commented 10 months ago

My opinion is that overloading some sort of bracket just to allow arbitrary naming is not a good trade-off, especially if you have to change existing expressions. The existing usage was chosen as best option for the feature set implemented, so to go back and change it leaves both features as less than optimal. Would it work with backslash before the offending character? Or a function that removes characters before using the name in the expression?

DmitrySharabin commented 10 months ago

Backticks? Or is it too much for HTML/CSS developers? Or is it not very readable?

`Time tracker`.Filter(Activity = thisRow).`Time spent`.sum()
LeaVerou commented 10 months ago

Backticks? Or is it too much for HTML/CSS developers? Or is it not very readable?

`Time tracker`.Filter(Activity = thisRow).[Time spent].sum()

I don't think it's too much, I think a bigger issue is that it's used in JS in a different way, so it makes expressions confusing to read to those who do understand JS. But many options have this problem. I added this as an option to consider.