5 ms·
I think that goes against the python dogma of "Explicit is better than implicit." In #1 and #2 there is no question about where 'x' comes from, while in #3 it c
by lojack 10y ago
I think that goes against the python dogma of "Explicit is better than implicit." In #1 and #2 there is no question about where 'x' comes from, while in #3 it could be a class variable or a global variable or from just about anywhere.
- fnl 10y agoAgree. Even better, though: # 4 def length(): return math.sqrt(.x**2 + .y**2 + .z**2) Ambiguity and "pseudo-keyword" are both gone! [EDITED code for better readability]
- pyrale 10y agoIf you mind with self being too bloated, you can already change it to what you like. The `self` is merely idiomatic. def length(s): return math.sqrt(s.x**2 + s.y**2 + s.z**2) The beauty with self in Python is that self is not at all magic : it merely indicates that the object instance you're using will be passed as first argument of the class method. Also you can get a custom font with typographic ligatures (e.g. for self, lambda, and so on) in order to make it more visually appealing. For instance (self > 圖) : def length(圖): return math.sqrt(圖.x**2 + 圖.y**2 + 圖.z**2)
- blauditore 10y agoHuh, I experience python as quite the opposite of "Explicit is better than implicit": - No static types - A variable might belong to the scope of a method, object or class, depending on where it was first set and changed afterwards - Implicit execution of code on import of a module (__init__.py, including parent packages) - Any object is truthy or falsey, i.e. conditional statements don't require an explicit boolean
- lojack 10y agoI suppose "dogma" was the incorrect word in that case.
- sweeneyrod 10y agoYou can get the "Python dogma" with `import this`. "Explicit is better than implicit" is part of it, but so is "practicality beats purity" (and "There should be one-- and preferably only one --obvious way to do it, although that way may not be obvious at first unless you're Dutch").