-
Notifications
You must be signed in to change notification settings - Fork 63
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
Choose / Switch syntax instead of ElseIf and Else #26
Comments
My opinion: the choose block or something with those semantics is the best choice for else/if... I don't really like how the first one works with else/if, it's a bit messy. Just as long as we can preserve backwards compatibility with the current syntax and add this as another way of expressing it. |
I'm really not sure how to go about this API. IMO and at first glance the cleanest choice would be to only support On the one hand
On the other hand we would introduce two idioms which solve the same thing. So the cons are:
In any case, let's start a discussion. We shouldn't rush this. |
Trying to pull in some people and their opinions: @justafish @helarqjsc @vitalybe (who opened the issue about elseif) and @jimfb (who appears to watch over this lib) |
Some research. Currently we're using Handlebars style syntax, although Handlebars doesn't support elseIf (if I'm not mistaken):
JSP (or JSTL to be more precise) has to handle this differently, because it's based on XML:
So depending on the background, different approaches have been taken. String based template languages like Handlebars implement what any developer would expect, while XML based templating languages need to adhere to correct nesting rules, which forces them to use the choose stlye. JSX tries to emualte XML, so it fits the second category. However, since it transpiles to JS it is not confronted with the same restrictions. My current thinking is to support both styles, knowing how cumbersome the choose style is. |
"choose" syntax looks good to me and I love the fact it makes indentation logical again. To make sure, the idea is that if one condition is true, the others wouldn't execute even if their condition would also resolve truthfully? E.g, this:
Would only generate a single |
Sure, it should and will behave as JS behaves. In any case it's going to be transformed into a nested / chained ternary operator. For your example: Are you also comfortable with Thanks for your feedback. |
The "choose" syntax is fine. Better option than switch. On Wed, Jan 13, 2016, 21:28 texttechne notifications@github.com wrote:
|
I'm finding myself preferring the |
See #32 for the better syntax. |
Considering the nesting of
<ElseIf>
and<Else>
they're just markers and cannot be indented automatically by IDE's. Correct indentation would look like this:So what about a choose statement (JSP style):
Or (misusing) switch style:
Maybe we should reserve the use of the switch statement instead of "abusing" the syntax. On the other hand we could also allow for an optional parameter for
switch
which allows exactly that, e.g.expression
.In any case I would tend to make
otherwise / default
optional, so that users are not forced to switch between if/else and switch syntax. Implementation-wise we would simply make use of the ternary operator. @AlexGilleran what do you think?The text was updated successfully, but these errors were encountered: