必须声明临时变量而不是绑定的原因是什么?

时间:2019-03-05 16:46:00

标签: pharo

在Pharo拥有的所有功能中,metpy.calc.vorticity(u, v, dx, dy)[source] Calculate the vertical vorticity of the horizontal wind. Parameters: u ((M, N) ndarray) – x component of the wind v ((M, N) ndarray) – y component of the wind dx (float or ndarray) – The grid spacing(s) in the x-direction. If an array, there should be one item less than the size of u along the applicable axis. dy (float or ndarray) – The grid spacing(s) in the y-direction. If an array, there should be one item less than the size of u along the applicable axis. dim_order (str or None, optional) – The ordering of dimensions in passed in arrays. Can be one of None, 'xy', or 'yx'. 'xy' indicates that the dimension corresponding to x is the leading dimension, followed by y. 'yx' indicates that x is the last dimension, preceded by y. None indicates that the default ordering should be assumed, which is ‘yx’. Can only be passed as a keyword argument, i.e. func(…, dim_order=’xy’). Returns: (M, N) ndarray – vertical vorticity 声明临时变量的风格确实感觉像应该保留在80年代。声明未初始化的变量然后对它们进行赋值而不是让let绑定有什么好处?

的确,IDE将有助于做出这样的声明,但是我发现删除赋值时很烦人,因为空声明仍会保留在其中。

1 个答案:

答案 0 :(得分:4)

我不知道最初的原因,但是每周使用Smalltalk,我看到很多好处。

  • 它使代码更具可读性。当我们看到一个变量时,通过查看声明的临时变量,我们可以知道它是临时变量还是实例变量。
  • 它定义了变量的范围(例如,因为它只能在块的范围内)
  • 它可以更好地完成代码

我想它也简化了编译器的实现。