托管与非托管语言:为什么非托管语言更难? [英] Managed vs Unmanaged languages: Why Unmanaged languages are harder?

查看:128
本文介绍了托管与非托管语言:为什么非托管语言更难?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

像C ++这样的非托管语言访问所有API并且不受限制。

但是学习非托管语言比较困难,他们有很深的学习曲线。

它是很难,这就是人们选择托管语言而不管理的原因。
我是对的吗?



那么,是什么让我更难写两者上的代码相同吗?

解决方案

不,C ++例如可以在托管或非托管中使用,无论如何都是相同的语言。

这是在那里产生差异的框架。



非托管代码有点困难,因为它对你没有那么多,它不会隐藏正在发生的事情的细节在一层抽象背后,这既是力量也是弱点。这是一种力量,因为它可以让你更多地控制正在发生的事情,这是一个弱点,因为控制权有责任自己清理!



如果您正在比较C ++和C#,那么C#比C ++更简单,更容易学习(和使用),即使在管理C ++时也是如此。但那是因为C#被设计成一种与.NET框架集成的更现代的语言。 C ++基于C,它基于ALGOL和Pascal,它的根源是一个四十年的计算机语言! :笑:



这并不意味着垃圾,只是它多年来收集了很多,而且必然变得相当复杂。


你甚至知道一个mananged代码是什么?为.NET框架运行的代码称为托管代码。有超过20个语言可用于在.NET框架上编写应用程序,C ++也是其中之一,您可以用C ++编写应用程序,它们可以称为托管代码应用程序,因为它们在.NET框架和IL等下执行这个术语托管代码归微软所有,因为它们被用于区分为其平台编写的代码与其他代码。



什么是托管代码? (MSDN链接) [ ^ ]



问题是,非托管代码,就像你说的那样,C ++更难学。是因为,在使用非托管代码时,您必须坚持默认语言,即本机语言。例如,托管和非托管C ++代码之间存在差异,请看下面,



  //  用于输入,输出 
#include< iostream>

// for cout
using namespace std;

void main(){
cout<< Hello world!;
}

/ * 以下是mananged代码,
*使用.NET类和框架
*首先,编辑配置确保运行时为
*,目标是通用和C / C ++中的\ CLR * /


#include< windows.h>

// for the console
使用 命名空间系统;
void main(){
Console :: WriteLine( Hello World);
}
< / windows.h > < / iostream >





现在,如果您感到不安,尝试阅读上面的代码,那么您首先需要开始热爱编程应用程序,而不仅仅是.NET应用程序。编程,是一个庞大的领域然而.NET是一个主要使用的框架,但这些语言也很有用,在Managed状态之外也是如此。它们并不难,你只是找不到System命名空间。



然而,高级脚本语言更容易被激活。 PHP,JavaScript等。但是,即使在托管语言中,C ++也是最难学的,因为它需要大量的时间来理解指针等功能。也许这就是为什么,语法似乎可怕


The Unmanaged language like C++ accesses all APIs and it is not limited.
But it is harder to learn unmanaged languages, they have deep learning curve.
It is hard and that is why people choose managed languages over unmanaged.
Am i right?

So, what makes it harder if to write the same code on both of them?

解决方案

No, C++ for example is usable in managed or unmanaged, it's the same language regardless.
It's the framework that makes the difference there.

Unmanaged code it a bit harder, because it doesn't do as much for you, it doesn't "hide" the nitty-gritty of what is going on behind a layer of abstraction, and that is both a strength and a weakness. It's a strength because it gives you a lot more control over what is going on, and it's a weakness because that control comes with the responsibility to clean up behind yourself!

If you were comparing C++ and C# then yes, C# is a lot simpler and easier to learn (and use) than C++, even when the C++ is managed. But that's because C# was designed to be a more modern language that was integrated with the .NET framework. C++ is based on C, which was based on ALGOL and Pascal and is at it's roots a forty year old computer language! :laugh:

That doesn't mean it rubbish, just that it's collected a lot over the years, and it has of necessity become pretty complex.


Do you even know what a mananged code is? The code that runs for the .NET framework is known as managed code. There are more than 20 lanugages that can be used to write applications on .NET framework, C++ is also one of them and you can write applications in C++ and they can be called managed code applications because they are executed under .NET framework and IL etc. This term, "Managed Code" is owned by Microsoft, because this is used by them, to distinguish the code written for their platform, from others.

What is Managed Code? (MSDN link)[^]

The thing is, that unmanaged code, like you said, C++ is harder to learn. Is because, while working in an unmanaged code, you have to stick to the default language, the native one. For example, there is a difference between managed and unmanaged C++ code, have a look below,

// for input, output 
#include <iostream>

// for cout
using namespace std;

void main() {
   cout << "Hello world!";
}

/* Below is the mananged code, 
 * using the .NET classes and framework
 * First of all, Edit the configuration make sure Runtime is
 * targeting the \CLR in General and C/C++ */

#include <windows.h>

// for Console
using namespace System;
void main () {
  Console::WriteLine("Hello World");
}
</windows.h></iostream>



Now, if you're getting uneasy, trying to read the above code then you first need to start love to program applications, not just .NET applications. Programming, is a huge field however .NET is a mainly used framework, but these languages are of good use, outside of "Managed" state too. They're not tough, you just don't find the "System" namespace around.

However, the high-level scripting languages are even more easy to laern. PHP, JavaScript etc. However, even in Managed languages, C++ is the toughest one to learn, because it requires a lot of time to understand the features like pointers etc. Maybe that is why, the syntax seems horrible.


这篇关于托管与非托管语言:为什么非托管语言更难?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆