Re:Python中的类型检查支持? [英] Re: type-checking support in Python?

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

问题描述

En Mon,2008年10月6日11:19:58 -0300,Joe Strout<jo*@strout.netescribió:

En Mon, 06 Oct 2008 11:19:58 -0300, Joe Strout <jo*@strout.netescribió:


最后,我有一件事我们考虑采用一些标识符前缀

表示类型。也许是iFoo对于整数,fFoo浮点数

数字,d对于字典,l对于列表,t对于元组,o对于

对象,以及v对象对于可能超过上面

之一的变量类型。我(从短短几天的浏览中)收集到这样一个

命名约定在Python社区中并不常见,但是这里有其他人吗?它?我宁愿采用一个现有的标准

(即使它没有被广泛使用),也不愿意做一个。
Finally, one thing I''ve considered is adopting some identifier prefixes
indicating type. Maybe "iFoo" for integer, "fFoo" for floating-point
numbers, "d" for dictionary, "l" for list, "t" for tuple, "o" for
object, and "v" for variable types that may be more than one of the
above. I gather (from just a couple days of browsing) that such a
naming convention isn''t common in the Python community, but is there
anyone else here who does it? I''d rather adopt an existing standard
(even if it''s not widely used) than make one up.



除了其他人所说的明智之词之外,我会补充一点,当他们仅仅标识符前缀时,我看不到

点表示类型 (在
Python意义上甚至更广泛的意义上) - 被称为系统匈牙利表示法

一些人。

相反,在apps匈牙利表示法中使用的前缀声明

种类或意图变量,在某些情况下可能有用。

这似乎是查尔斯西蒙尼在写论文时的原意[1];这两种方法之间的差异在这里讨论

[2]。

例如,在我国的石油工业中有一个混合的

常用的测量单位。深度以米为单位测量,但以英寸为单位泵送b $ b行程;以磅为单位加载,但压力以kg / cm2为单位。因此,跟踪哪个变量代表哪个单位非常重要

- 它的类型将是

总是浮动,并且没有信息;但它的单位*是*重要的

信息,所以我有时会使用后缀来表示。

变量名称应该*有意义* - 在自动粘贴

" f"或i或i。或m_事物的前缀,想想你从中获得了什么。如果

您总是使用应用程序中的字符串表示街道地址,

" szAddress" (或sAddress)除了

地址之外,不再向您提供任何信息。单独,所以前缀是没用的。


[1] http://msdn.microsoft.com/en-us/library/Aa260976.aspx

[2] http://blogs.msdn.com/ericlippert/ar ... / 12 / 52989.aspx


-

Gabriel Genellina

Apart from the wise words that others have said, I''d add that I see no
point in identifier prefixes when they merely indicate "type" (in the
Python sense or even a broader sense) - called "system Hungarian notation"
by some.
In contrast, the prefix used in "apps Hungarian notation" declares the
"kind" or "intent" of the variable, and it may be useful in some cases.
This appears to be the original intent of Charles Simonyi when he wrote
his paper [1]; the differences between both approaches are discussed here
[2].
As an example, in the oil industry here in my country there is a mix of
measurement units in common usage. Depth is measured in meters, but pump
stroke in inches; loads in lbs but pressures in kg/cm2. So it''s important
to keep track of which unit some variable represents - its type would be
always float, and that carries no information; but its unit *is* important
informacion, so I sometimes use a postfix to indicate that.
Variable names should be *meaningful* - before automatically sticking an
"f" or "i" or "m_" prefix to something, think what you gain from it. If
you always represent a street address using a string in your application,
"szAddress" (or "sAddress") don''t give you any more information than
"address" alone, so the prefix is useless.

[1] http://msdn.microsoft.com/en-us/library/Aa260976.aspx
[2] http://blogs.msdn.com/ericlippert/ar.../12/52989.aspx

--
Gabriel Genellina

推荐答案

在消息< ma ************************************* *@python.o rg>,Gabriel

Genellina写道:
In message <ma**************************************@python.o rg>, Gabriel
Genellina wrote:

例如,在我国的石油工业这里有混合使用

常用的测量单位。深度以米为单位测量,但以英寸为单位泵送b $ b行程;以磅为单位但压力以kg / cm 2为单位。
As an example, in the oil industry here in my country there is a mix of
measurement units in common usage. Depth is measured in meters, but pump
stroke in inches; loads in lbs but pressures in kg/cm?2.



是不是正确处理每个数字附加尺寸的方法?

Isn''t the right way to handle that to attach dimensions to each number?


On 7 Ott,08:36,Lawrence D''Oliveiro< l ... @ geek-

central.gen.new_zealandwrote:
On 7 Ott, 08:36, Lawrence D''Oliveiro <l...@geek-
central.gen.new_zealandwrote:

在消息< mailman.2089.1223358567.3487.python-l ... @ python.org> ;,加布里埃尔


Genellina写道:
In message <mailman.2089.1223358567.3487.python-l...@python.org>, Gabriel

Genellina wrote:

例如,在我国的石油工业中,通常使用的是混合的b
测量单位。深度以米为单位测量,但以英寸为单位泵送b $ b行程;以磅为单位加载,但压力以kg / cm2为单位。
As an example, in the oil industry here in my country there is a mix of
measurement units in common usage. Depth is measured in meters, but pump
stroke in inches; loads in lbs but pressures in kg/cm2.



处理每个数字的维度是不是正确的方法?


Isn''t the right way to handle that to attach dimensions to each number?



你能负担得起避免浮动和整数吗?附加后缀是

最好的内置类型。

在C ++中,可以在编译时检查尺寸( http://www.boost.org/

doc / libs / 1_36_0 / doc / html / boost_units。 html)适度增加

繁琐,但Python需要非常重量级的类

包含一个值及其尺寸并替换所有需要的

函数和操作。


问候,

Lorenzo Gatti

Can you afford to avoid floats and ints? Attaching suffixes is the
best one can do with the builtin types.
In C++ one can check dimensions at compile time (http://www.boost.org/
doc/libs/1_36_0/doc/html/boost_units.html) with a modest increase of
cumbersomeness, but Python would need very heavyweight classes
containing a value and its dimension and a replacement of all needed
functions and operations.

Regards,
Lorenzo Gatti


En Tue,10月7日2008 03:36:12 -0300,Lawrence D''Oliveiro

<ld*@geek-central.gen.new_zealandescribió:
En Tue, 07 Oct 2008 03:36:12 -0300, Lawrence D''Oliveiro
<ld*@geek-central.gen.new_zealandescribió:

在消息< ma ************************************** @ python.o rg> ,Gabriel

Genellina写道:
In message <ma**************************************@python.o rg>, Gabriel
Genellina wrote:

>举个例子,在我国的石油工业中有一个混合的/> measurem常用单位。深度以米为单位测量,但泵的行程以英寸为单位;以磅为单位加载,但压力以kg / cm2为单位。
>As an example, in the oil industry here in my country there is a mix of
measurement units in common usage. Depth is measured in meters, but pump
stroke in inches; loads in lbs but pressures in kg/cm2.



处理每个数字的维度是不是正确的方法?


Isn''t the right way to handle that to attach dimensions to each number?



也许,但我更喜欢这些值是普通的浮动对象。在我的情况下,它是

而不是单位本身是动态的:这个文件格式的深度为

英尺,那个一个人用米,但从一开始就知道了。我想如果它们是动态的,我会将单位附加到值,我必须完全重现

原始格式,但还没有发生(幸运的是) 。


-

Gabriel Genellina

Maybe, but I prefer the values to be plain float objects. In my case it''s
not that units are dynamic themselves: "this" file format has depth in
feet, "that" one uses meters, but that''s known from start. I think I''d
attach units to values if they were dynamic and I had to reproduce the
original format exactly, but hasn''t happened yet (fortunately).

--
Gabriel Genellina


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

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