0

在创建模型或变量时,网络上是否有不应该使用的项目列表?

例如,如果我想创建公寓列表,将模型命名为类似Property的名称将来会出现问题并且也会令人困惑,因为property它是一个内置的 Python 函数。

我确实尝试过用谷歌搜索这个,但什么都想不出来。

谢谢!

4

3 回答 3

1

一般来说,编程语言有“保留词”或“关键字”,你要么不能使用,要么在某些情况下应该远离它们。对于 Python,您可以在此处找到该列表。

于 2012-06-24T00:09:43.313 回答
1

关于命名的规则和约束取决于编程语言。标识符/名称的绑定方式取决于语言语义及其范围规则:标识符/名称将根据范围绑定到不同的元素。作用域通常是词法的(即静态的),但有些语言具有动态作用域(lisp 的一些变体)。

如果名称不同,则范围界定不会混淆。如果标识符/名称在跨范围内重复使用,则标识符/名称可能会掩盖另一个。这称为阴影。这是混乱的根源。

某些保留名称(即关键字)具有特殊含义。可以简单地禁止此类关键字作为其他元素的名称,也可以不禁止。

For instance, in Smallatalk self is a keyword. It is still possible to declare a temporary variable self, though. In the scope where the temporary variable is visible, self resolves to the temporary variable, not the usual self that is receiver of the message.

Of course, shadowing can happen between regular names.

Scoping rules take types into consideration as well, and inheritance might introduce shadows.

Another source of confusion related to binding is Method Overloading. In statically typed languages, which method is executed depends on the static types at the call site. In certain cases, overloading makes it confusing to know which method is selected. Both Shadowing and Overloading should avoided to avoid confusions.

If your goal is to translate Python to Javascript, and vice versa, I guess you need to check the scoping rules and keywords of both languages to make sure your translation is not only syntactically correct, but also semantically correct.

于 2012-06-26T07:29:42.403 回答
0

根据上下文,大多数自然语言中的大多数单词都可以具有不同的含义。这就是为什么我们使用说明符来明确单词的含义。如果在任何情况下您认为某些特定标识符可能会造成混淆,您可以添加一个说明符以使其清晰。例如ObjectProperty,可能与房地产无关,即使在处理房地产的应用程序中也是如此。

您提出的案例与使用没有附加上下文的通用标识符没有什么不同。例如,一个名为limitor的变量length在不同的程序中可能具有完全不同的含义。只需使用有意义的标识符并广泛记录其含义即可。在您自己的代码库中保持一致也是可取的。不要用永远不会完整的禁止术语列表使您的生活复杂化,只会使编程变得更加困难。

明显的例外是您选择的编程语言保留的字词 - 但是再一次没有像样的编译器允许您使用它们......

于 2012-06-24T00:11:34.590 回答