-
Notifications
You must be signed in to change notification settings - Fork 82
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
Proposal for significant changes to syntax for V4 #45
Conversation
You use string templates as an example here but curly braces are used for far more than that in JavaScript. They're most commonly used to define a scope of some description, not a template literal, and modifying things outside of the current scope is a common pattern. There is nothing bad about it. I think the attribute suggestions are particularly problematic, but even if they weren't, I'm struggling to see the value in any of these changes. This just looks like change for it's own sake, if anything the suggested syntax is even more esoteric than the existing syntax which is at least inspired by handlebars (it was never intended to be compatible with HTML, Svelte has had its own template parser forever). This just looks like a personal preference for different syntax, it would cause significant disruption for relatively little value. |
The syntax is inherited from templating engines, and this is referring to string templates, which I think is an obvious and apt comparison. However, even with blocks - yes, they do define a scope, but only inbetween the braces. But, at least to me, I don't think of
It seems almost every time a change is suggested it is pushed back because of inconsistencies with HTML spec. And Svelte absolutely WAS intended to at least be vaguely parsed by HTML tooling - the
I disagree that this is of "little value", how often have you heard developers incessantly complain about how JS syntax is awful? Syntax, especially the feeling of it and how it flows as you read it, is very important. |
All valid HTML should work in Svelte but I don't know that we've ever tried to maintain compatibility with HTML in the template, that boat sailed a long time ago. We do want to maintain compatibility with JS tooling inside the script block and CSS tooling inside the style block though. Where possible we will take the approach that is most compatible with existing tooling if all else is equal (including the HTML).
Then please explain the value. I'm not seeing any convincing arguments outside of the fact that you think it is better. But any significant overhaul of syntax doesn't just need to be slightly better but needs to also be worth the upheaval it will cause. It is a pretty high bar. |
The reason curly braces around attribute expressions are a 'good idea' is because we subscribe to the view that explicit is better than implicit. Curly braces make it very easy for the reader to work out whether or not something is a plain attribute or attribute expression, even if technically they aren't always necessary. |
I feel like this is somehow about me when I didn't intend for this to be my personal demands. This is quite literally the repo for making controversial suggestions.
Regardless, I'll focus on attributes, which I do agree probably has the least value out of the three proposed changes. My argument for it is that Svelte is already so dynamic that making such an explicit divide between the dynamic 'script' bits of Svelte and the static HTML bits of Svelte is counterproductive. For example, in components, explicitly having to type curly brackets for props you know can't even accept a string feels strange to me. However, I think most importantly, and I think I got this across in the RFC, is that you can already represent plain attributes with Svelte expressions near identically already. It feels bizarre to separate the two when HTML is only ever going to accept a string anyways - if it's a string, it's a string, and you can see it. If it's not a string, well it must be something else then. Pug does this already, and I don't think anyone is confused by that. |
And whoever makes those suggestions needs to try to communicate the advantage of the change. You have suggested some alternatives but I don't really see any benefits.
Then there would be a significant disparity between passing props and passing attributes. I don't think that would be beneficial outside of saving a few characters. You read code far more than you write it, so optimising for write-ability is a mistake. Making attribute and prop expressions easy scannable without need to know all of the context is beneficial.
We do not wish to take design tips from Pug. |
They're syntax changes. The advantages of the change depend upon literally your personal opinion as there isn't anything technical to talk about here. This is your opinion, and that's absolutely fine - I'm sorry if I can't convince you of why I prefer this.
I personally find it easier to read cleaner, less symbol-ridden code. Many people prefer Python for just this reason alone, and that's a perfectly fine reason. Additionally, syntax highlighters are pretty much everywhere - almost always strings and other types will be highlighted differently.
I think you missed the point, it wasn't a design tip, just a real-world example. I am not suggesting you go make Svelte pythonic or something. |
I will add that I have finally found where I read that Rich had put forward the idea of updated control flow. It has been discussed and proposed before - and mentions a lot of ideas that I already talked about. Perhaps it is fruitless to suggest an update to control flow considering this previous discussion, but time has passed, and it should be at least talked about again. |
I generally think syntax changes are not worth it due to the backwards compatibility issues they cause. Unless it enables new functionality or addresses a significant confusion demonstrated over a prolonged period of time by a large number of users, the pain it causes is not worth it to our users who would need to update all their code. |
It's also a no vote from me I'm afraid. I don't like any of the new syntax proposals, I actively dislike all of them in fact. Thanks for taking the time to create this RFC however, absolutely the right way to go about it. |
Going through the proposed changes / areas of changes: Changing control flow syntaxFor me the " More terse props syntaxThis will make it harder to understand what's going on since the syntax is now ambiguous. Does Changing parameters for actions/transitions/etcWith more than three parameters this will become hard to read. You also may not know what these parameters are. Yes it's more to type, but easier to read for others. It would also close off the possibility to ever introduce some third parameter which is not used for parameters but something else. |
Thanks for this RFC, however I don't think we feel that these changes are right for Svelte. |
Rendered
Sorry for the unusual format of this RFC - I didn't feel that it was right for me to make an individual RFC for each of these changes, as I don't feel like they should be implemented individually. Of course, if it turns out that there is a desire to, any of these changes could be split out into their own RFC.
Please let this be a catalyst for discussion, I really want to see this furiously discussed as I think there is a lot to ponder here.