<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Tom Jackson</title>
    <description>The latest articles on DEV Community by Tom Jackson (@tom0901).</description>
    <link>https://dev.to/tom0901</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F420549%2F61f79f9d-0e91-4bd2-9b7a-00b5963cecc2.jpeg</url>
      <title>DEV Community: Tom Jackson</title>
      <link>https://dev.to/tom0901</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tom0901"/>
    <language>en</language>
    <item>
      <title>Why SvelteScript Is a Good Thing For The Future of The Web</title>
      <dc:creator>Tom Jackson</dc:creator>
      <pubDate>Sat, 02 Jul 2022 16:31:00 +0000</pubDate>
      <link>https://dev.to/tom0901/why-sveltescript-is-a-good-thing-for-the-future-of-the-web-2j96</link>
      <guid>https://dev.to/tom0901/why-sveltescript-is-a-good-thing-for-the-future-of-the-web-2j96</guid>
      <description>&lt;p&gt;Evan You, the creator of Vue, made this observation about Svelte's &lt;a href="https://svelte.dev/docs#component-format-script-3-$-marks-a-statement-as-reactive" rel="noopener noreferrer"&gt;labelled statements&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-1057291776724271104-940" src="https://platform.twitter.com/embed/Tweet.html?id=1057291776724271104"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-1057291776724271104-940');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=1057291776724271104&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;The idea here being that moving beyond the constraints of JavaScript, via the Svelte compiler, makes Svelte its own language. Evan isn't wrong and Svelte themselves aren't shy about admitting that this is the &lt;a href="https://gist.github.com/Rich-Harris/0f910048478c2a6505d1c32185b61934" rel="noopener noreferrer"&gt;case&lt;/a&gt;. &lt;/p&gt;

&lt;p&gt;Typically, the front-end community hasn't responded well to frameworks or languages that treat the Web as a compile target or try to replace it's core languages: HTML, CSS and JavaScript. &lt;a href="https://www.sitepoint.com/google-dart-fail/" rel="noopener noreferrer"&gt;Dart&lt;/a&gt; is a great example of this. Languages that seek to replace those core languages often have the following problems: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;They increases the risk of adoption because we are now writing a language that isn't as ubiquitous and as universally supported as JavaScript&lt;/li&gt;
&lt;li&gt;They potentially exclude the use of existing JavaScript tooling or impose some complex boiler plate to get that tooling.&lt;/li&gt;
&lt;li&gt;They increase the distance between the code that runs in the browser and what we actually write&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, Svelte doesn't completely discard the languages of the Web like Dart does - it extends them. It also does this in a way that safeguards against most of the risks outlined and allows Svelte to deliver great features like the aforementioned labelled statement&lt;/p&gt;

&lt;p&gt;Rich Harris, unsurprisingly, does a better job of explaining how Svelte extends the core languages of the Web &lt;a href="https://gist.github.com/Rich-Harris/0f910048478c2a6505d1c32185b61934#thinking-inside-the-box:~:text=Thinking%20inside%20the%20box" rel="noopener noreferrer"&gt;here&lt;/a&gt; and we can summarise this by paraphrasing the following three points: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It extends HTML by adding JavaScript expressions in markup, directives for controlling behaviour and reacting to input, syntax for using conditions, loops and asynchronous values&lt;/li&gt;
&lt;li&gt;It extends CSS by adding a scoping mechanism that keeps styles from clobbering each other&lt;/li&gt;
&lt;li&gt;It extends JavaScript by making reactivity a language primitive&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;As a community, we've become accustomed to the first two but the third is still a controversial topic because of those criticisms outlined above. It's important though, not to ignore the developments made in the 2010s to JavaScript frameworks. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;React Isn't Just JavaScript Anymore&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The community can largely agree that building modern complex apps with vanilla JavaScript isn't a great idea. I for one am glad that I no longer write code like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;btn&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;button&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; 
      &lt;span class="nx"&gt;btnText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createTextNode&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;increment&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;),&lt;/span&gt; 
      &lt;span class="nx"&gt;counterDisplay&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;div&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt; 

&lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 

&lt;span class="nx"&gt;btn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;btnText&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;counterDisplay&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;  
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;btn&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nb"&gt;window&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;body&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;counterDisplay&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

&lt;span class="nx"&gt;btn&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;addEventListener&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;click&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt;&lt;span class="o"&gt;=&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;counter&lt;/span&gt; &lt;span class="o"&gt;++&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; 
  &lt;span class="nx"&gt;counterDisplay&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;counter&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Doing the same thing with any modern framework is hugely different and that is a good thing. Take React for example:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;React&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;useState&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;react&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;function&lt;/span&gt; &lt;span class="nf"&gt;Example&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="c1"&gt;// Declare a new state variable, which we'll call "count"&lt;/span&gt;
  &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;useState&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;0&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;

  &lt;span class="k"&gt;return &lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;You clicked &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; times&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;p&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
      &lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;onClick&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nf"&gt;setCount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
        Click me
      &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;div&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;There is no denying that this code is a huge departure from the vanilla JavaScript example. The community has already shifted away from writing just JavaScript, because JavaScript isn't sufficient to write complex UIs. All frameworks play fast and loose with JavaScript in some way. React has hooks, Vue has getter setters and Svelte has labelled statements. Everyone is bending the rules of JavaScript to get reactive behaviour. &lt;/p&gt;

&lt;p&gt;Svelte is different though, because it's a compiler, it can do things that by definition are not possible with &lt;a href="https://www.ecma-international.org/publications-and-standards/standards/ecma-262/" rel="noopener noreferrer"&gt;ECMA-262&lt;/a&gt; like changing the semantics of existing unused syntax. This is the source of Svelte's biggest criticisms but also its greatest advantage over frameworks that do adhere to ECMA-262. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;How Does Svelte Address These Criticisms?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Svelte is very targeted about where it departs from Web standards and only does so if there are some real gains to be made. Like in the case of &lt;a href="https://svelte.dev/tutorial/reactive-declarations" rel="noopener noreferrer"&gt;labelled statements&lt;/a&gt; and &lt;a href="https://svelte.dev/tutorial/auto-subscriptions" rel="noopener noreferrer"&gt;stores&lt;/a&gt;. These deviations are localised to individual Svelte modules to further mitigate the risk of adoption. There's no demand for complex boiler plate to interop with JavaScript. Svelte has carefully extended Javascript in such a way that it can still make use of the existing tooling and continue its development without departing significantly from existing Web technologies. &lt;/p&gt;

&lt;p&gt;There is one criticism that remains valid though, and it's highlighted very well in this talk by &lt;a href="https://youtu.be/ft5bYnt0W48?t=3258" rel="noopener noreferrer"&gt;Kyle Simpson&lt;/a&gt;. By treating the Web as a compile target, we unavoidably increase the distance between the code in our IDE and what is actually running. We make it harder for anyone looking at our source code to actually work out what's going on. This isn't just a problem for Svelte though, realistically this is a sacrifice we make with all front-end frameworks. &lt;/p&gt;

&lt;p&gt;I find it quite telling that the descriptions for &lt;a href="https://chrome.google.com/webstore/detail/react-developer-tools/fmkadmapgofadopljbjfkapdkoienihi?hl=en" rel="noopener noreferrer"&gt;React Dev Tools&lt;/a&gt; and &lt;a href="https://chrome.google.com/webstore/detail/svelte-devtools/ckolcbmkjpjmangdbmnkpjigpkddpogn" rel="noopener noreferrer"&gt;Svelte Dev Tools&lt;/a&gt; are almost exactly the same. They are both tools for inspecting the component hierarchies in the browser. They are both trying to take the muddled, hard to understand, imperative code you'll see when you view page source and brings it closer to the declarative code we write in our IDEs. &lt;/p&gt;

&lt;p&gt;Svelte, being a compiler, has come under more criticism than it's competitors in this area but that doesn't follow. Yes, the code we serve the browser is very distant to what we are actually writing but that is as true of React as it is of Svelte. &lt;/p&gt;

&lt;p&gt;To summarise, Svelte, like all front-end frameworks, does increase the distance between the code we write and the code we serve to the browser. However, because the deviations from JavaScript are targeted and carefully implemented, Svelte doesn't discard the years of accumulated knowledge and tooling the Web's community has gained. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So What Are The Advantages of SvelteScript?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The core advantage of Svelte being a language is that it allows developers to write code like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&gt;&lt;code&gt;&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    let count = 0;

    function handleClick() &lt;span class="si"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;+=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;script&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="p"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt; &lt;span class="na"&gt;on&lt;/span&gt;&lt;span class="err"&gt;:&lt;/span&gt;&lt;span class="na"&gt;click&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;handleClick&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
    Clicked &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt; &lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nx"&gt;count&lt;/span&gt; &lt;span class="o"&gt;===&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt; &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;time&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;times&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="nt"&gt;button&lt;/span&gt;&lt;span class="p"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The difference between this and the earlier JavaScript example is huge. Svelte fundamentally changes how accessible your code is, how easy it is to maintain, and how easy it is to reason about. &lt;/p&gt;

&lt;p&gt;This is a huge advantage, but the freedom departing from JavaScript allows the Svelte team is its greatest asset.&lt;/p&gt;

&lt;p&gt;It's time to face facts, JavaScript needs help to continue being the language of the Web. Increasingly, there are things we as developers want to do on the Web that aren't possible with just JavaScript. The widespread adoption of Typescript has taught us that languages that compile to JavaScript and target the Web platform can solve these issues.  &lt;/p&gt;

&lt;p&gt;Compilers inherently have an edge over frameworks that operate strictly within ECMA-262 because they allow the teams developing them more freedom to add the features we as developers need to build modern apps. &lt;/p&gt;

&lt;p&gt;Svelte is uniquely positioned to shape the future of the Web precisely because it is a language, not a framework. The JavaScript community isn't just developers who work on the Web and changes that make sense for the Web platform don't always make sense for JavaScript. We, as a community, need to be able to adapt the core languages of the Web without being constrained by the larger community and we need to be able to make those adaptations without discarding the significant progress JavaScript has made over the last 27 years. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Does Your JS Spark Joy? Svelte and the Future of the Web</title>
      <dc:creator>Tom Jackson</dc:creator>
      <pubDate>Thu, 02 Jun 2022 14:01:32 +0000</pubDate>
      <link>https://dev.to/tom0901/does-your-js-spark-joy-svelte-and-the-future-of-the-web-5c9c</link>
      <guid>https://dev.to/tom0901/does-your-js-spark-joy-svelte-and-the-future-of-the-web-5c9c</guid>
      <description>&lt;p&gt;At You &lt;a href="https://www.youtube.com/watch?v=AdNJ3fydeao&amp;amp;t=7s" rel="noopener noreferrer"&gt;Gotta Love Frontend 2019&lt;/a&gt; Rich Harris posed a simple question to the audience: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does your JS spark joy?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw4s1bi7nywlc1xcjv3ey.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fw4s1bi7nywlc1xcjv3ey.png" alt="Marie Kondo"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The idea here was to demonstrate that writing less code is the only true way to improve performance by a meaningful margin. &lt;/p&gt;

&lt;p&gt;I think we can take the question a step further though. In fact, applying the laser focussed minimalism of Marie Kondo to your code base is a neat way of summarising the core benefits of Svelte and gives you a good idea of how it's changing the web. &lt;/p&gt;

&lt;p&gt;So, I'm going to begin and summarise this article by posing two questions to you. &lt;/p&gt;

&lt;p&gt;However, before we begin, I think it's important to give a brief overview of the framework and its crucial differences from other component-based frameworks like React. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So what is Svelte?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Svelte is a compiler that does the job of a component-based framework. It takes your .svelte files and converts them into HTML, CSS and JS. Effectively moving the complexity of the framework to the build step so the runtime is smooth. &lt;/p&gt;

&lt;p&gt;By comparison, traditional frameworks like React famously have expensive runtimes. &lt;/p&gt;

&lt;p&gt;With Svelte your browser gets what it was built to run immediately; HTML, CSS and JS. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkbar96la3wvvlw946tr2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkbar96la3wvvlw946tr2.png" alt="svelte"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this point, you might be asking how we achieve reactive state-driven apps this way. This is a valid question, but Svelte has a good answer. Unlike React with Svelte, you're not reliant on the Virtual DOM and expensive DOM diffing to manage and update your application's state. With Svelte the DOM tree is manipulated directly when state changes and, through some clever quirks of the compiler, this is achieved very efficiently by a single bundled JS file. &lt;/p&gt;

&lt;p&gt;So, the TLDR is: Svelte leverages the familiar concept of moving our framework's runtime away from the client by compiling your declarative component-based code to imperative instructions the browser understands at build time. &lt;/p&gt;

&lt;p&gt;All right, let's move on to those questions! Ultimately, as front-end developers, I think we should ask ourselves two questions. &lt;/p&gt;

&lt;p&gt;Does our JS spark joy in us as developers? &lt;/p&gt;

&lt;p&gt;Does our JS spark joy in our users? &lt;/p&gt;

&lt;p&gt;If the answer to either of those questions is no, like Marie Kondo, we should thank it, then discard it. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Section 1&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does your JS spark joy in you as a developer?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Does it allow you to write simple maintainable declarative code? &lt;/p&gt;

&lt;p&gt;Traditional component-based frameworks were created so you, the developer, could write neat understandable declarative code and avoid the hefty imperative implementation that's required to get the browser to actually do what you want.&lt;/p&gt;

&lt;p&gt;With React, the trade-off for having this nice dev experience is an expensive runtime on the client. &lt;/p&gt;

&lt;p&gt;However, with Svelte, because it's a compiler, the bundle size of Svelte itself isn't important - it's the output of that compiler that is actually being run. This has freed up the Svelte team to develop a remarkable developer experience.&lt;/p&gt;

&lt;p&gt;Here are some of my favorite code examples that highlight Svelte's great developer experience.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Svelte's skinny syntax&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;React was a huge step forward, abstracting the imperative JS that actually manipulates the DOM into a much simpler format, but React also introduces a lot of boilerplate to hide that complexity behind its hooks. &lt;/p&gt;

&lt;p&gt;Here's how you'd implement a simple form in React:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import React, { useState } from 'react';

export default () =&amp;gt; {
    const [a, setA] = useState(1);
    const [b, setB] = useState(2);

    function handleChangeA(event) {
        setA(+event.target.value);
    }

    function handleChangeB(event) {
        setB(+event.target.value);
    }

    return (
        &amp;lt;div&amp;gt;
            &amp;lt;input type="number" value={a} onChange={handleChangeA}/&amp;gt;
            &amp;lt;input type="number" value={b} onChange={handleChangeB}/&amp;gt;

            &amp;lt;p&amp;gt;{a} + {b} = {a + b}&amp;lt;/p&amp;gt;
        &amp;lt;/div&amp;gt;
    );
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here's the equivalent code in Svelte:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;
    let a = 1;
    let b = 2;
&amp;lt;/script&amp;gt;

&amp;lt;input type="number" bind:value={a}&amp;gt;
&amp;lt;input type="number" bind:value={b}&amp;gt;

&amp;lt;p&amp;gt;{a} + {b} = {a + b}&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Svelte removes so much of that boilerplate leaving us with more readable maintainable code that is much more accessible to non-technical colleagues.  &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Svelte provides a better CSS experience&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The basis of modern front-end frameworks is JS. When you write in React you are primarily working with JS but your browser serves HTML. This results in a subpar CSS experience for the React dev. &lt;/p&gt;

&lt;p&gt;We all want CSS files that are scoped to our components and many of us want the HTML, CSS and JS that drive our component to live in one file. There are many solutions for achieving this with React but the downside of all of them is that they rely on installing extra dependencies and learning extra syntax to get this behavior. &lt;/p&gt;

&lt;p&gt;With Svelte, because .svelte files are a superset of HTML we can simply include all of our HTML, CSS and JS in one file and the Svelte compiler will add unique hashes to our CSS classes to ensure they are scoped to their components. Here's what that looks like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;script&amp;gt;
    alert('Hello world!')
&amp;lt;/script&amp;gt;

&amp;lt;style&amp;gt;
    h1{
        color: red;
    }
&amp;lt;/style&amp;gt;

&amp;lt;h1&amp;gt;Hello world!&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to add global CSS, don't worry Svelte has you covered with the &lt;code&gt;:global(...)&lt;/code&gt; modifier:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;style&amp;gt;
    :global(body) {
        /* this will apply to &amp;lt;body&amp;gt; */
        margin: 0;
    }

    div :global(strong) {
        /* this will apply to all &amp;lt;strong&amp;gt; elements, in any
             component, that are inside &amp;lt;div&amp;gt; elements belonging
             to this component */
        color: goldenrod;
    }

    p:global(.red) {
        /* this will apply to all &amp;lt;p&amp;gt; elements belonging to this 
             component with a class of red, even if class="red" does
             not initially appear in the markup, and is instead 
             added at runtime. This is useful when the class 
             of the element is dynamically applied, for instance 
             when updating the element's classList property directly. */
    }
&amp;lt;/style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Svelte is truly reactive&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;For your program to be reactive, the dynamic variables within it have to be defined when you declare them. &lt;/p&gt;

&lt;p&gt;The front-end community has been striving for an efficient way to write reactive code for a long time now and the solution we've settled on is the virtual DOM. &lt;/p&gt;

&lt;p&gt;The virtual DOM is essentially a lightweight snapshot of your app's DOM structure. In React, every time your state changes that snapshot is compared to the previous one, and the real DOM is only changed where they differ. &lt;/p&gt;

&lt;p&gt;This is a huge progression from previous frameworks that would rewrite large portions of the DOM tree just to make small changes. There is a 'but' here though. If we know ahead of runtime which variables depend on one another, we can change only what is necessary when our state changes without any comparisons. This is what Svelte does, the virtual DOM isn't fast it's merely faster than rewriting the whole tree. Direct DOM manipulation, if it is precise, has always been faster than the virtual DOM approach.&lt;/p&gt;

&lt;p&gt;Svelte allows us to be explicit about which variables are dependent on one another. It allows us to create an app that knows which variables to update, the order to update them and is faster at updating them than it's competitors. &lt;/p&gt;

&lt;p&gt;In order to understand how Svelte gets this behavior let's look at some examples lifted from &lt;a href="https://paulstovell.com/reactive-programming/" rel="noopener noreferrer"&gt;Paul Stovel&lt;/a&gt; via &lt;a href="https://youtu.be/AdNJ3fydeao?t=863" rel="noopener noreferrer"&gt;Rich Harris&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;var a = 10;
var b = a + 1;
a = 11;
b = a + 1;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we can see that getting &lt;code&gt;b&lt;/code&gt; to depend on &lt;code&gt;a&lt;/code&gt; is clunky to say the least. It requires that any time we change &lt;code&gt;a&lt;/code&gt; we also have to reassign &lt;code&gt;b&lt;/code&gt;. As a solution to this problem, Paul Stovel proposed the theoretical destiny operator:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;
var a = 10;
var b &amp;lt;= a + 1;
a = 20;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In this example, the &lt;code&gt;&amp;lt;=&lt;/code&gt; binds the value of &lt;code&gt;b&lt;/code&gt; to &lt;code&gt;a&lt;/code&gt;. Unfortunately, this syntax doesn't exist in JS but, Svelte, being a compiler, is less constrained by the limitations of JS than other frameworks. &lt;/p&gt;

&lt;p&gt;Svelte has leveraged this, to convert the labeled statement, a fairly unused piece of syntax, into the theoretical destiny operator.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let a = 10;
$: b = a * 2; 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's that simple - &lt;code&gt;b&lt;/code&gt; is now bound to the value of &lt;code&gt;a&lt;/code&gt;. Whenever &lt;code&gt;a&lt;/code&gt; changes &lt;code&gt;b&lt;/code&gt; will update. All the boilerplate React demands you write to get the equivalent behavior is gone. Yes, obviously there is still a lot of complexity hidden by the compiler but it's not forcing that boilerplate on you. What the client runs is efficient vanilla JS that directly manipulates only those parts of the DOM you have explicitly declared will change when your state does. &lt;/p&gt;

&lt;p&gt;Essentially, because Svelte is a compiler, it has been able to drastically improve upon the front-end dev experience and this isn't just my opinion - Svelte was voted most loved Framework in the Stack Overflow 2021 developer survey. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Section 2&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Does your JS spark joy in your users?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Does it help you deliver performant apps with great UX without compromising your developer experience? &lt;/p&gt;

&lt;p&gt;The obvious benefit of Svelte being a compiler is that the bundle size the browser is served is significantly smaller. Svelte, according to this &lt;a href="https://svelte.dev/blog/frameworks-without-the-framework" rel="noopener noreferrer"&gt;article&lt;/a&gt;, is 10 times smaller than React and ReactDOM when zipped. Not only is Svelte a lot easier for the browser to run, but once it's up and running it's faster too because it doesn't rely on virtual DOM diffing. That all translates to faster load times for your user and an app that is interactive more quickly.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdi35gpn2n6s1h8lpdvfz.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdi35gpn2n6s1h8lpdvfz.png" alt="Google page experience update"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Last year's &lt;a href="https://developers.google.com/search/docs/advanced/experience/page-experience" rel="noopener noreferrer"&gt;Google page experience update&lt;/a&gt; taught us that performance is the new SEO. It signaled the beginning of a new trend where UX is the most important factor in your app's search ranking. This major overhaul coupled with the increased traffic from low-performance devices has created an environment where Svelte really shines. Svelte, unlike React and Vue, can still offer great performance on low-performance devices like smart watches, payment terminals and smart TVs. &lt;/p&gt;

&lt;p&gt;As developers, we have become obsessed with shipping one solution that works across all devices. We've ditched closely coupled legacy CMSs for shiny, headless offerings that can drive our content on all devices. &lt;/p&gt;

&lt;p&gt;Why not take the same attitude with our front-end framework? React and Vue simply aren't options that will result in a responsive UX on a payment terminal. In this environment, Svelte is the only framework that is efficient enough, ultimately allowing you as a developer to work on a single tech stack that serves the range of devices that access the internet in 2022.  &lt;/p&gt;

&lt;p&gt;This brings us full circle, back to the original point Rich Harris was making at &lt;a href="https://www.youtube.com/watch?v=AdNJ3fydeao&amp;amp;t=7s" rel="noopener noreferrer"&gt;You Gotta Love Front End 2019&lt;/a&gt;. The only true way to increase the performance of our apps is to reduce their size. The only true way to give our users an excellent experience is to reduce the amount of JavaScript we are serving their device. Our two goals of having happy users and happy developers are both served by reducing the amount of code we write and ship. &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Thank it, then discard it&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Svelte means slender or elegant and the name is apt. The core benefits of Svelte all stem from the fact that it is a compiler and that that compilers output is, well, svelte. This allows us to do away with expensive run times in the browser, removes the constraints of needing our code to be read by the browser and it achieves all this without compromising on the developer experience. &lt;/p&gt;

&lt;p&gt;The mantra of the first major JS framework JQuery was: &lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Write less, do more&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Svelte, like JQuery in the Noughties is empowering developers to write more efficient minimal code that is accessible to more devices, users and developers. So, if your JS doesn't spark joy - thank it, then discard it. &lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
