Do you use the get/set pattern (in Python)?

后端 未结 8 1963
长情又很酷
长情又很酷 2020-12-12 13:25

Using get/set seems to be a common practice in Java (for various reasons), but I hardly see Python code that uses this.

Why do you use or avoid get/set methods in Py

8条回答
  •  無奈伤痛
    2020-12-12 13:58

    Here is what Guido van Rossum says about that in Masterminds of Programming

    What do you mean by "fighting the language"?

    Guido: That usually means that they're trying to continue their habits that worked well with a different language.

    [...] People will turn everything into a class, and turn every access into an accessor method,
    where that is really not a wise thing to do in Python; you'll have more verbose code that is
    harder to debug and runs a lot slower. You know the expression "You can write FORTRAN in any language?" You can write Java in any language, too.

提交回复
热议问题