diff --git a/site/content/blog/2016-11-26-frameworks-without-the-framework.md b/site/content/blog/2016-11-26-frameworks-without-the-framework.md index 9c663a01ba..933b0fbc48 100644 --- a/site/content/blog/2016-11-26-frameworks-without-the-framework.md +++ b/site/content/blog/2016-11-26-frameworks-without-the-framework.md @@ -1,7 +1,6 @@ --- title: Frameworks without the framework: why didn't we think of this sooner? description: You can't write serious applications in vanilla JavaScript without hitting a complexity wall. But a compiler can do it for you. -pubdate: 2016-11-26 author: Rich Harris authorURL: https://twitter.com/Rich_Harris --- diff --git a/site/content/blog/2017-08-07-the-easiest-way-to-get-started.md b/site/content/blog/2017-08-07-the-easiest-way-to-get-started.md index 4dec8e66fb..b29c3cb5c2 100644 --- a/site/content/blog/2017-08-07-the-easiest-way-to-get-started.md +++ b/site/content/blog/2017-08-07-the-easiest-way-to-get-started.md @@ -1,7 +1,6 @@ --- title: The easiest way to get started with Svelte description: This'll only take a minute. -pubdate: 2017-08-07 author: Rich Harris authorURL: https://twitter.com/Rich_Harris --- diff --git a/site/content/blog/2017-09-06-the-zen-of-just-writing-css.md b/site/content/blog/2017-09-06-the-zen-of-just-writing-css.md index c89935c104..4ea56bc633 100644 --- a/site/content/blog/2017-09-06-the-zen-of-just-writing-css.md +++ b/site/content/blog/2017-09-06-the-zen-of-just-writing-css.md @@ -1,7 +1,6 @@ --- title: The zen of Just Writing CSS description: I would say this is the future, but we're already doing it. -pubdate: 2017-09-06 author: Rich Harris authorURL: https://twitter.com/Rich_Harris --- diff --git a/site/content/blog/2017-12-31-sapper-towards-the-ideal-web-app-framework.md b/site/content/blog/2017-12-31-sapper-towards-the-ideal-web-app-framework.md index 614f266136..ff986a2258 100644 --- a/site/content/blog/2017-12-31-sapper-towards-the-ideal-web-app-framework.md +++ b/site/content/blog/2017-12-31-sapper-towards-the-ideal-web-app-framework.md @@ -1,7 +1,6 @@ --- title: Sapper: Towards the ideal web app framework description: Taking the next-plus-one step -pubdate: 2017-12-31 author: Rich Harris authorURL: https://twitter.com/Rich_Harris --- diff --git a/site/content/blog/2018-04-18-version-2.md b/site/content/blog/2018-04-18-version-2.md index 295efbbd11..7e5441f090 100644 --- a/site/content/blog/2018-04-18-version-2.md +++ b/site/content/blog/2018-04-18-version-2.md @@ -1,7 +1,6 @@ --- title: Svelte v2 is out! description: Here's what you need to know -pubdate: 2018-04-18 author: Rich Harris authorURL: https://twitter.com/Rich_Harris --- diff --git a/site/content/blog/2018-12-26-svelte-css-in-js.md b/site/content/blog/2018-12-26-svelte-css-in-js.md index 40bbfe8bd1..5e8e6ed71b 100644 --- a/site/content/blog/2018-12-26-svelte-css-in-js.md +++ b/site/content/blog/2018-12-26-svelte-css-in-js.md @@ -1,7 +1,6 @@ --- title: Using CSS-in-JS with Svelte description: You don't need to, but you can -pubdate: 2018-12-26 author: Rich Harris authorURL: https://twitter.com/Rich_Harris --- @@ -17,11 +16,13 @@ But Svelte's style handling does have some limitations. It's too difficult to sh Here, we're using [Emotion](https://emotion.sh) to generate scoped class names that can be used across multiple components: - +
+ +
It's important to note that most CSS-in-JS libraries have a runtime library, and many don't support statically extracting styles out into a separate .css file at build time (which is essential for the best performance). You should therefore only use CSS-in-JS if it's necessary for your application! diff --git a/site/content/blog/2018-12-27-virtual-dom-is-pure-overhead.md b/site/content/blog/2018-12-27-virtual-dom-is-pure-overhead.md index f70bda43d5..d71652fe8d 100644 --- a/site/content/blog/2018-12-27-virtual-dom-is-pure-overhead.md +++ b/site/content/blog/2018-12-27-virtual-dom-is-pure-overhead.md @@ -1,7 +1,6 @@ --- title: Virtual DOM is pure overhead description: Let's retire the 'virtual DOM is fast' myth once and for all -pubdate: 2018-12-27 author: Rich Harris authorURL: https://twitter.com/Rich_Harris --- diff --git a/site/content/blog/2019-01-31-svelte-on-the-changelog.md b/site/content/blog/2019-01-31-svelte-on-the-changelog.md index 79ad985bf9..936c50240e 100644 --- a/site/content/blog/2019-01-31-svelte-on-the-changelog.md +++ b/site/content/blog/2019-01-31-svelte-on-the-changelog.md @@ -1,7 +1,6 @@ --- title: Svelte on The Changelog description: Listen to the interview here -pubdate: 2019-01-31 author: Rich Harris authorURL: https://twitter.com/Rich_Harris --- diff --git a/site/content/blog/2019-04-15-setting-up-your-editor.md b/site/content/blog/2019-04-15-setting-up-your-editor.md new file mode 100644 index 0000000000..c157682e44 --- /dev/null +++ b/site/content/blog/2019-04-15-setting-up-your-editor.md @@ -0,0 +1,13 @@ +--- +title: Setting up your editor +description: Instructions for configuring linting and syntax highlighting +author: Rich Harris +authorURL: https://twitter.com/Rich_Harris +draft: true +--- + +*Coming soon* This post will walk you through setting up your editor so that recognises Svelte files: + +* eslint-plugin-svelte3 +* svelte-vscode +* associating .svelte files with HTML in VSCode, Sublime, Atom, etc etc etc \ No newline at end of file diff --git a/site/content/blog/2019-04-16-svelte-for-new-developers.md b/site/content/blog/2019-04-16-svelte-for-new-developers.md new file mode 100644 index 0000000000..54d5a2b7ce --- /dev/null +++ b/site/content/blog/2019-04-16-svelte-for-new-developers.md @@ -0,0 +1,9 @@ +--- +title: Svelte for new developers +description: Never used Node.js or the command line? No problem +author: Rich Harris +authorURL: https://twitter.com/Rich_Harris +draft: true +--- + +*Coming soon* This blog post will walk you through installing Node.js and git and using Terminal.app to clone a project template and start developing with Svelte \ No newline at end of file diff --git a/site/content/blog/2019-04-20-write-less-code.md b/site/content/blog/2019-04-20-write-less-code.md new file mode 100644 index 0000000000..226909259c --- /dev/null +++ b/site/content/blog/2019-04-20-write-less-code.md @@ -0,0 +1,165 @@ +--- +title: Write less code +description: The most important metric you're not paying attention to +author: Rich Harris +authorURL: https://twitter.com/Rich_Harris +draft: true +--- + +All code is buggy. It stands to reason, therefore, that the more code you have to write the buggier your apps will be. + +Writing more code also takes more time, leaving less time for other things like optimisation, nice-to-have features, or being outdoors instead of hunched over a laptop. + +In fact it's widely acknowledged that [project development time](https://blog.codinghorror.com/diseconomies-of-scale-and-lines-of-code/) and [bug count](https://www.mayerdan.com/ruby/2012/11/11/bugs-per-line-of-code-ratio) grow *quadratically*, not linearly, with the size of a codebase. That tracks with our intuitions: a ten-line pull request will get a level of scrutiny rarely applied to a 100-line one. And once a given module becomes too big to fit on a single screen, the cognitive effort required to understand it increases significantly. We compensate by refactoring and adding comments — activities that almost always result in *more* code. It's a vicious cycle. + +Yet while we obsess — rightly! — over performance numbers, bundle size and anything else we can measure, we rarely pay attention to the amount of code we're writing. + + +## Readability is important + +I'm certainly not claiming that we should use clever tricks to scrunch our code into the most compact form possible at the expense of readability. Nor am I claiming that reducing *lines* of code is necessarily a worthwhile goal, since it encourages turning readable code like this... + +```js +for (let i = 0; i <= 100; i += 1) { + if (i % 2 === 0) { + console.log(`${i} is even`); + } +} +``` + +...into something much harder to parse: + +```js +for (let i = 0; i <= 100; i += 1) if (i % 2 === 0) console.log(`${i} is even`); +``` + +Instead, I'm claiming that we should favour languages and patterns that allow us to naturally write less code. + + +## Yes, I'm talking about Svelte + +Reducing the amount of code you have to write is an explicit goal of Svelte. To illustrate, let's look at a very simple component implemented in React, Vue and Svelte. First, the Svelte version: + +
+ +
+ +How would we build this in React? It would probably look something like this: + +```js +import React, { useState } from 'react'; + +export default () => { + const [a, setA] = useState(1); + const [b, setB] = useState(2); + + function handleInputA(event) { + setA(+event.target.value); + } + + function handleInputB(event) { + setB(+event.target.value); + } + + return ( +
+ + + +

{a} + {b} = {a + b}

+
+ ); +}; +``` + +Here's an equivalent component in Vue: + +```html + + + +``` + + + +In other words, it takes 442 characters in React, and 263 characters in Vue, to achieve something that takes 145 characters in Svelte. The React version is literally three times larger! + +It's unusual for the difference to be *quite* so obvious — in my experience, a React component is typically around 40% larger than its Svelte equivalent. Let's look at the features of Svelte's design that enable you to express ideas more concisely: + + +### Top-level elements + +In Svelte, a component can have as many top-level elements as you like. In React and Vue, a component must have a single top-level element — in React's case, trying to return two top-level elements from a component function would result in syntactically invalid code. (You can use a fragment — `<>` — instead of a `
`, but it's the same basic idea). + +In Vue, your markup must be wrapped in a `