webassembly._.NET和WebAssembly-这是前端的未来吗?

webassembly.

webassembly.

6 years ago Erik Meijer and I were talking about how JavaScript is/was an assembly language. It turned into an interesting discussion/argument (some people really didn't buy it) but it still kept happening. Currently WebAssembly world is marching forward and is supported in Chrome, Firefox, and in Development in Edge, Opera, and Safari.

6年前,Erik Meijer和我在谈论JavaScript是/是一种汇编语言。 变成了一个有趣的讨论/争论(有些人确实不买它),但是它仍然不断发生。 当前,WebAssembly世界正在前进,并且在Chrome,Firefox和Edge ,Opera和Safari中受开发支持。

"The avalanche has begun, it's too late for the pebbles to vote." - Ambassador Kosh

“雪崩已经开始,卵石投票还为时已晚。” -科什大使

Today in 2017, WebAssembly is absolutely a thing and you can learn about it at http://webassembly.org. I even did a podcast on WebAssembly with Mozilla Fellow David Bryant (you really should check out my podcast, I'm very proud of it. It's good.)

在2017年的今天,WebAssembly绝对是一回事,您可以在http://webassembly.org上了解它。 我什至与Mozilla Fellow David Bryant一起在WebAssembly上进行了播客(您真的应该查看我的播客,我对此感到非常自豪。这很好。)

The classic JavaScript TODO app, written with C# and .NET and Blazor

The image above is from Steve Sanderson's NDC presentation. He's writing the classic client-side JavaScript ToDo application...except he's writing the code in C#.

图来自Steve Sanderson的NDC演示文稿。 他正在编写经典的客户端JavaScript ToDo应用程序……除了他正在使用C#编写代码外。

什么是WebAssembly? (What is WebAssembly?)

"WebAssembly or wasm is a low-level bytecode format for in-browser client-side scripting, evolved from JavaScript." You can easily compile to WebAssembly from C and C++ today...and more languages are jumping in to include WebAssembly as a target every day.

“ WebAssembly或wasm是浏览器内部客户端脚本的底层字节码格式,是从JavaScript演变而来的。” 您现在可以轻松地从C和C ++编译为WebAssembly ……并且每天都有越来越多的语言加入WebAssembly作为目标。

Since I work in open source .NET and since .NET Core 2.0 is cross-platform with an imminent release, it's worth exploring where WebAssembly fits into a .NET world.

由于我从事开源.NET的工作,并且.NET Core 2.0具有即将发布的跨平台版本,因此值得探索WebAssembly适合.NET世界的地方。

Here's some projects I have identified that help bridge the .NET world and the WebAssembly world. I think that this is going to be THE hot space in the next 18 months.

我已经确定了一些项目,这些项目有助于将.NET世界和WebAssembly世界联系起来。 我认为这将是未来18个月的热门空间。

.NET的WebAssembly (WebAssembly for .NET)

Despite its overarching name, this OSS project is meant to consume WASM binary files and execute them from within .NET assemblies. To be clear, this isn't compiling .NET languages' (C#, VB.NET, F#) into WebAssembly, this is for using WebAssembly as if it's any other piece of resuable compiled code. Got an existing WASM file you REALLY want to call from .NET? This is for that.

尽管有其总体名称,但此OSS项目旨在使用WASM二进制文件并从.NET程序集中执行它们。 需要明确的是,这并不是将.NET语言(C#,VB.NET,F#)编译为WebAssembly,这是为了使用WebAssembly,就像将其作为任何其他可恢复的已编译代码一样。 得到了您真正想从.NET调用的现有WASM文件? 为此。

Interestingly, this project doesn't spin up a V8 or Chakra JavaScript engine to run WASM, instead it reads in the bytecode and converts them to .NET via System.Reflection.Emit. Interesting stuff!

有趣的是,该项目不会启动V8或Chakra JavaScript引擎来运行WASM,而是读取字节码并将其通过System.Reflection.Emit转换为.NET。 有趣的东西!

Mono和WebAssembly (Mono and WebAssembly)

One of the great things happening in the larger .NET Ecosystem is that there is more than one ".NET" today. In the past, .NET was a thing that you installed on Windows and generally feared. Today, there's .NET 4.x+ on basically every Windows machine out there, there's .NET Core that runs in Docker, on Mac, Windows, and a dozen Linuxes...even Raspberry Pi, and Mono is another instance of .NET that allows you to run code in dozens of other platforms. There's multiple "instances of .NET" out there in active development.

更大的.NET生态系统中发生的一件大事是,当今有多个“ .NET”。 过去,.NET是您在Windows上安装的,通常令人担心。 如今,基本上所有的Windows机器上都存在.NET 4.x +,在Docker,Mac,Windows和十几个Linuxes上运行的.NET Core……甚至是Raspberry Pi,而Mono是.NET的另一个实例允许您在许多其他平台上运行代码。 在积极开发中,存在多个“ .NET实例”。

The Mono Project has two prototypes using Mono and WebAssembly.

Mono项目有两个使用Mono和WebAssembly的原型

The first one uses the traditional full static compilation mode of Mono, this compiled both the Mono C runtime and the Mono class libraries along with the user code into WebAssembly code. It produces one large statically compiled application. You can try this fully statically compiled Hello World here. The full static compilation currently lives here.

第一个使用Mono的传统的完全静态编译模式,它将Mono C运行时和Mono类库以及用户代码一起编译为WebAssembly代码。 它产生一个大型的静态编译应用程序。 您可以在此处尝试使用此完全静态编译的Hello World。 完整的静态编译当前位于此处

So that's a totally statically compiled Hello World...it's all of Mono and your app into Web Assembly. They have another prototype with a difference perspective:

因此,这是一个完全静态编译的Hello World……这是Mono和您的应用程序全部集成到Web Assembly中的过程。 他们还有另一个具有不同观点的原型:

The second prototype compiles the Mono C runtime into web assembly, and then uses Mono’s IL interpreter to run managed code. This one is a smaller download, but comes at the expense of performance. The mixed mode execution prototype currently lives here.

第二个原型将Mono C运行时编译为Web程序集,然后使用Mono的IL解释器运行托管代码。 这是一个较小的下载,但以性能为代价。 混合模式执行原型当前位于此处

Here they've got much of Mono running in Web Assembly, but your IL code is interpreted. One of the wonderful things about Computer Science - There is more than one way to do something, and they are often each awesome in their own way!

在这里,他们在Web Assembly中运行了许多Mono,但是将解释您的IL代码。 关于计算机科学的一件奇妙的事情-做事情的方法不止一种,而且每种方法都各有千秋!

“ Blazor”-在浏览器中运行.NET的实验UI框架 ("Blazor" - Experimental UI Framework running .NET in the browser)

With a similar idea as the Mono Project's second prototype, Steve Sanderson took yet another "instance of .NET," the six year old open source DotNetAnywhere (DNA) project and compiled it into Web Assembly. DNA was an interpreted .NET runtime written in portable C. It takes standard IL or CIL (Common Intermediate Language) and runs it "on resource-constrained devices where it is not possible to run a full .NET runtime (e.g. Mono)." Clever, huh? What "resource-constrained device do we have here six years later?" Why, it's the little virtual machine that could - the JavaScript VM that your browser already has, now powered by a standard bytecode format called WebAssembly.

史蒂夫·桑德森(Steve Sanderson)的想法与Mono Project的第二个原型类似,它采用了另一个“ .NET实例”,即已有6年历史的开源DotNetAnywhere(DNA)项目,并将其编译为Web Assembly。 DNA是用可移植的C语言编写的经过解释的.NET运行时。它采用标准的IL或CIL(通用中间语言),并在“无法运行完整的.NET运行时(例如Mono )的资源受限的设备上运行”。 聪明吧? 六年后,我们在这里拥有什么资源受限的设备? 为什么呢?它是可能的小虚拟机-您的浏览器已拥有JavaScript VM,现在由称为WebAssembly的标准字节码格式提供支持。

To prove the concept, Steve compiles DotNetAnywhere to WASM but then takes it further. He's combined standard programming models that we see on the web with things like Angular, Knockoutjs, or Ember, except rather than writing your web applications' UI in JavaScript, you write in C# - a .NET language.

为了证明这一概念,Steve将DotNetAnywhere编译为WASM,然后将其进一步扩展。 他将我们在网络上看到的标准编程模型与Angular,Knockoutjs或Ember等功能结合在一起,除了用JavaScript编写Web应用程序的UI之外,您还使用C#-.NET语言编写。

Here in the middle of some Razor (basically HTML with C# inline) pages, he does what looks like a call to a backend. This is C# code, but it'll run as WASM on the client side within a Blazor app.

在某些Razor(基本上是带有C#内联HTML)页面的中间,他所做的看起来像是对后端的调用。 这是C#代码,但是它将在Blazor应用程序中作为WASM在客户端运行。

@functions {
WeatherForecast[] forecasts;

override protected async Task InitAsync()
{
using (var client = new HttpClient())
{
var json = await client.GetStringAsync(AbsoluteUrl("/api/SampleData/WeatherForecasts"));
forecasts = JsonUtil.Deserialize<WeatherForecast[]>(json);
}
}
}

This would allow a .NET programmer to use the same data models on the client and the server - much like well-factored JavaScript should today - as well as using other .NET libraries they might be familiar or comfortable with.

这样一来,.NET程序员就可以在客户端和服务器上使用相同的数据模型(就像今天构造良好JavaScript一样),以及使用他们可能熟悉或熟悉的其他.NET库。

Why do this insane thing? "To see how well such a framework might work, and how much anyone would care." How far could/should this go? David Fowler already has debugging working (again this is ALL prototypes) in Visual Studio Code. Don't take my word for it, watch the video as Steve presents the concept at the NDC Conference.

为什么这疯狂的事情? “看看这种框架可能运作得如何,以及每个人都会关心多少。” 这可以/应该走多远? David Fowler已经在Visual Studio Code中进行了调试工作(同样,这是所有原型) 。 不要相信我,在史蒂夫(Steve)在NDC会议上介绍这个概念时观看视频。

Blazor as a prototype has a number of people excited, and there was a Blazor Hackthon recently that produced some interesting samples including a full-blown app.

Blazor作为原型使很多人兴奋不已,最近有一个Blazor Hackthon产生了一些有趣的样本,包括一个功能完善的应用程序

还有其他可能性吗? (Other possibilities?)

There's lots of other projects that are compiling or transpiling things to JavaScript. Could they be modified to support WebAssembly? You can take F# and compile it to JavaScript with F#'s Fable project, and some folks have asked about WebAssembly.

还有许多其他项目正在将内容编译或转译为JavaScript。 可以修改它们以支持WebAssembly吗? 您可以使用F#并通过F#的Fable项目将其编译为JavaScript一些人问到WebAssembly的问题

At this point it's clear that everyone is prototyping and hacking and enjoying themselves.

在这一点上,很明显每个人都在原型设计黑客攻击娱乐中。

What do YOU think about WebAssembly?

您如何看待WebAssembly?

翻译自: https://www.hanselman.com/blog/net-and-webassembly-is-this-the-future-of-the-frontend

webassembly.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值