强/弱打字 [英] Strong/weak typing

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

问题描述

我正在编写Python,好像它是强类型的,从不回收

名称来保存原始类型以外的类型。


这是一个很好的软件工程实践,还是我错过了什么

Pythonic?

I''m writing Python as if it were strongly typed, never recycling a
name to hold a type other than the original type.

Is this good software engineering practice, or am I missing something
Pythonic?

推荐答案

8月1日,5:31 * pm,MartinRineh ... @ gmail.com写道:
On Aug 1, 5:31*pm, MartinRineh...@gmail.com wrote:

我正在编写Python,好像它是强类型的,从不回收

名称用于保存原始类型以外的类型。


这是一个很好的软件工程实践,还是我错过了什么

Pythonic?
I''m writing Python as if it were strongly typed, never recycling a
name to hold a type other than the original type.

Is this good software engineering practice, or am I missing something
Pythonic?



我不确定你的术语是否100%正确。强打字是

而不是重新使用名字。


看看: http://eli.thegreenplace.net/2006/11...yping-systems/


Le Friday 2008年8月1日17:31:25 Ma ************ @ gmail.com ,vousavezécrit*:
Le Friday 01 August 2008 17:31:25 Ma************@gmail.com, vous avez écrit*:

I'm编写Python就好像它是强类型一样,永远不会回收一个

名称来保存原始类型以外的类型。


这是一个很好的软件工程实践,或者我错过了什么

Pythonic?
I''m writing Python as if it were strongly typed, never recycling a
name to hold a type other than the original type.

Is this good software engineering practice, or am I missing something
Pythonic?



正如其他人已经说过的那样,Python是强类型的,事实是

类型的对象嵌入了对象本身,而不是你给的名字

他在一个程序的不同地方。


但实际上你有效地重复使用你的程序中的名字,它'这是

语言的基础。


想想以下几行:


a,b = 0 ,1

a + = b

a,b = b,a


s =" foo"

s = s.upper()


-

_____________


Maric Michaud

As already stated by others, Python is strongly typed, the fact is that the
type of an object is embeded with the object itself, not by the name you give
him at different place in a program.

But in fact you effectively re-use names in your programs, it''s the basic of
the language.

Think of the following lines :

a, b = 0, 1
a += b
a, b = b, a

s = "foo"
s = s.upper()

--
_____________

Maric Michaud


Ma ************ @ gmail.com schrieb:
Ma************@gmail.com schrieb:

我正在编写Python,好像它是强类型的,从不回收

名称保持原始类型以外的类型。
I''m writing Python as if it were strongly typed, never recycling a
name to hold a type other than the original type.



如果它能买到什么东西吗?也许对于流行皮肤或某些未来

to-native-code编译器?

If it buys you anything? Maybe for shedskin or some future
"to-native-code" compiler?


这是一个很好的软件工程实践,还是我错过了什么

Pythonic?
Is this good software engineering practice, or am I missing something
Pythonic?



我会这么说。在函数/方法体中,我重复使用通用名称,例如

数据,计数器等。但我永远不会改变说实例变量为另一个

类型(除了None)。这里适用最少惊喜的原则。


欢呼

Paul

I''d say so. In a function/method body I do reuse generic names like
data,counter,etc. but I never change say an instance variable to another
type (except from None). Principle of least surprise applies here.

cheers
Paul


这篇关于强/弱打字的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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