You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Sometimes I'd think that using the semicolon (;) as the argument delimiter would be syntactically more consistent. Think about it - using commas for delimiting both mixin arguments and parts of some particular style rules (background, box-shadow, etc., but most notably font-family) can be inconsistent/ambiguous at times, resulting in cases like this.
Semicolons, however, have always been used to signify the end of a style rule (and also the end of a variable value in LESS), so it fits pretty well in the role of delimiting arguments. As a bonus, this even makes it possible to give default argument values that contain commas (for a trivial example .otherfont (@face: Helvetica, Arial; @size: 13px) { font-family: @face; font-size: @size; }). This is really not that unintuitive.
If you wrap your head around it, this could prove the best solution - if not for the fact that it might break existing code. To solve this problem, some sort of compilation configuration flags could be set to determine whether ',' or ';' would be used as argument delimiters, with the former being the default.
I think you make a good point for semicolons—The problem is more to do with what people are used to, when passing arguments to a function, in any other language. I'll see what I can do, in terms of supporting both styles. In the end, the syntax which allows the most flexibility, ie semicolons should win.
I do think supporting both semi-colons and commas is actually a decent compromise, because semi-colons are not accidental insertions (not inserted into a mixin statement for any other reason that I can think of).
The logic could be as follows:
Both commas and semi-colons are argument delimeters, unless...
If both are present, treat only semi-colons as an argument delimeter
This would allow all existing LESS code to function exactly the same, and extend the ability to separate arguments that may have commas without resorting to string escaping. I think this is a good suggestion, and deals more elegantly with the problem that CSS presents, that the "value" of a property (and thus a variable) can have white space and commas already.
UPDATE: One more argument in support of this: the English language. Lists have commas unless the object listed contains a list, in which case the list is separated by semi-colons. So @Wyverald has a good example, but I'm against forcing a compilation flag. We can easily do it automatically and intuitively by allowing a dev to choose semi-colons instead of commas for any given mixin.
One revision. My previous solution won't work (EDIT: Maybe, as there are possibly other ways to indicate a "switch" to semi-colons). If there's only one argument, that algorithm wouldn't be able to detect if the comma was intended as part of the argument or a second argument.
SASS handles this more elegantly and intuitively. The syntax uses parentheses.
Each argument can be wrapped in parentheses to indicate the entire sequence is one argument, and each set of parentheses can then separated by commas, like this:
Coming back to this, this does get a little complicated to use now that parentheses is being used to indicate math operations. Don't know if that will make this too complicated or we can still make the parser smart enough.
Now, was the author's intent to specify a valid elliptical radius as simply the first (and only) argument? Or was their intent to do math division? How is the parser supposed to know?
I want LESS to be completely backwards-compatible, but in truth, if I had to make this choice before LESS was in widespread use, I probably would have advocated instead for semi-colon separators, as it's much cleaner and clearer, doesn't conflict with CSS, is easier to understand, and doesn't give a possible unexpected result like the above example. But I hate breaking things, so I'm torn.
@arguments-list - hack and incomplete
comma-seperated(@arguments) - hacky
parenthesis means keep "," literal - not so obvious in some situations
change to ";" for seperating args - cleanest but breaking change
Right, I get you. In case of a conflict between parentheses for specifying arguments and parentheses for math, we do math (but only if what's inside the parentheses is a valid math equation).
If you want to override this behavior (for this extreme edge case), you use string escaping.
My example is a bit of a red herring anyway, since it doesn't make sense that an author would arbitrarily be using a single set of parentheses for arguments.
Further to issue #146, here is a not-so-edge case with what I believe should be the intended behavior:
/* Example - Test A */.mymixin(@font,@borderRadius){
font:@font;border:1px solid red;
border-radius:@borderRadius;}.myclass{.mymixin(( 14px/1.4 Georgia,serif), 10px / 2px );}/* Expected output - Test A */.myclass{font:14px/1.4 Georgia, serif;/* parentheses were not around a valid equation, so don't do math */border:1px solid red;border-radius:10px/2px;/* no inner parentheses, so don't do math */}/* Forced division - Test B */.myclass{.mymixin(((14px/1.4) Georgia,serif),(10px / 2px));}/* Expected output - Test B */.myclass{font:10px Georgia, serif;/* the valid equation was directly encapsulated by parentheses, meaning an intended math operation */border:1px solid red;border-radius:5px;/* it's possibly an argument, but math wins */}/* Overriding when math/argument is ambiguous - Test C */.myclass{.mymixin(((14px/1.4) Georgia,serif),(~"10px / 2px"));}/* Expected output - Test C */.myclass{font:10px Georgia, serif;/* same as Test B */border:1px solid red;border-radius:10px/2px;/* rejected as a math operation, so the parentheses are an argument delimiter */}
@agatronic Yes, we would change the documentation to favor semi-colons. But the GOOD part is that commas can still be accepted in legacy libraries without a problem.
What about using square or curly braces instead of parentheses to indicate a list?
Alternatively, if you went with parentheses, you could prefix it with a character to indicate the list. For example, *(a, b). This avoids any confusion between math and lists and it also bears a resemblance to string escaping with ~"...".
@R1ch0 curly brackets - we have enough of them, square brackets already discussed and I think discounted because they aren't in the flavour of declarative css..
add *( to parenthesis I think looks even more confusing (this vs "5 * (3 / 2)")
Just a note. Even though I called @arguments-list a hack, what I meant is that it didn't reach the underlying problem, and still left some problems unsolved and on the table.
Having said that, even though @arguments-list shouldn't be necessary with some fixes to argument separation, it doesn't mean it couldn't exist. In CSS, there's multiple ways to solve the same problem, and I'm fine with both solutions: a proper way to separate arguments, and a keyword for a comma-separated list. Are they mutually exclusive ideas?
-1 for curly or square brackets, for the same reasons @agatronic mentioned. I'm now leaning more heavily towards a backwards-compatible semi-colon syntax.
@agatronic Yeah I see that I picked a really bad example with *. But my point was simply that it could be prefixed with any character to indicate a list instead of math. Preferably a character that isn't used for other things! Oops.
I don't really have an opinion either way on this matter but if you use semicolons, wouldn't that mean it's not possible to assign a list to a variable? I know there's not really a need to do this since commas would work there, but it would create a small caveat that should be documented.
Semi-colons would only be allowed as delimiters of parameters in a parametric mixin definition or call.
And I'm on board with this, I still think it's the cleanest solution. The only other things I came up with were pipes as dilimeters (and or wrappers), and I still don't think I like that very much.
@R1ch0 Your example does not make sense. Even if you could declare a variable like that, which you can't, you would never be able to use it in LESS, since you can't just plop a variable onto it's own line. So....
@dmcass Thanks for the additional input. Yeah, I think we can really make this low impact. I like where this is headed. Who would like to start working on a PR request for this? ;-)
Have almost finished - found 2 bugs with named arguments when writing unit tests so had to fix those too. Will put a pull request soon. Not completely sure on the syntax because the mix of , and ; doesn't exactly look completely explanatory.. but will send a pull and you can take a look.
Activity
cloudhead commentedon Jun 2, 2010
hmm, the correct behaviour is the 2nd one though,
,is the argument delimiter.dylan commentedon Jun 2, 2010
So how would you recommend passing several (n number) arguments to box-shadow for css3?
jamesfoster commentedon Jun 2, 2010
I'd recommend using variables:
i don't think we can support passing values with commas. I also don't like the idea of escaping the comma with
\,or,,another (ugly) way to do it would be to pass the value as a "string" and unquote it inside the mixin using
e(@x).I'd say the first case is a bug. it should pass 2 arguments
cloudhead commentedon Jun 18, 2010
what he said.
Wyverald commentedon Dec 6, 2010
Sometimes I'd think that using the semicolon (;) as the argument delimiter would be syntactically more consistent. Think about it - using commas for delimiting both mixin arguments and parts of some particular style rules (background, box-shadow, etc., but most notably font-family) can be inconsistent/ambiguous at times, resulting in cases like this.
Semicolons, however, have always been used to signify the end of a style rule (and also the end of a variable value in LESS), so it fits pretty well in the role of delimiting arguments. As a bonus, this even makes it possible to give default argument values that contain commas (for a trivial example
.otherfont (@face: Helvetica, Arial; @size: 13px) { font-family: @face; font-size: @size; }). This is really not that unintuitive.If you wrap your head around it, this could prove the best solution - if not for the fact that it might break existing code. To solve this problem, some sort of compilation configuration flags could be set to determine whether ',' or ';' would be used as argument delimiters, with the former being the default.
cloudhead commentedon Dec 6, 2010
I think you make a good point for semicolons—The problem is more to do with what people are used to, when passing arguments to a function, in any other language. I'll see what I can do, in terms of supporting both styles. In the end, the syntax which allows the most flexibility, ie semicolons should win.
fabiosantoscode commentedon Jun 5, 2012
less is just treating the values after the comma as a second argument.
matthew-dean commentedon Jul 18, 2012
About this:
Sending a comma separated value to a single variable can be done like this:
.box-shadow(~"0 2px 5px rgba(0, 0, 0, 0.125), 0 2px 10px rgba(0, 0, 0, 0.25)");I do think supporting both semi-colons and commas is actually a decent compromise, because semi-colons are not accidental insertions (not inserted into a mixin statement for any other reason that I can think of).
The logic could be as follows:
This would allow all existing LESS code to function exactly the same, and extend the ability to separate arguments that may have commas without resorting to string escaping. I think this is a good suggestion, and deals more elegantly with the problem that CSS presents, that the "value" of a property (and thus a variable) can have white space and commas already.
UPDATE: One more argument in support of this: the English language. Lists have commas unless the object listed contains a list, in which case the list is separated by semi-colons. So @Wyverald has a good example, but I'm against forcing a compilation flag. We can easily do it automatically and intuitively by allowing a dev to choose semi-colons instead of commas for any given mixin.
fabiosantoscode commentedon Jul 18, 2012
+1. Reminds me of javascript strings. Use "" or '', whatever fits your needs.
matthew-dean commentedon Jul 25, 2012
One revision. My previous solution won't work (EDIT: Maybe, as there are possibly other ways to indicate a "switch" to semi-colons). If there's only one argument, that algorithm wouldn't be able to detect if the comma was intended as part of the argument or a second argument.
SASS handles this more elegantly and intuitively. The syntax uses parentheses.
The syntax would be like this:
.box-shadow( ( 0 2px 5px #FFF , 0 2px 10px #000 ) );Each argument can be wrapped in parentheses to indicate the entire sequence is one argument, and each set of parentheses can then separated by commas, like this:
LESS is already using parentheses to optionally wrap expressions, so it doesn't introduce any new syntax and follows convention.
matthew-dean commentedon Sep 5, 2012
Coming back to this, this does get a little complicated to use now that parentheses is being used to indicate math operations. Don't know if that will make this too complicated or we can still make the parser smart enough.
For example:
Now, was the author's intent to specify a valid elliptical radius as simply the first (and only) argument? Or was their intent to do math division? How is the parser supposed to know?
I want LESS to be completely backwards-compatible, but in truth, if I had to make this choice before LESS was in widespread use, I probably would have advocated instead for semi-colon separators, as it's much cleaner and clearer, doesn't conflict with CSS, is easier to understand, and doesn't give a possible unexpected result like the above example. But I hate breaking things, so I'm torn.
Food for thought. Would love to hear more input.
lukeapage commentedon Sep 5, 2012
I would phrase the concern as one for consistancy.. e.g.
is that obvious? I think the parser could handle these two differently easy enough, but would it be obvious what is going to happen?
lukeapage commentedon Sep 5, 2012
In summary
@arguments-list - hack and incomplete
comma-seperated(@arguments) - hacky
parenthesis means keep "," literal - not so obvious in some situations
change to ";" for seperating args - cleanest but breaking change
? @cloudhead any thoughts?
matthew-dean commentedon Sep 5, 2012
Right, I get you. In case of a conflict between parentheses for specifying arguments and parentheses for math, we do math (but only if what's inside the parentheses is a valid math equation).
If you want to override this behavior (for this extreme edge case), you use string escaping.
My example is a bit of a red herring anyway, since it doesn't make sense that an author would arbitrarily be using a single set of parentheses for arguments.
Further to issue #146, here is a not-so-edge case with what I believe should be the intended behavior:
lukeapage commentedon Sep 5, 2012
I agree that this is how I would expect it to work if this is what we decide to do.
Sorry - another point.
parenthesis means breaking change for the consumer of the mixin. arguments-list/comma-seperated mean a optional change for the author of the mixin.
12 remaining items
matthew-dean commentedon Sep 5, 2012
@agatronic Yes, we would change the documentation to favor semi-colons. But the GOOD part is that commas can still be accepted in legacy libraries without a problem.
richardp-au commentedon Sep 5, 2012
What about using square or curly braces instead of parentheses to indicate a list?
Alternatively, if you went with parentheses, you could prefix it with a character to indicate the list. For example,
*(a, b). This avoids any confusion between math and lists and it also bears a resemblance to string escaping with~"...".Just trying to throw out some other ideas. :)
lukeapage commentedon Sep 5, 2012
@R1ch0 curly brackets - we have enough of them, square brackets already discussed and I think discounted because they aren't in the flavour of declarative css..
add *( to parenthesis I think looks even more confusing (this vs "5 * (3 / 2)")
I think arguments-list and ; are my favourites
matthew-dean commentedon Sep 5, 2012
Just a note. Even though I called @arguments-list a hack, what I meant is that it didn't reach the underlying problem, and still left some problems unsolved and on the table.
Having said that, even though @arguments-list shouldn't be necessary with some fixes to argument separation, it doesn't mean it couldn't exist. In CSS, there's multiple ways to solve the same problem, and I'm fine with both solutions: a proper way to separate arguments, and a keyword for a comma-separated list. Are they mutually exclusive ideas?
-1 for curly or square brackets, for the same reasons @agatronic mentioned. I'm now leaning more heavily towards a backwards-compatible semi-colon syntax.
richardp-au commentedon Sep 5, 2012
@agatronic Yeah I see that I picked a really bad example with
*. But my point was simply that it could be prefixed with any character to indicate a list instead of math. Preferably a character that isn't used for other things! Oops.I don't really have an opinion either way on this matter but if you use semicolons, wouldn't that mean it's not possible to assign a list to a variable? I know there's not really a need to do this since commas would work there, but it would create a small caveat that should be documented.
matthew-dean commentedon Sep 6, 2012
No, if you used semi-colons, it should still be perfectly possible to assign a list to a variable. Maybe I need to document it further.
richardp-au commentedon Sep 6, 2012
@MatthewDL If I rewrite your example A above with a variable, would it still work?
lukeapage commentedon Sep 6, 2012
It would not be possible to do this.. its not possible today right? Do we
need it? I hope not...
richardp-au commentedon Sep 6, 2012
I can't see why you'd need or want that. I'm just saying that it should be clearly documented where semicolons are and aren't supported.
dmcass commentedon Sep 6, 2012
Semi-colons would only be allowed as delimiters of parameters in a parametric mixin definition or call.
And I'm on board with this, I still think it's the cleanest solution. The only other things I came up with were pipes as dilimeters (and or wrappers), and I still don't think I like that very much.
matthew-dean commentedon Sep 6, 2012
@R1ch0 Your example does not make sense. Even if you could declare a variable like that, which you can't, you would never be able to use it in LESS, since you can't just plop a variable onto it's own line. So....
@dmcass Thanks for the additional input. Yeah, I think we can really make this low impact. I like where this is headed. Who would like to start working on a PR request for this? ;-)
lukeapage commentedon Sep 6, 2012
I may have a go later afternoon - I have two flights and an idea on how to do it..
lukeapage commentedon Sep 7, 2012
Have almost finished - found 2 bugs with named arguments when writing unit tests so had to fix those too. Will put a pull request soon. Not completely sure on the syntax because the mix of , and ; doesn't exactly look completely explanatory.. but will send a pull and you can take a look.
lukeapage commentedon Oct 29, 2012
semi-colon seperators is checked into the master branch.