Live data from Hacker News

Svelte is a language

gist.github.com

61–70 of 95 posts

Re: Svelte is a language

#61
post #57

Earlier quoted context omitted.

I don’t follow… in what sense is this JavaScript? Specifically, what is on:click? It doesn’t look like JavaScript, and it doesn’t look like the DOM. It looks like a new language which is specific to Svelte. Or what about this… is this JavaScript? $: doubled = count * 2; Or… {#if user.loggedIn} Log out {/if} Or… Click me I am willing to believe that all of that is ergonomic in some way, but it doesn’t appear to me at…

> I don’t follow… in what sense is this JavaScript? > it's not. it's html. incrementCount is a pointer to a javascript function. > Or what about this… is this JavaScript? > $: doubled = count * 2; Yes. $: is a javascript label. We use it to indicate that a function should be reactive - if the count variable changes, the right hand will be rerun and double updated. > Click me html again. the |once is a modifier to cli…

> which the compiler picks up

I think this is the crux of the gp's question. The browser doesn't support explicit behaviours for "on:click" or "|once" (the "$" label is a cool trick I'd forgive the gp for not recognising as native JS) - it may be "valid" HTML but it's not "just HTML" (nor just JS), it's a DSL.

Re: Svelte is a language

#62
post #15

The really exciting thing about svelte is getting rid of the virtual Dom. Having everything just be explicit JavaScript code that modifies the Dom manually makes for really readable code. If you have not tried it, got to the svelte tutorial and look at the output code. It's awesome.

First we were excited for the virtual DOM which is good for batching updates, flexibility, efficiency, etc. But now the cool thing is to get rid of it?

Never been excited in the least by it. Being too clever imho. Problem is: I don’t often get to dictate what we use so there I am, caught in the web.

Re: Svelte is a language

#63

> Svelte is a language. All Javascript frameworks may become implementations of SAT solvers, where rendering and state are scheduled constraints, i.e. tiny operating systems. NPM uses CSS as a query language - https://news.ycombinator.com/item?id=33136843 - 9 months ago Then apps may be instantiations of the framework.

They should be SAT solvers, but people also want them to be vague and super flexible. Many people I know responded to Apple UI constraints (what was the name again?) with ‘what am I, a math professor?’. People want throw poop against a wall and smear it around and when they are happy with their work, they want to press a button and get the absolute optimal result that fits their broadest use case.

No different from what most non-frontend developers want by the way.

Problem is; that is not yet possible at all, because ‘the spec’ is too vague and strictness generated from vagueness will either be just vagueness (cannot find any constraints to throw into a solver so just leave it) or too strict (where many cases simply are suddenly forbidden that were actually feasible cases by the author).

Re: Svelte is a language

#64
post #52

Earlier quoted context omitted.

https://angular.io/guide/binding-overview Haven't looked at angular since 2015 to be honest, but it still seems like they do weird html stuff to me, such as: {{customer.name}} or Type something: {{customerInput.value}}

I agree with you, it looks weird, but my point was that it's correct HTML syntax, even though you cannot expect it to work if you open an Angular template in a browser, but an HTML parser can tell you it's syntactically correct.

Oh, that makes sense, I get you now.

Re: Svelte is a language

#65
post #57

Earlier quoted context omitted.

I don’t follow… in what sense is this JavaScript? Specifically, what is on:click? It doesn’t look like JavaScript, and it doesn’t look like the DOM. It looks like a new language which is specific to Svelte. Or what about this… is this JavaScript? $: doubled = count * 2; Or… {#if user.loggedIn} Log out {/if} Or… Click me I am willing to believe that all of that is ergonomic in some way, but it doesn’t appear to me at…

> I don’t follow… in what sense is this JavaScript? > it's not. it's html. incrementCount is a pointer to a javascript function. > Or what about this… is this JavaScript? > $: doubled = count * 2; Yes. $: is a javascript label. We use it to indicate that a function should be reactive - if the count variable changes, the right hand will be rerun and double updated. > Click me html again. the |once is a modifier to cli…

While this is all technically true, I don't think it's all that helpful a thought process to have when approaching Svelte. Yes, Svelte files are syntactically valid HTML, Javascript, etc, but they have very different semantics.

Take the ability to reference functions in HTML - this is simply not possible in normal HTML, where inline event handlers instead are passed Javascript expressions to evaluate. It's definitely a useful feature, but it's very clearly outside of the normal realm of HTML.

This goes further with Javascript: here the semantics differ considerably, with labels in normal Javascript doing nothing except when dealing with loops, and labels in Svelte are a form of reactivity. You've also got things like dollar signs interacting with stores, and other semantic differences.

As Rich Harris says, Svelte is a language.

Re: Svelte is a language

#66
post #52

Earlier quoted context omitted.

https://angular.io/guide/binding-overview Haven't looked at angular since 2015 to be honest, but it still seems like they do weird html stuff to me, such as: {{customer.name}} or Type something: {{customerInput.value}}

I agree with you, it looks weird, but my point was that it's correct HTML syntax, even though you cannot expect it to work if you open an Angular template in a browser, but an HTML parser can tell you it's syntactically correct.

This is true of Svelte's syntax as well, is it not?

Re: Svelte is a language

#67
post #8
post #5

Earlier quoted context omitted.

Or maybe one day people will realize render functions explicitly listening to event emitters is actually a better pattern than implicit reactivity.

Certainly I've had a lot of fun with wiring mobx up to various things that provide render functions (react with mobx viewstate classes is way nicer than hooks to me). Svelte I've never quite got the hang of to the point where I feel comfortable expressing an opinion about it (and I haven't spent enough time experimenting to claim my not having got the hang of it yet means anything either).

Mobx as your ViewModel/Model selector implementation is precisely where it belongs in your stack. You just need to be disciplined and not build your whole state/update loop on it. Sadly, I'm stuck on v4.5.x at work, and my big complaint is arrays not being a first-class observable.

Re: Svelte is a language

#68
post #48

Earlier quoted context omitted.

Because React is JS and Svelte isn't

React is JSX* Nothing preventing them from making an … … component

And this is typically how conditionals work in SolidJS, which also uses JSX but adds extra core components to handle conditionals and iteration. In fairness, this is largely because they can better support the reactivity model that SolidJS uses, but it's a convenient side effect.

Re: Svelte is a language

#69
post #60

Svelte Kit is great for static is "classic"-like websites. I've converted my company website to svelte-kit from first Angular, then Vue. But for SPA it's bad. If you use oidc auth. There's only Auth.JS and it's a confidential client, for Svelte Kit. If you're not using svelte-kit you can use vite to create a Svelte SPA. There you can use your PCKE client as usual and burden the load on the client. I have yet to exper…

SevelteKit has some rough corners. The debugging is not as smooth especially because these frontend frameworks needlessly insists on being server side framework first for no reason specifically because server side frameworks have very strong, battle tested options ranging from Django, Flask, echo, Rails, sinatra and what not.

This makes tooling complicated and a debugging that works out of the box for both server and client side is non existent even in SvelteKit 4.

When I'm picking up SvelteKit, it's only for its routing which isn't so great either with file based arrangements, things get out of and pretty fast.

Re: Svelte is a language

#70

If you want a good language that turns into Javascript I recommend PureScript

I did a stint of Elm and it taught me a lot. But I found I prefer dirtier languages like elixir and typescript. I would not recommend the pure languages for anything other than learning FP.
Post reply on HN