简体   繁体   English

当一个人喜欢使用JavaScript而不是C#来编写Windows8应用程序时,它是否会提供性能或可访问性好处?

[英]Does it give performance or accessibility benefit when one prefer to use JavaScript over C# for writing a Windows8 app?

If one will have an option to select between JavaScript (With HTML) and C# (With XAML) for writing a Windows 8 app which one should he/she prefer ? 如果有人可以选择在JavaScript(使用HTML)和C#(使用XAML)之间进行选择,以编写一个他/她更喜欢的Windows 8应用程序吗? Does it give any performance benefit or Is C# has greater accessibility to Windows8 API and system calls ? 它是否具有任何性能优势,或者C#是否可以更好地访问Windows8 API和系统调用?

I'm afraid there was some confusion about the OP. 我担心OP会有一些混乱。 We're talking about developing apps for Windows 8. You can use multiple language stacks to target Windows 8. You can use XAML/C#, XAML/C++, DirectX/C++, or HTML/JavaScript. 我们正在讨论为Windows 8开发应用程序。您可以使用多种语言堆栈来定位Windows 8.您可以使用XAML / C#,XAML / C ++,DirectX / C ++或HTML / JavaScript。 The question was in regard to which of the two most popular stacks - XAML/C# and HTML/JavaScript - has better performance and better access to the Windows API. 问题在于两个最流行的堆栈中的哪一个--XAML / C#和HTML / JavaScript - 具有更好的性能和更好的Windows API访问权限。

I'm a Developer Evangelist at Microsoft and this is the most frequently asked question I get. 我是微软的开发人员传播者,这是我得到的最常见问题。 I have a post at codefoster.com/Which-Windows-8-Language-Stack-Should-I-Choose that touches part of the question but not all. 我在codefoster.com/Which-Windows-8-Language-Stack-Should-I-选择了一个帖子,它涉及问题的一部分,但不是全部。

First, regarding access to the Windows API (WinRT), all language stacks are identical. 首先,关于对Windows API(WinRT)的访问,所有语言堆栈都是相同的。 The entire WinRT object space is actually projected into the different languages, so in any language you can call into the Windoww API and they always start with "Windows.". 整个WinRT对象空间实际上被投射到不同的语言中,因此在任何语言中,您都可以调用Windoww API,它们始终以“Windows”开头。

The projections follow the conventions of each of the languages they're projected into as well, so in C# you might call Windows.UI.Popups.MessageDialog("Hello World").ShowAsync(), whereas in JavaScript you would call Windows.UI.Popups.MessageDialog("Hello World").showAsync(). 这些预测也遵循它们预测的每种语言的惯例,因此在C#中你可以调用Windows.UI.Popups.MessageDialog(“Hello World”)。ShowAsync(),而在JavaScript中你可以调用Windows。 UI.Popups.MessageDialog(“Hello World”)。showAsync()。 Similarly, each language uses its own conventions for handling async. 同样,每种语言都使用自己的约定来处理异步。 In C#, you would use the async/await pattern, but in JavaScript you would use the promise pattern. 在C#中,您将使用async / await模式,但在JavaScript中您将使用promise模式。

Next, on the matter of performance. 接下来,就性能问题而言。 There are going to be differences between the language stacks due to the natural and drastic differences between the languages. 由于语言之间的自然和巨大差异,语言堆栈之间将存在差异。 The important thing to know is that for all built in controls and scenarios, all language stacks are designed to meet a minimum performance threshold. 重要的是要知道,对于所有内置控件和场景,所有语言堆栈都旨在满足最低性能阈值。 Honestly, I don't think you need to worry about any of the language stacks falling behind in performance for you unless you've got some really interesting stuff going on in which case you should be specific about what it is. 老实说,我不认为你需要担心任何语言堆栈在性能方面落后于你,除非你有一些非常有趣的东西,在这种情况下你应该具体说明它是什么。

Each of the language stacks has its own strengths and weaknesses as well. 每个语言堆栈也有自己的优点和缺点。 If you're using C# you have a good set of the .NET framework with is extremely familiar to many people. 如果您使用的是C#,那么很多人都非常熟悉.NET框架。 It's also a very well designed and expressive language. 它也是一种设计精良,富有表现力的语言。 Additionally, XAML is a very powerful UI language. 此外,XAML是一种非常强大的UI语言。 If you're using JavaScript then you have code in common with the rest of the vast internet and can share a lot of code. 如果您使用的是JavaScript,那么您可以使用与其他大量互联网相同的代码,并可以共享大量代码。 You can find JavaScript libraries to do just about anything you want and you can use any of those in your Windows 8 app. 您可以找到JavaScript库来执行您想要的任何操作,您可以使用Windows 8应用程序中的任何一个。 If you are using C++ then you have access to existing C and C++ components and access to DirectX for making 3D apps. 如果您使用的是C ++,那么您可以访问现有的C和C ++组件,并可以访问DirectX来制作3D应用程序。

Keep in mind that you can make hybrid apps where you use C# or C++ to create WinRT components and then you can consume those components in any of the language stacks - including JavaScript! 请记住,您可以使用C#或C ++创建混合应用程序来创建WinRT组件,然后您可以在任何语言堆栈中使用这些组件 - 包括JavaScript! So if you know C# and want to write your business logic in C#, you can do that and then just use that logic in your JavaScript app. 因此,如果您了解C#并希望在C#中编写业务逻辑,则可以执行此操作,然后在JavaScript应用程序中使用该逻辑。

Finally, I think the two biggest factors in making the decision on which stack to choose are 1) the stack you have the most skill in already and 2) the stack you enjoy using. 最后,我认为决定选择哪个堆栈的两个最大因素是1)你已经掌握最多技能的堆栈和2)你喜欢使用的堆栈。 Those are important and might carry you through a project you would otherwise ditch. 这些很重要,可能会带您完成一个您可能会放弃的项目。

I hope this helps make your decision. 我希望这有助于你做出决定。 If you need any help making Windows 8 apps, I'm at codefoster.com . 如果您需要任何帮助制作Windows 8应用程序,我在codefoster.com

You're comparing a scripting language to a native (compiled) language. 您正在将脚本语言与本机(编译)语言进行比较。

JS has very limited access to the system when compared to C#. 与C#相比,JS对系统的访问权限非常有限。 But then again, depending on what you want to application to do, it could be the best choice. 但话又说回来,根据你想申请的内容,它可能是最好的选择。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM