3 ms·
From the perspective of a python programmer, I must say this is an interesting list. I'm rather convinced by your points on print and public. On the other hand
by j88439h84 8y ago
From the perspective of a python programmer, I must say this is an interesting list. I'm rather convinced by your points on print and public.
On the other hand,
"__name__ == __main__" is just a convenience for debugging and small scripts. I wouldn't use it in real programs.
I dont use @staticmethod, or find it useful. If I want a function, I use a function.
- lou1306 8y ago> I dont use @staticmethod, or find it useful. If I want a function, I use a function. In principle, it makes sense to "bundle" functions that are strictly related to a class within the class itself (i.e. as static methods). Of course, the benefits viz. top-level functions are only noticeable if your codebase is big enough.
- j88439h84 8y agoWhat are those benefits?
- lou1306 8y agoOf course it's just better organization of the codebase and a less-polluted namespace. Also, if you're writing a library, it may affect the API you give to the user. If you move a function to a static method, the end user only needs to import the desired class. But again, they are "usability" benefits. I'm no CPython expert but I don't think that a static method would have noticeably worse (or better) performance than a function.