React VS Svelte - Which one should you choose in 2024? ft Rich Harris

Prismic
26 Jul 202426:04

Summary

TLDRIn this insightful discussion, Rich Harris, the creator of Svelte, compares Svelte's compiled approach with React's runtime methodology. Harris argues that Svelte's design offers advantages in UI development due to JavaScript's unsuitability for describing user interfaces. He acknowledges React's robust ecosystem and advanced data handling but asserts Svelte's simplicity and performance as key benefits. The conversation also touches on the philosophical differences between the frameworks and the potential of Svelte 5 to address advanced programming needs while maintaining ease of use.

Takeaways

  • 🤔 Rich Harris, creator of Svelte, has written enough React to be familiar with it but hasn't built substantial applications with it.
  • 🔍 Svelte is a compiled language, whereas React is a runtime language, giving Svelte a design advantage in UI development.
  • 👎 Harris argues that JavaScript is not a good language for describing user interfaces, unlike HTML which is, once interactivity is added.
  • 🛠️ Svelte has to develop its own tooling, like a type checker, which is an overhead compared to other frameworks.
  • 🌐 React's recent updates, like React 19's experimental compiler, show a trend towards pre-runtime compilation in web development.
  • 📈 The adoption of compiled languages in web development is not inevitable, as seen with Elm or Mint, due to the familiarity gap and learning curve.
  • 👌 Svelte avoids the learning curve by being similar to HTML, allowing developers to use their existing skills.
  • 📱 Harris suggests that Svelte might allow for an application with no JavaScript, emphasizing its templating capabilities.
  • 🔄 React's ability to write code that runs directly in the browser without build steps is a niche advantage, but not commonly used.
  • 🌟 React has a strong ecosystem and job market, which are significant advantages for developers choosing to learn and use it.
  • 💡 Svelte's focus on simplicity and performance for common UI tasks makes it an attractive choice for developers looking for a streamlined framework.

Q & A

  • What is the main difference between Svelte and React as described by Rich Harris?

    -Svelte is a compiled language, while React is a runtime language. Svelte has the advantage of a larger space to search for solutions to problems as it doesn't have to fit everything into JavaScript, which Rich Harris argues is not fundamentally well-designed for UI development.

  • Why does Rich Harris believe JavaScript is not ideal for describing user interfaces?

    -Rich Harris thinks JavaScript is not a good language for UI development because it is event-driven, and UIs are better described in a state-driven manner. HTML is great for static UIs, and the gap to make it interactive is smaller compared to adapting JavaScript for the same purpose.

  • What does Rich Harris think about the adoption of compiled languages in web development?

    -Rich Harris doesn't see it as inevitable that compiled languages will overtake runtime languages. He mentions that despite the advantages, there's a familiarity gap as people are reluctant to learn new languages, which has limited the adoption of languages like Elm or Mint.

  • How does Rich Harris view the role of compilers in web development frameworks?

    -Rich Harris sees compilers as a positive development in web frameworks, noting that doing more work before the application runs improves the user experience. He mentions that React 19 now has a compiler, indicating a trend towards compilers in the industry.

  • What are some of the advantages of using React over Svelte according to Rich Harris?

    -Rich Harris acknowledges that React has a large ecosystem, a wide range of available jobs for developers, and advanced capabilities for data handling and large applications. React's approach to colocating data with components is also seen as an advantage for managing asynchronous operations.

  • What does Rich Harris think about the learning curve for Svelte and React?

    -Rich Harris believes that Svelte might lead to a more idiomatic understanding of JavaScript because it doesn't introduce as many abstractions as React does with its hooks and component lifecycle. He suggests that React developers might be learning React-specific patterns rather than general JavaScript.

  • How does Rich Harris view the community and collaboration between different web development frameworks?

    -Rich Harris views the web development community as collaborative and respectful, with different frameworks occupying different niches and offering meaningful choices to developers based on their preferences and project needs.

  • What does Rich Harris think about the verbosity of React code compared to Svelte?

    -Rich Harris acknowledges that Svelte is focused on making common use cases simple and concise, while React code can be more verbose. He suggests that React's verbosity is due to its focus on composability and integration with the rest of the JavaScript ecosystem.

  • What are Rich Harris's thoughts on the future of Svelte, particularly with the introduction of Svelte 5?

    -Rich Harris is excited about Svelte 5, which aims to preserve the simplicity of Svelte while adding more power, flexibility, and composability. The new features are designed to address the limitations encountered when building larger applications with Svelte.

  • What would it take for Rich Harris to consider using React over Svelte?

    -Rich Harris would need to see React adopt features that are currently unique to Svelte, such as built-in support for transitions, animations, and styles as part of the component definition, and a shift in philosophy to be more encapsulated and focused on day-to-day UI problems.

Outlines

00:00

🤔 Introduction to React vs. Svelte Discussion

The conversation begins with the host introducing the topic of choosing between React and Svelte for web development. Rich Harris, the creator of Svelte, is invited to provide an unbiased comparison. Rich shares his experience with React, acknowledging his familiarity without having built substantial applications with it. The discussion then pivots to the differences between Svelte as a compiled language and React as a runtime language, with Rich suggesting that Svelte's approach offers a broader solution space but also comes with its own set of challenges, such as the need for additional tooling like a type checker.

05:04

🔍 Svelte's Advantages and the Role of Compilers

Rich discusses the advantages of Svelte's compiled nature, arguing that it allows for more efficient solutions due to the larger design space available before runtime. He critiques JavaScript's suitability for UI development, favoring HTML's static nature for describing interfaces. Rich also touches on the growing trend of frameworks adopting compilers, noting that React's recent addition of an experimental compiler indicates a move towards pre-runtime optimization. However, he tempers this by acknowledging that compiled languages like Svelte may not inevitably overtake runtime ones due to the familiarity gap and the resistance to learning new languages.

10:06

🛠️ The Philosophy Behind Svelte and React

The conversation delves into the philosophical differences between Svelte and React, with Rich emphasizing Svelte's focus on simplicity and directness, which contrasts with React's approach that involves more JavaScript intricacies. He suggests that Svelte's design avoids the need for external packages in many cases, promoting a more integrated and straightforward development experience. Rich also addresses the idea of 'deleteability', the concept of cleanly removing code without leaving unnecessary dependencies, which he sees as a challenge in large codebases that React has been addressing.

15:06

💼 React's Strengths in the Job Market and Ecosystem

Rich acknowledges React's dominance in the job market and its extensive ecosystem, which offers a vast array of pre-built solutions. He contrasts this with Svelte's approach, which often avoids the need for external packages by leveraging the platform's capabilities. The discussion highlights React's strengths in handling advanced data operations and its suitability for large-scale applications, areas where Svelte is currently less advanced. Rich also suggests that learning React can lead to a deeper understanding of JavaScript, contrary to the host's initial impression.

20:09

🧙‍♂️ The Magic of Svelte and the Abstractions of React

The dialogue explores the 'magic' of Svelte, where developers can write less code and achieve more with simpler syntax. Rich argues that Svelte's syntax is more intuitive and closer to idiomatic JavaScript, making it easier for developers familiar with web standards. He contrasts this with React's approach, which involves more verbose code and a style of programming that is distinct from traditional JavaScript. The conversation also touches on the challenges of understanding React's lifecycle and state management, which can be abstract and counterintuitive for developers.

25:09

🌟 The Future of Svelte and the Web Development Ecosystem

Rich discusses the future of Svelte, particularly the upcoming Svelte 5, which aims to maintain simplicity while providing more power and flexibility. He addresses the limitations of Svelte's current syntax and the need for a more robust system, particularly for advanced use cases. The conversation concludes with a reflection on the diversity of the web development ecosystem, where different frameworks cater to different needs and philosophies. Rich emphasizes the importance of choice and innovation, encouraging developers to select the framework that aligns best with their goals and preferences.

Mindmap

Keywords

💡React

React is a popular JavaScript library for building user interfaces, particularly for single-page applications. It allows developers to create reusable UI components and is known for its efficient update and rendering process. In the video, React is compared with Svelte, another framework for building web applications, highlighting differences in their approaches to UI development. The script mentions React's capabilities, such as managing asynchronous operations and server-side rendering, which are seen as advantages over Svelte.

💡Svelte

Svelte is a relatively new JavaScript framework that focuses on simplifying the process of building web applications. Unlike React, which uses a runtime approach, Svelte compiles components into efficient JavaScript at build time. This results in smaller, faster, and easier-to-manage code. The video discusses Svelte's advantages, such as its simplicity and performance, and how it compares to React, particularly in terms of the developer experience and the resulting application size.

💡Compiler

In the context of web development, a compiler is a program that translates code written in one language (the source language) into another language (the target language). The video script discusses how Svelte uses a compiler to convert components into optimized JavaScript code. This is contrasted with React, which traditionally has been a runtime framework but has introduced an experimental compiler in React 19. The use of compilers in web frameworks is seen as a way to improve performance by doing more work ahead of time.

💡Runtime

Runtime refers to the period when a program is being executed by a processor. In web development, a runtime framework like React manages the lifecycle of components and updates the DOM as needed. The script contrasts Svelte's compile-time approach with React's runtime approach, suggesting that Svelte's method can lead to more efficient code because it does not require the overhead of managing state and re-rendering at runtime.

💡HTML

HTML (HyperText Markup Language) is the standard markup language for creating web pages and web applications. It is used to structure content on the web. The video script mentions HTML in relation to Svelte, which is described as a superset of HTML, allowing developers to write interactive web applications using a syntax that is familiar and intuitive for those who already know HTML, CSS, and JavaScript.

💡JavaScript

JavaScript is a scripting language commonly used for web development, allowing for interactive web pages and implementing complex features on websites. The script discusses JavaScript's suitability for UI development, with the creator of Svelte arguing that it is not ideally designed for this purpose, unlike HTML. The conversation also touches on how JavaScript's event-driven nature contrasts with the state-driven nature typically desired in UI frameworks.

💡Component

In web development, a component refers to a reusable piece of a user interface. Components can contain HTML, CSS, and JavaScript, and can be used to build complex applications. The video script discusses components in the context of both React and Svelte, highlighting how each framework handles the creation and management of components differently, with React using a more traditional JavaScript approach and Svelte using a compile-time approach.

💡Hooks

Hooks are a feature in React that allows developers to use state and other React features in functional components. The script mentions hooks as part of the discussion on how React abstracts certain aspects of JavaScript, leading to a different programming style compared to traditional JavaScript. Hooks enable more complex state management and side effects in components, which contrasts with Svelte's approach where such patterns are handled differently.

💡Asynchronous Operations

Asynchronous operations refer to tasks in programming that are performed without blocking the execution of other tasks. In the context of the video, asynchronous operations are discussed as a strength of React, where it can manage data dependencies and handle asynchronous work across different components without manual coordination. This is contrasted with Svelte's approach, which is described as less capable in this area.

💡Ecosystem

In the context of web development, an ecosystem refers to the collection of tools, libraries, and community resources available for a particular framework or technology. The script mentions the React ecosystem as a significant advantage, with a vast array of pre-built solutions and packages available for developers. This contrasts with Svelte, which has a smaller ecosystem but is growing as its popularity increases.

💡Idiomatic JavaScript

Idiomatic JavaScript refers to writing code in a way that follows the conventions and best practices of the JavaScript language. The video script suggests that Svelte encourages more idiomatic JavaScript compared to React, which abstracts many of JavaScript's features through its own APIs and patterns. This can lead to a different learning curve and coding experience for developers, with Svelte potentially offering a more straightforward path for those already familiar with JavaScript.

Highlights

Rich Harris, creator of Svelte, discusses the advantages and disadvantages of Svelte and React.

Svelte is a compiled language, whereas React is a runtime language, offering different advantages.

JavaScript is not ideal for UI development, according to Harris, who favors HTML for static UIs.

Svelte's design allows for a larger solution space compared to React.

React's ecosystem and job market are significant advantages over Svelte.

React's recent adoption of a compiler in React 19 is noted as a trend towards pre-runtime optimization.

Svelte's simplicity and ease of learning are highlighted as advantages over React.

React's advanced data handling and large application management are recognized strengths.

Harris suggests that Svelte developers might have a more idiomatic understanding of JavaScript.

The philosophical differences between state-driven (Svelte) and event-driven (React) programming are explored.

Svelte's focus on pragmatism and quick expression of ideas is contrasted with React's composability.

Svelte 5 aims to address the limitations found in larger Svelte applications.

Harris envisions a future where different frameworks occupy distinct niches in the web development ecosystem.

The importance of having a choice between frameworks with different philosophies is emphasized.

Innovation in web development and the 'golden age' of frameworks are celebrated.

Harris humorously reflects on his appearance and influencer status at the end of the discussion.

Transcripts

play00:00

So, you're starting a

play00:01

new web development project

play00:01

and you need to decide if you

play00:03

want to use React or Svelte.

play00:05

Well, my guest today

play00:06

can give you a proper,

play00:07

unbiased evaluation of the two.

play00:09

I'm here with Rich

play00:09

Harris, creator of Svelte.

play00:10

Rich, thanks so much for joining me.

play00:12

- Thanks for having me.

play00:13

- So Rich, how much React have you

play00:15

written in your life?

play00:16

- Enough to be pretty

play00:18

familiar with how it works.

play00:19

I haven't built any substantial

play00:21

applications with React,

play00:22

but I am the guy that

play00:24

people will sometimes come to

play00:26

for help with their React code

play00:28

because as a framework author, you know,

play00:30

you got to study the enemy.

play00:34

- I'm glad we got that

play00:35

clip on camera, perfect.

play00:37

So, you know enough

play00:39

React to be dangerous.

play00:42

I have a question about this

play00:43

and it's following a

play00:44

little bit on a conversation

play00:45

you had with my

play00:46

colleague, Alex, a few months back.

play00:49

You guys were talking about how Svelte

play00:51

is a compiled language and

play00:53

React is a runtime language.

play00:55

I want to know, do you

play00:56

think that that gives Svelte

play00:57

kind of like an unfair advantage?

play01:00

- It gives us, the makers of Svelte,

play01:04

a bit of an advantage in that we have

play01:06

just a much larger space

play01:08

in which to search for

play01:08

solutions to problems

play01:10

because we're not trying

play01:11

to shoehorn everything into,

play01:12

you know, a language that I would argue

play01:15

is fundamentally badly designed

play01:16

for the task that we put it to.

play01:17

Like I don't think that

play01:18

JavaScript is a good language

play01:19

for describing user interfaces.

play01:22

And a rendering

play01:23

framework's job is essentially

play01:24

to try and bully JavaScript

play01:27

into being suitable for UI development.

play01:30

HTML on the other

play01:31

hand is a great language

play01:32

for describing user

play01:33

interfaces as long as they're static.

play01:35

And so for me, the gap between, you know,

play01:40

HTML and a good language

play01:41

for describing user interfaces

play01:44

is just adding some interactivity.

play01:45

Whereas the gap between JavaScript

play01:48

and a good language for

play01:49

user interfaces is much larger.

play01:51

So there are definite

play01:53

advantages from a design standpoint,

play01:56

but in other ways, it's

play01:58

definitely not an advantage.

play02:00

Like in terms of being

play02:02

able to use existing tooling

play02:03

and things like that,

play02:04

like most frameworks

play02:06

don't have to write

play02:07

their own type checker.

play02:09

Like we have to have

play02:10

this separate package

play02:11

for type checking

play02:12

inside Svelte components

play02:14

and things like that.

play02:15

So it swings around about,

play02:17

I think we made the right choice.

play02:20

You know, your mileage may vary.

play02:22

A lot of people just fundamentally don't

play02:24

want to touch anything

play02:25

that isn't JavaScript.

play02:27

And that's fine.

play02:30

But I would say it gives us an advantage,

play02:32

but certainly not an unfair one.

play02:34

And, you know, a lot of frameworks are

play02:37

adopting compilers themselves.

play02:39

Like last week, React 19 was announced,

play02:42

and it has a compiler.

play02:44

It's experimental for now,

play02:45

but React now has a compiler.

play02:47

Most frameworks have a compiler.

play02:48

And I think we're

play02:49

starting to see a broad agreement

play02:52

that the more work you can do

play02:55

before your application runs,

play02:57

the better it's going to be for users.

play03:00

And so there's, you know, different ideas

play03:03

about what a compiler means.

play03:05

Like one of Twitter's

play03:07

favorite topics to discuss

play03:08

is the exact meaning

play03:09

of the word "compiler."

play03:12

But it seems like everyone is kind of

play03:13

drifting in that direction.

play03:15

So, you know, while we

play03:16

are probably the framework

play03:17

that is most strongly

play03:18

associated with the idea of compilers,

play03:20

I don't think it gives us a leg up over

play03:24

everyone else anymore.

play03:26

But I hear what you're

play03:27

saying that React has a compiler,

play03:29

Vue has a compiler, but

play03:30

there's still languages

play03:31

that are fundamentally

play03:33

designed for runtime.

play03:36

Do you think it's

play03:36

inevitable that compile time,

play03:38

since increasingly all web, all code that

play03:42

we write for the web

play03:43

is compiled or

play03:44

transpiled or whatever inevitably,

play03:46

do you think it's

play03:47

inevitable that compiled languages,

play03:49

whether Svelte or

play03:49

some other up-and-comer,

play03:51

will eventually overtake languages that

play03:53

are designed for runtime?

play03:56

I wouldn't say inevitable, no.

play03:59

There have been more

play04:01

expansive attempts than Svelte

play04:03

to apply this line of thinking.

play04:04

I'm thinking of things

play04:05

like Elm or Mint is a language

play04:09

that is designed specifically for

play04:13

designing user interfaces.

play04:14

And, you know, candidly, these things

play04:16

haven't seen the adoption

play04:18

that they probably deserve,

play04:19

and a lot of that is

play04:20

because of this familiarity gap.

play04:23

People just don't want to

play04:24

have to learn any language.

play04:26

And I think Svelte has

play04:27

largely avoided that trap

play04:28

because it is very similar to HTML.

play04:30

In fact, we call

play04:31

ourselves a superset of HTML.

play04:34

And so if you know

play04:35

HTML, and if you know CSS,

play04:37

and you know

play04:37

JavaScript, then you know Svelte.

play04:39

You don't have to

play04:39

learn an additional thing.

play04:41

And so maybe someone will

play04:44

come along and prove me wrong,

play04:46

but I don't think that someone is going

play04:48

to design the ideal language

play04:52

for user interfaces

play04:53

and see adoption with it

play04:55

because people are too

play04:56

busy to learn new stuff.

play04:57

And in theory, you actually could write a

play04:59

Svelte app with no JavaScript.

play05:04

You could. I mean, it

play05:04

wouldn't do very much.

play05:06

But like you could just use it as a

play05:08

templating language like that.

play05:09

Yes, and you know, some people do.

play05:12

That's definitely possible.

play05:15

I think there are probably

play05:16

better languages for that.

play05:18

Like you may as well just

play05:19

write markdown at that point.

play05:22

Astro is a great example of a framework

play05:25

that has leaned very

play05:26

heavily in that direction.

play05:29

We are a little bit more focused on

play05:32

being able to create

play05:33

richly interactive applications.

play05:36

But yeah, absolutely.

play05:38

In theory, on the flip side, in theory,

play05:41

you can still write React code and send

play05:43

it directly to the browser.

play05:45

Do you think that for the for React to

play05:48

view that's still an advantage?

play05:50

That is an interesting

play05:51

question for React not so much.

play05:53

I mean, no one really

play05:54

writes react that way.

play05:55

It's sort of it's quote

play05:57

unquote possible, but no one does it.

play06:00

For view, it's a bit

play06:01

more of a realistic option.

play06:03

And in fact, a lot of

play06:05

views usage comes from people

play06:07

just dropping a script tag on their page

play06:09

and decorating some existing HTML.

play06:13

That's not where we want to be.

play06:15

Like we think that the

play06:17

best way to build applications

play06:18

is to have a tighter integration between

play06:20

the page and the things on the page.

play06:23

But it's a thing that the view community

play06:27

has got a lot of mileage out of.

play06:28

And I don't expect them to

play06:29

give that up anytime soon.

play06:32

And there are other

play06:34

projects with like a similar focus.

play06:36

Like Alpine is an example of that where

play06:38

rather than trying to own

play06:40

the application development, they're just

play06:43

like a thing that you add at the end.

play06:48

So yeah, that's great for them.

play06:49

It's not where we want to be.

play06:51

So you jokingly

play06:53

referred to React as the enemy.

play06:57

But like we all know that this is

play06:58

actually like a very

play06:59

collaborative cooperative space

play07:00

where there's like a lot of idea sharing

play07:01

and a lot of respect

play07:02

for the different players.

play07:05

And in that spirit, what do you generally

play07:08

tell people are the

play07:09

advantages of using React over Svelte?

play07:12

Yeah, I mean, they're

play07:13

actually not the enemy at all.

play07:15

We have boundless respect for the React

play07:17

team and the work that they do.

play07:21

Obviously, if you want to work in front

play07:24

end, then knowing

play07:26

React is a huge advantage.

play07:27

There are jobs available if you write

play07:29

Svelte, but there are jobs

play07:30

available if you write React.

play07:33

And so there's like just it's a thing

play07:36

that you need to know if you're going to

play07:37

be a front end developer today,

play07:38

then you need to at least have a passing

play07:40

familiarity with React.

play07:43

But you know, the framework has a lot of

play07:46

capabilities that we don't yet.

play07:51

You know, managing asynchronous

play07:53

operations in a coordinated fashion is

play07:55

something that Svelte

play07:56

isn't great at candidly.

play07:59

Our server side

play08:00

rendering is fully synchronous.

play08:02

So if you have some data that loads

play08:05

lazily, then that has to be

play08:07

outside the rendering process.

play08:09

Whereas in React, you can like capture

play08:12

your dependencies, your data dependencies

play08:14

as part of the component, which like

play08:18

you're talking about

play08:19

React server components there.

play08:21

I'm talking about

play08:22

React server components.

play08:22

I'm also talking about suspense.

play08:24

Okay.

play08:24

The fact that it's possible to manage

play08:26

asynchronous work across different

play08:29

components without them having to

play08:30

manually coordinate with each other.

play08:33

It's a very cool idea.

play08:34

And that's an idea that you know, every

play08:36

framework is eventually

play08:37

going to adopt in some form.

play08:40

So by when you say every framework, you

play08:42

mean Svelte is going to have to reckon

play08:44

with this at some point?

play08:45

Absolutely.

play08:47

So, you know, there was this idea many

play08:50

years ago that you should keep your

play08:52

concerns separated and gradually people

play08:54

came to understand that

play08:55

that's not really true.

play08:56

Like you actually want to have the

play08:58

behaviors that relate to your markup

play09:01

described in the same place.

play09:02

You want them to be co-located.

play09:04

Svelte took that one step further and

play09:07

said, well, we want styles to be

play09:09

co-located with your markup as well

play09:10

because you know, they

play09:12

relate to each other.

play09:13

And because we're a super set of HTML, we

play09:16

can put all of those in the same file.

play09:19

But then React came

play09:20

along and said, that's great.

play09:22

But what we really want to have is our

play09:25

data co-located with our components.

play09:28

That is a separation of

play09:30

concerns that makes no sense.

play09:33

And gradually, like the trajectory, the

play09:35

path of evolution is towards having all

play09:38

of the things in one place

play09:42

and not having this arbitrary separation

play09:44

where your data loading happens over here

play09:46

and it gets fed into

play09:47

your component over here.

play09:48

And then maybe you're pulling in some

play09:49

styles from over there.

play09:50

Like that, you know, you want

play09:51

that to be in the same place.

play09:55

Malta Eubel, who's the CTO of the cell

play09:57

where I work, he talks about

play09:58

deleteability a lot.

play10:02

Like if you can remove some code from

play10:05

your code base and there are

play10:07

vestiges of it left behind,

play10:09

like you're still pulling in the styles

play10:11

that relate to the

play10:11

market that no longer exists

play10:12

or you're still fetching some data over

play10:14

the network that is no longer being

play10:16

rendered by a component, then you fail.

play10:18

But that is the fate of just about every

play10:20

code base eventually.

play10:24

And React, because perhaps of its

play10:27

background in building very, very large

play10:29

applications at meta,

play10:31

that's the kind of problem that they've

play10:33

spent many years

play10:34

thinking about how to solve.

play10:36

And we just haven't because our

play10:37

background has been different.

play10:38

Like Svelte came out of a need to create

play10:41

richly interactive widgets

play10:42

on a very short timeframe.

play10:45

And so that is definitely an area where

play10:47

React is far ahead of us.

play10:52

And there are, you know,

play10:53

I'm sure there are others.

play10:54

The ecosystem obviously is one thing that

play10:57

people talk about a lot.

play10:58

If you need to solve a problem in React,

play11:00

then someone has probably

play11:01

already solved it for you

play11:01

and you can just

play11:02

install a thing from NPM.

play11:04

Kind of a blessing and a curse.

play11:06

You know, we talk about in Svelte the

play11:08

fact that very often you don't need to

play11:10

use an external package

play11:11

because it's easier to just use the

play11:14

platform in many cases.

play11:16

And libraries don't need special Svelte

play11:18

integrations the way they sometimes need

play11:20

special React integrations.

play11:22

But aside from that, like the fact that

play11:25

so much work has gone into solving

play11:27

problems in the React world

play11:29

is a huge advantage if

play11:31

you're a React developer.

play11:32

So jobs, ecosystem, maybe advanced data

play11:36

handling or data handling

play11:38

and really large applications

play11:40

or areas where React is obviously

play11:42

especially powerful.

play11:43

Yeah, very much so.

play11:44

Yeah.

play11:45

Svelte does a lot of the heavy lifting

play11:46

when it comes to logic and JavaScript.

play11:49

React doesn't, I feel like React doesn't

play11:52

hide as much of that.

play11:53

I mean, it kind of

play11:54

does with hooks and stuff.

play11:57

Do you think that somebody who comes to

play11:59

web development as a React developer

play12:00

will have a more intimate

play12:02

understanding of JavaScript

play12:03

than somebody who comes to web

play12:04

development as a Svelte developer?

play12:07

Honestly, I think the reverse is true.

play12:10

Particularly when Svelte 5 comes out and

play12:13

we're removing some of the

play12:16

magic that exists in Svelte 4.

play12:19

But even today, I think, you know, if you

play12:21

come to web development

play12:22

and you learn React first,

play12:23

which a lot of people do, a huge number

play12:25

of people learn React first,

play12:27

then you're kind of

play12:29

learning React and not JavaScript.

play12:32

And yes, React is JavaScript in a sense,

play12:35

but it's also very much not.

play12:37

Like you're learning a very specific

play12:38

style of programming.

play12:40

And the way that hooks work is like it's

play12:42

not how functions normally work.

play12:45

Like the idea that the return value of a

play12:46

function depends on like

play12:48

when it was last called

play12:50

and whether it was previously called and

play12:51

what it was last

play12:51

called, all of these things.

play12:53

That's just not how

play12:54

JavaScript typically behaves.

play12:56

And obviously, like you can do many

play13:01

things with JavaScript and like that is

play13:03

implemented without any magic,

play13:06

but it still like sort of

play13:08

violates your expectations.

play13:10

And so, you know, the way that you learn

play13:13

how to solve problems in React

play13:15

versus how you would have solved them

play13:16

without React, they're

play13:18

quite different things, I think.

play13:20

Whereas in Svelte, I think we are pushing

play13:23

people towards more idiomatic JavaScript

play13:26

solutions to problems.

play13:30

And, you know, I think people who are

play13:35

familiar with HTML, CSS and JavaScript

play13:39

but have not yet encountered a framework,

play13:41

very often we'll see that

play13:42

those people take to Svelte

play13:43

much more naturally

play13:44

than they'll take to React.

play13:47

Because it's just more natural.

play13:51

That feels counterintuitive to me and

play13:53

maybe that's why you started there.

play13:56

When I learned to React, I kind of felt

play13:59

like this is all just

play14:01

JavaScript, you know.

play14:04

I don't know if I ever fully understood

play14:06

how hooks work, but

play14:07

when it was taught to me,

play14:08

I kind of understood like, okay, like I

play14:10

could probably figure out how to

play14:11

implement this or work with this,

play14:12

like by understanding

play14:14

the code base better.

play14:15

Whereas when I look at runes, I think

play14:16

this is kind of magic.

play14:18

Like I don't need to

play14:19

understand how this works.

play14:20

Are you saying that you

play14:21

don't feel like that's the case?

play14:22

Like it is just JavaScript and you can

play14:24

kind of understand it in those terms?

play14:26

So I think the...

play14:29

When I say that it's more idiomatic, I

play14:31

mean the fact that, you know,

play14:33

if you have a component that is on the

play14:34

page and it's on the page for

play14:36

a while and the state comes in,

play14:38

the form of props and there's internal

play14:39

state that changes and then maybe

play14:41

eventually the component goes away.

play14:43

The component is instantiated once and

play14:46

the contents of the

play14:47

script tag, it runs once.

play14:50

Whereas in React, you're running that

play14:52

code again and again and again.

play14:54

And so you have to

play14:54

understand closures very deeply.

play14:57

You have to understand

play14:57

why things might get stale.

play15:00

And that is not how JavaScript typically

play15:04

works, but it's also...

play15:06

It's not really how our brains work.

play15:07

You think about a component or an

play15:11

instance of a component and it's a thing.

play15:14

Like you can talk about

play15:15

it as if it is a thing.

play15:18

But in React, it's not a thing.

play15:20

It is... In React, everything is sort of

play15:22

this transient sort of state of flux.

play15:27

And so you can get quite

play15:30

philosophical about this.

play15:33

The world is in a state of flux and the

play15:35

labels that we assign to things,

play15:36

the models of our... It's

play15:39

our internal representation.

play15:40

It doesn't describe anything in the

play15:41

objective world and React is actually a

play15:44

more faithful extension of that idea.

play15:48

But the human brain has evolved to think

play15:50

in terms of concrete objects.

play15:54

And I think that some of the ways in

play15:56

which people get confused about life

play15:59

cycle in React can sort

play16:00

of be traced back to that.

play16:02

We think in terms of objects and React

play16:05

thinks in terms of functions.

play16:07

It feels like what you're getting at when

play16:08

you talk about flux versus objects is the

play16:10

difference between event-driven and

play16:11

state-driven development.

play16:15

Kind of, yeah.

play16:18

Yeah, we...

play16:20

It's difficult to fully articulate this

play16:24

in a way that doesn't sound like...

play16:27

Like it's very abstract nonsense.

play16:30

But it's something that...

play16:32

What else are we doing here?

play16:33

Yeah. It's definitely something that I've

play16:36

seen people struggle with when looking at

play16:39

code and not really being

play16:40

able to understand like,

play16:42

why is this rerunning or what is it mean

play16:45

that it's rerunning?

play16:47

But JavaScript is an event-driven

play16:50

language and I mean, I feel like

play16:52

JavaScript does kind of

play16:53

exist in a state of flux.

play16:55

Yes. I mean, this is why I think

play16:58

JavaScript is fundamentally not a great

play17:00

language for UI development

play17:03

because it is event-driven.

play17:05

But when you're describing user

play17:05

interfaces, you want

play17:07

things to be state-driven.

play17:11

Are you slicing space

play17:14

or are you slicing time?

play17:15

Like those are two very different things.

play17:19

Let's keep going.

play17:21

And all a framework is essentially is a

play17:24

way to allow you to model state-driven

play17:28

programming in an event-driven language.

play17:32

So I'm in the process of converting a

play17:34

Next.js code base to Salt right now.

play17:39

And I keep on coming across these little

play17:41

pieces of React or Next.js syntax that I

play17:46

really kind of feel like I banged my head against a little bit.

play17:48

So aside from this being a really

play17:50

contrived example, how do we get here?

play17:52

How do we get to the place where the

play17:53

Svelte component is so concise, where the

play17:59

React component is so verbose?

play18:02

Yeah, I mean, as you say, it is extremely

play18:04

contrived. Normally, it's

play18:05

not quite that egregious.

play18:07

But this is, I think, what happens when

play18:10

you start from one set of priorities as

play18:13

opposed to a different set of priorities.

play18:15

Svelte is very relentlessly focused on

play18:17

these pragmatic goals of how

play18:19

quickly can we express an idea.

play18:23

And React is focused on different things.

play18:26

It's focused on being able to integrate

play18:31

with the rest of your application.

play18:34

It's all JavaScript. Everything that you

play18:36

see there is, well, not valid JavaScript,

play18:38

but valid JSX at least.

play18:41

If you wanted, you could extract part of

play18:44

that out into another function and you

play18:46

could move it to a different file or

play18:49

elsewhere in that module.

play18:52

So it's like composable in a certain way

play18:55

that Svelte maybe isn't.

play18:59

And, you know, most of the time, you're

play19:02

not going to need to

play19:03

write that sort of thing.

play19:04

So maybe focusing on that case hasn't

play19:07

been a big priority.

play19:11

And a lot of people prefer that. A lot of

play19:12

people look at that React code and say,

play19:13

well, that's much better because, you

play19:15

know, I haven't had to learn this weird

play19:18

new syntax, like this

play19:19

hash each array as number.

play19:23

Like, what is that? I don't want to have

play19:24

to learn any syntax. To which I always

play19:26

reply, like, if that syntax is too hard

play19:29

for you to learn, then maybe programming is the wrong profession.

play19:31

It's obviously pretty straightforward

play19:34

what's happening there.

play19:37

You know, it's just relative priorities.

play19:41

Like, my background is in journalism.

play19:45

Svelte was built for me to solve the

play19:47

problems that I faced as a working

play19:49

journalist needing to hit deadlines.

play19:52

And it takes a lot less time to write the

play19:55

code on the top than it takes to write

play19:56

the code on the bottom.

play19:57

And so that's why we

play19:59

ended up where we did.

play20:00

I think it's really cool thinking about

play20:03

it in terms of what you're describing of,

play20:05

like, managing a world in flux.

play20:09

And I kind of like you said, React is

play20:13

good if you're dealing with, like, a data

play20:16

intensive, like, a large code base, like,

play20:18

a lot of data flowing through it.

play20:19

Then I feel like React does kind of feel

play20:22

like it's got those power tools for

play20:24

dealing with these, like,

play20:27

large flows of data and stuff.

play20:28

It's for, like you said, it's for slicing

play20:30

time. Whereas if you're dealing with

play20:33

something that feels more like objects,

play20:35

something that feels more solid,

play20:37

something that feels more visual, if

play20:39

you're slicing space,

play20:41

Svelte's got your back.

play20:43

I think I'm probably going to think about

play20:45

it from the thing about

play20:46

it that way from now on.

play20:48

Yeah, I mean, historically, I think we

play20:50

probably over-indexed on that problem.

play20:56

Like, how can we solve 90% of problems in

play21:00

a very straightforward way?

play21:02

Can we provide some syntax that makes

play21:04

this common use case super easy?

play21:07

And that's great for a lot of use cases.

play21:11

But then when you hit that 10% of the

play21:13

things where you really do need some advanced programming,

play21:16

that's where Svelte 3 and 4

play21:18

start to fray a little bit.

play21:22

And over the years since Svelte 3 came

play21:24

out, and people have started to build

play21:25

more and larger applications, we've

play21:28

started to see people

play21:29

hit those boundaries.

play21:30

And so that is really what Svelte 5 is

play21:32

all about. We're trying to preserve the

play21:35

simple cases, keep those

play21:37

as simple as they are today,

play21:39

but also give people the extra power and

play21:42

flexibility and composability that people

play21:45

in the React world take for granted.

play21:48

Am I right in thinking that you're

play21:49

talking about the dollar sign operator?

play21:53

Among other things, yeah. That is a great

play21:55

example of something that, you know, you

play21:59

learn it in the first 10

play22:00

minutes of using Svelte,

play22:01

and it feels like, you know, coding with

play22:04

the wind in your hair and everything.

play22:05

But when you start to use it more

play22:11

extensively, you find that actually it's

play22:13

a little bit of a trap, because inside

play22:16

that dollar colon statement,

play22:19

we're operating under slightly different

play22:21

rules. Like that code will rerun when the

play22:24

compiler says that it should rerun.

play22:27

And when you start to put more and more

play22:29

logic in there, and then realize that you

play22:32

can't really refactor it out without

play22:34

changing the behavior,

play22:36

that becomes a little bit frustrating.

play22:38

And that's the kind of problem that we're

play22:40

solving in Svelte 5 by taking some of the

play22:44

responsibility out of the compiler and

play22:46

putting it into the runtime

play22:47

using our signal mechanism.

play22:51

And based on everything that we've seen

play22:54

from using Svelte 5 to re-implement

play22:56

things that we maintain,

play23:00

I think that people are hopefully going

play23:03

to find that we still have this really

play23:07

nice, elegant syntax for common problems,

play23:10

but we also have the ability to do things

play23:12

in a more robust and scalable fashion

play23:17

than we could before.

play23:19

What would React have to do for you to

play23:23

hang up your hat and say, "All right, I'm

play23:24

going to get a job as a React developer"?

play23:26

Oh, wow. A lot of the things that come

play23:35

with Svelte, like transitions and

play23:37

animations and styles as part of your component definition,

play23:40

I would really be reluctant to give those

play23:44

up. And you can do those things in React.

play23:48

You have to install some packages and you

play23:50

have to do things in a

play23:52

slightly different way,

play23:52

but it's all possible. You can do all

play23:54

that. But it doesn't feel as nice, and

play23:58

they would have to make it feel as nice.

play24:01

That stuff needs to be built in. It needs

play24:02

to come with part of the framework. The

play24:04

framework needs to consider these

play24:05

problems to be part of its domain,

play24:08

rather than, "We're just concerned with

play24:13

reconciling the DOM and all of these

play24:15

other problems. We're going

play24:16

to leave that to userland."

play24:18

That's a perfectly legitimate and

play24:20

understandable stance to take, but it's

play24:23

not the stance that I

play24:24

want my framework to take.

play24:26

And so it's not the stance that Svelte

play24:27

takes. And for me to not use Svelte and

play24:30

use React instead, that would have to be

play24:33

quite a big philosophical shift.

play24:35

Which is, I think, a good and healthy

play24:38

thing. The fact that we have these

play24:40

different projects in the ecosystem that

play24:43

have these different philosophies.

play24:44

If you want to be a React developer, if

play24:47

you subscribe to the React philosophy,

play24:48

then use React. If you

play24:50

subscribe to the Svelte philosophy,

play24:52

the thing should be a little bit more

play24:54

encapsulated and focused on day-to-day

play24:57

problems than come and use Svelte.

play24:59

And if you're somewhere in between, if

play25:03

you prefer the aesthetics of a different

play25:05

framework, solid view,

play25:06

whatever it is, then use those.

play25:09

I don't see all of these things as in

play25:12

competition so much. We're just occupying

play25:15

different niches in the ecosystem.

play25:17

And I think it's important that all of

play25:19

those things exist and continue to be

play25:21

meaningfully different so that people

play25:23

actually have a meaningful choice.

play25:25

This is just such an exciting time. I

play25:27

feel like there's so much innovation

play25:30

happening in the web development sphere.

play25:32

I feel like it's really a golden age for

play25:34

web development with all these different

play25:36

frameworks, which are all coming up with

play25:38

different approaches to solving problems,

play25:41

or coming up with the same approaches to

play25:42

solving problems. And I'm really excited

play25:45

to see where it goes, and I genuinely

play25:47

hope that you do not hang up your hat and

play25:49

become a React developer.

play25:50

And if you want to learn more about

play25:52

Svelte, you can check out our feature

play25:54

interview with Rich, which we did at his

play25:56

apartment in New York

play25:57

City back in December.

play26:00

And otherwise, thanks very much for

play26:02

joining me. Thank you.

play26:06

Thank you, Sam. Do I look like a

play26:07

YouTuber? Do I come

play26:09

off like an influencer?

play26:09

Do I come off like an influencer?

play26:10

I mean, I think you're

play26:13

actually smashing it.

play26:14

I'm fishing for compliments here.

play26:15

I'm fishing for compliments here.

Rate This

5.0 / 5 (0 votes)

Связанные теги
Web DevelopmentReactSvelteRich HarrisJavaScriptUI FrameworksFrontendInterviewCode ComparisonDevelopment Philosophy
Вам нужно краткое изложение на английском?