Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Scope and the order of declarations/definitions. #110

Closed
seven-phases-max opened this issue Feb 12, 2014 · 5 comments
Closed

Scope and the order of declarations/definitions. #110

seven-phases-max opened this issue Feb 12, 2014 · 5 comments

Comments

@seven-phases-max
Copy link
Member

(I linked to the "Scope" section from 1868, read it and...)
It states:

Note that the order of declaration does matter.

This is misleading. The order of declarations does not matter actually . E.g. the following two examples are equal:
(A):

@var: red;

#page {
  @var: white;
  #header {
    color: @var; // white
  }
}

(B):

@var: red;

#page {
  #header {
    color: @var; // white
  }
  @var: white;
}

Not counting a few language dark corner cases and issues similar to those mentioned in 1399 where the order of definition is indeed important (usually just involving some recursive (re)definitions and cycling dependencies)).


I decided to create this ticket first just in case someone has any/other ideas for improving/rewording this docs section.

@seven-phases-max
Copy link
Member Author

Also not counting that in case of "re-definition" the last declaration wins (so in that context the order would matter), but this is somewhat beyond the scope of the "Scope" section.

@matthew-dean
Copy link
Member

It does matter. What this means is that it matters within a scope.

@seven-phases-max
Copy link
Member Author

Aha, so I was a bit hurrying t close this.

What this means is that it matters within a scope.

That makes sense. Though the way it was originally written (stressed does right before the example) it really was confusing (making an illusion that the colour is white because of the variable definition order and not because of the scope visibility).

Assuming that section is just an introductory section of the language overview (so we don't probably want to bring all those "last declaration wins" details there with tons of ifs and whens, e.g. "for the scopes themselves the order does not matter" vs. "within a single scope the standard 'last definition of the variable is used' rule applies") - How about changing current:

Note that the order of declarations does not matter so the following Less code is identical to the previous example...

to something more neutral like:

Variables and mixins do not have to be declared before being used so the following Less code is identical to the previous example...

?

(I.e. not mentioning any "order" stuff at all since this is described later in "Lazy Loading" linked with "See also")

@lukeapage
Copy link
Member

Sounds better to me

@seven-phases-max
Copy link
Member Author

Closing as fixed in the docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants