类型检查 [英] type checking

查看:51
本文介绍了类型检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是一个Python新手。我已经使用c ++ 5年了,之前我用
编程Pascal。关于python

让我烦恼的一件事是动态类型,因为我发现自己在编译时在编译器处拾取了C ++下的那种排序错误。

br />
时间。使用Python我必须等待错误在运行时出现在

命令中才能让我纠正它。我发现这效率低下。任何关于

如何解决这个问题的建议都将受到赞赏。

解决方案

10月12日星期日2003 15:56:19 +1300,文章

< bm ********** @ lust.ihug.co.nz> ;, sashan写道:
< blockquote class =post_quotes> [...]让我烦恼的关于python的一件事情是动态打字,因为我发现自己犯了印刷错误,这种错误会在C ++下被提取出来。编译器编译时间。


问问自己静态类型检查需要花费多少,而不是多少动态类型错误需要花费你多少b
$ b动态类型错误。如果您的答案需要静态类型检查,那么
Python对您来说不是一个好选择。

任何有关如何解决此问题的建议都将受到赞赏。




Python,Smalltalk和其他语言的设计没有静态

类型检查。绕过这种设计决策可能非常困难或不可能。


On Sun,2003年10月12日15:56:19 +1300 ,sashan< ma *** @ operamail.com>

写道:

我是Python的新手。我已经使用c ++ 5年了,之前我用Pascal编程。让我烦恼的一件事是关于python
是动态类型,因为我发现自己在编译器编译时会在编译器拾取C ++的那种类型的印刷错误。使用Python我必须等待错误出现在运行时才能让我纠正它。我发现这效率低下。任何有关如何解决这个问题的建议都会受到赞赏。




就个人而言,我发现我很少在Python中犯这些错误。

正确的数据类型在任何情况下都不保证具有正确的

值。


在Python中,错误主要是通过编写清晰的代码(以便很难发出非明显的错误)来避免并通过测试来检测(

是检查要求是否是唯一的方法符合)。


还有其他自我一致性检查方案,例如

按合同设计,虽然它们可以运作,但对您来说可能效果很好

在运行时而不是编译时间。


如果你真的需要静态打字(而不是只需要

习惯了改变),Python简直是选择

语言。无论是Java,C#还是Delphi都可能是一个不错的选择。

-

Steve Horne


史蒂夫九点儿fsnet dot co dot uk


Quoth Stephen Horne<


I''m a Python newbie. I have been using c++ for 5 years and before that I
was programming in Pascal. The one thing that annoys me about python
is dynamic typing because I find myself making typographical errors of
the sort that would under C++ be picked up by the compiler at compiler
time. With Python I have to wait for the error to appear at runtime in
order for me to correct it. I find this inefficient. Any advice about
how to get around this would be appreciated.

解决方案

On Sun, 12 Oct 2003 15:56:19 +1300, in article
<bm**********@lust.ihug.co.nz>, sashan wrote:

[...] The one thing that annoys me about python
is dynamic typing because I find myself making typographical errors of
the sort that would under C++ be picked up by the compiler at compiler
time.
Ask yourself how much static type-checking costs you versus how much
dynamic type errors cost you. If your answer demands static type-checking,
Python is not a good choice for you.
Any advice about
how to get around this would be appreciated.



Python, Smalltalk, and other languages are designed without static
type-checking. Getting around this kind of design decision can be
exceptionally difficult or impossible.


On Sun, 12 Oct 2003 15:56:19 +1300, sashan <ma***@operamail.com>
wrote:

I''m a Python newbie. I have been using c++ for 5 years and before that I
was programming in Pascal. The one thing that annoys me about python
is dynamic typing because I find myself making typographical errors of
the sort that would under C++ be picked up by the compiler at compiler
time. With Python I have to wait for the error to appear at runtime in
order for me to correct it. I find this inefficient. Any advice about
how to get around this would be appreciated.



Personally, I find that I rarely make these errors in Python. Having
the right datatype is in any case no guarantee of having the right
value.

In Python, bugs are primarily avoided by writing clear code (so that
it is hard to make non-obvious errors) and detected by testing (which
is the only approach that checks whether the requirements are met).

There are also alternative self-consistency checking schemes such as
design-by-contract that may work well for you, though they do operate
at run time rather than compile time.

If you really do need static typing (as opposed to simply needing to
get used to the change), Python is simply the wrong choice of
language. Either Java, C# or Delphi may be a good option for you.
--
Steve Horne

steve at ninereeds dot fsnet dot co dot uk


Quoth Stephen Horne <


这篇关于类型检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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