Transcript from the "Why Web Assembly" Lesson
[00:00:42] And again, those are two different concepts. They're both different processes running in the browser. But web assembly is its own environment its sandbox is memory safe. And the main point of web assembly is that other engineers can write code that runs on browser. And this is the part that always gets me it's kind of a misnomer because people say we're suddenly like, yeah, it must be something in front engineers do.
[00:01:10] And actually, from the people I've talked to you all the blog posts I've read the talks I've seen, most of the people writing web assembly are not front end engineers. They are people that write C. They're people to write rust or C++ or I don't know if C sharp compiles yet.
[00:01:24] I'll look that up. But there are people that aren't necessarily enamored with the front end like like, we are in front of masters. There are people that they want to do video processing image processing games, because web assembly works with binary data. That is super low level ones and zeros and you're moving them around, which is why we're gonna spend quite a bit of time on the foundational work.
[00:02:43] It runs on more than just browsers. Right now, there's not a really broad use case for writing desktop apps with web assembly, but that's coming in the future. The whole reason why web assembly exists is to have a portable, memory safe, consistent environment, to write a language. And if you're thinking, Well, that sounds a lot like the old days, like where we wrote desktop apps, and then we ship them constantly.
[00:03:33] That's because a native application written in C sharp or Java or anything like that is always going to use the low level memory instructions of the computer that it's on. So if it's using Windows or Linux or an arm system or an x86 system, a desktop application can take advantage of that because it can reach down into low level instruction code and just be more efficient.
[00:04:16] And then we can take that code and move it to a Linux machine or Windows machine and run it natively on the desktop. That's pretty cool. That's so cool. Alright, but mainly I'm trying to set context here and it's not a silver bullet, it's not gonna solve all of your performance issues or things like that.
[00:04:42] That's not what web assembly is for. It's for this portability and the ability to take complex programs that you've already written in C, like a video encoder or decoder, and then bring them to the web and then use that power in a safe, memory efficient manner. Okay, that was a lot.
[00:05:00] Are there any questions so far on web assembly because I talked at a super high level. And I really wanna make sure we understand what we're doing here today. And what we're going to get out of it.
>> Is a question about comparing it to Java has byte code what it compiles versus web assembly like how are they different?
>> Are there similarities.
>> There are similarities because Java and I want to say Python also compiles down to bytecode or some form of it. There's similarities there but web assembly ultimately is going to compile down to assembly it is. It's not the lowest level of programming that would be assembly language itself.
[00:05:50] That's as low as we can get, we can't write ones and zeros. I haven't met a human who can do that I'm sure there's like one person on the planet who can like I can code in ones and zeros. I don't know how, but the lowest level of programming we can get is assembly.
[00:06:03] And then right above that is web assembly. So hence the name web assembly. Now Java is still going to compile to, or Python is still doing part of bytecode which has to compile down again into assembly instructions, and then it runs natively. So, in terms of performance, I would say Java is still gonna be faster, not not due to anything like input or architecture or how it's written.
[00:06:32] It's just the more mature platform. There are more optimizations in the Pilar. There are more tips and tricks we know for optimizing all that code. Web assembly is the newest kid on the block. It's been around for a few years, but it really gained popularity once all the browser's decided that this was the thing.
[00:06:50] We're gonna adopt it and let's make it work for everybody. And for the most part for something kind of relatively unknown in the front end land every browser supports web assembly, that's one of the reasons why I'm making this course is because we just don't really know that it's for engineers.
[00:07:23] And that's why I wrote this course because as we go on in the future, we will definitely see more web assembly and I want people to be familiar with it. This is exactly what I say in my full stack course, in that you're not gonna learn everything about full stack or servers or things like that.
[00:07:40] It's more when you see it again, you'll be familiar and if it's an area you're interested in, well, maybe I can change your career path into being a web assembly programmer. I really believe this is the forefront of the next stage of the internet, which, yeah, I'll talk more about that and my passionate and all that.
[00:07:59] Are any other questions? I love that what about Java and bytecode. The question was, is web assembly similar to programming in assembly itself as an x86 instructions or arm or whatever micro architecture of the system they programming on? The answer is yes and no. Yes, in that the principles are the same we're actually just taking bits and we're moving them around.
[00:08:25] We're applying low level instructions called opcodes to all of these bits. But it's a step above assembly and that we have nice things like four loops, and dealing with arrays, and if statements that aren't completely ridiculous to read, so I'd say it's somewhere in the middle. It's definitely more approachable than trying to learn assembly.
[00:08:50] And that's really the goal of this course is to make it approachable make it understandable for everybody. But yeah, I'll do some comparisons to assembly a bit later. But for now think of it as the middle ground between assembly and a high level language.
>> I was just wondering.
[00:09:10] So that means we can actually rethink the way we shipped like for example packages can we just swipe packages in web assembly and then they can actually. I mean, the consumer can compose those packages they could do when shipping.
>> Yes, thank you. Yeah, you're already there. You're already that's why we wanna think about this.
[00:09:28] Yes, what we, the power we get right now is the ability to take, let's say a video decoder. It's written in C, which is a time tested, very old language. Very efficient. We can compile that to web assembly and we take all those efficiencies we got from C.
[00:10:46] You really do still have to know what you're doing because it can quickly go off the rails I'll say when we tackle memory later which I save memory till pretty far down the course because it's a really complicated topic and it's cognitively it's difficult for a lot of engineers to understand.
[00:11:06] But you have to understand exactly what's going on. Because we're going to see sine shifting, like literally we're moving bits here and there and we're moving from a 16 bit Integer to an unsigned eight bit integer. And you really have to understand that stuff at a low level.
[00:11:22] So I wouldn't say go out and pour your favorite library to web assembly just yet. However, there are many examples of people have done that so far and there are some links at the end where we see made with web assembly where people have ported rust and other high level programs into it.
[00:11:39] But yes, to answer that, that's a long way to answer your question. You can. It's a little tricky though. There's the question in the chat was, can we reuse things like fetch and other browser API's or do we have to rewrite them from scratch? The answer is yes, we will use fetch.
[00:11:58] We will use some browser API's. But the surface area is pretty minimal. And it's gonna come down to moving memory back and forth and the tooling that we're going to use later built by using assembly scripts and things like binary and things like that. But good question we will get there.