Re: [css-variables] ...let's change the syntax

18.03.2014, 19:41, "Brian Kardell" <bkardell@gmail.com>:

> Note that really the primary driver for changing anything would be a single way to notate 'custom things',

I'm not really convinced that all custom things must necessarily have same or similar syntax, and that such similarity is a really big advantage that we should be in pursuit of at any price.


> if we add $ into selectors I believe we lose one of the few remaining characters and, again - from my other thread and make it more cryptic - it's yet another kind of magic looking looking. šWhy invent wholly new looking solutions when there are at least 2 very good ones on the table.

Using `$` for variables with functional notation to retrieve value has multiple benefits.

1. `$` does not explicitly mention variables (avoiding explicit mentioning of variables was the main reason for this thread to appear in the first place).

2. Functional notation `$()` for retrieving a variable value makes it possible in future to use a variable value in property names too, not just in property values.

3. Using `$` for both declaring and retrieving a variable is consistent and intuitive (the same `$` as prefix for declaring and as function for retrieving).

4. Syntax looks familiar -- `$` is used as prefix for variables in many languages including popular CSS preprocessors like SASS. (Regardless of whether some of us wants this or not, what we now call custom properties are actually still variables -- just with cascading and inheritance that are basic features of CSS itself and make quite natural and clear difference compared with other languages).

5. `$` is clearly isolated to use for variables. Using `--` to declare a variable, we still should use some function with some name to retrieve it.

    * `--` is fine as a prefix, but not as a standalone function name like `--()`.
    * `var()` does explicitly mention variable which is considered undesirable by spec authors and the author of this thread.
    * `prop()` looks universal while its possible artificial limitation to retrieve solely `--`-prefixed properties for now may be somewhat confusing for web developers (or may at least be _considered_ confusing by spec authors). Moreover, repeating `--` before variable name (prop(--foo)) when retrieving it would probably be redundant and unneeded compared with `$(foo)`.
    * `custom()` is too uncertain (custom what?), while `custom-property()` would probably be too long for usable everyday use.
    * `my()` looks too unofficial-ish, etc.

6. Using `$` for something _different_ from variables (e.g. for mixins) in future (and _reserving_ `$` for such purposes for now) may be confusing and harmful given that `$` is the long-standing familiar indicator of a variable in many languages.

Received on Tuesday, 18 March 2014 17:12:41 UTC