3 ms·
I don't understand why people bashing self argument. It's part of best design decisions in python. Methods in languages such Java or JavaScript always have hidd
by h8hawk 8y ago
I don't understand why people bashing self argument. It's part of best design decisions in python. Methods in languages such Java or JavaScript always have hidden argument called 'this'. In js this actually become messy duo to binding of this. In python you can easily find this method is bind to instance of class aka 'self'. It's not always self, It could be cls for classmethods or nothing for static methods.
- wenc 8y agoMost languages have an implicit “this”/“self” which works well. This makes it easy to convert functions to class methods and vice versa without using any editor refactoring features. It also makes it easier to refactor (no need to search and replace every reference to foo within an object to self.foo —- the only time this might be iffy is if there’s a global function foo, but in practice it’s not onerous to handle) Also beginners don’t have to mentally blot out in their heads the self argument when calling a method (“you mean self isn’t the first argument?”). Debug messages are also more consistent (“the debug message says my method needs 1 argument. Isn’t self right there?”) I accept Python’s explicit self for what it is (Python’s philosophy prefers explicit over implicit), and don’t have trouble with it but aesthetically it deviates from most OOP languages out there. It’s a valid choice for practical reasons but I would also say that an implicit “this” is an equally valid choice for aesthetic reasons. Here’s a survey of this/self choices: https://en.m.wikipedia.org/wiki/This_(computer_programming) https://en.m.wikipedia.org/wiki/This_(computer_programming)