comparing c++ and c# -- a perspective from high level languages such as C#

recently I was trouble shooting some c# projects exported a very famous game company. they make tools by using .net WPF frameworks.

 

I was really headache on fixing most of bugs, because these bugs were just too stupid, and I can never think of it. And these bugs were rase by careless coding, un-protection design. But it's not just all the programmer's fault to make the code unrealiable, but also the language structure they used, such as C#.

 

For example, provided that we need to pass a directory(or path) variable into a function throught the parameter. what did the path variable look like in both languages?

 

In C# maybe a wraped string type, since C# did not have the concept of pointer types, so the programmer believe that the passed in parameter is alway valid, thought the path string can be a empty string, but a empty is still a valid string. So the programmer didn't know how to, or they should always verify the input. But all the c# variable type have a 'null' concept, before the function was called, the upper level may provide a null string. So when the null string variable is processed by the function code, exception occured, and the debug information may completely missleading you to and unrelated place, because the error level is occured under some very low level internal systems of .net framework, and may not covered the invalid usages by the programmers. So, c# did provide a lazy model, but the higher level attributes of language has completely hide the inner details of computer system. for those beginner from c#, since there is no concept of what pointer really are, I guess 80% precent of people won't truly understand what a 'null' type really was, and 80% of people won't take a 'null' type check, because all the types were referenced, and some guys always believe that the system is robust and can always take protections on the code they used, this is true, .net framework did take well protections, but only protecting your application from harming the system, but not protecting your application from crash, remember. So when you application really crashed, some of the debug information may really missleading you.

 

So what is the conditions if we work on C++. when we passed in a path variable into a function, the parameter type is the pointer type in most common conditions. I believe 90% of people which have experience on c++ did know what pointer type really means, a pointer can be invalid when the value is NULL,  so I believe 80% of people will take a good behavior to check the variable if it's valid before they take operation on them. so, the low level attributes of the language force us to take a more step considerations. since we have consider the invalid condition, and then will come along with the corresponding precaution( this precaution defines what behavior the code should take when the  the input is invalid), and this step really improve the stability, robustness of our applications.

 

From above view, some low level languages, such as c++, will make you work more closely with the computer system traits, and you will take a more burden to separate you logic from platform attributes, but only in the situation, since the programmer will take more responsibility to insure the application robustness, this forcing us alway take a good and robust design, and foster a careful and strict programming behavior personally. I think this is the true differences between c++ and most of high level oop languages.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值