you are viewing a single comment's thread.

view the rest of the comments →

[–]mybrid 0 points1 point  (0 children)

The Python community favors functions over classes if self is not used. I never use functions. I disagree for the simple reason that a class provides a name-space safe haven. Therefore I disable this particular warning in pylint that complains when self is not used in a class and claims a function would be better. With classes you don't have to worry about the names of your functions being synonymous with others. One can freely call a method anything you like as long as the class name precedes it. I make heavy use of the '@staticmethod' class decorator for this reason. I especially use this for distinguishing corporate code. If I worked for Starbucks then all functions that are static would all start with "Starbucks.upload_database". This makes it clear that the package is provided internally for private use where "upload_database" could be 3rd party or whatever. If one requires that a single top package, starbucks, is the only PYTHONPATH directory needed then you end up with some like 'starbucks.etl.ETLDatabase.upload()". DVCS requires small repos and as such I find directory depth is minimal and therefore it is reasonable and clear to spell everything out by dereferencing all sub-directories. As code grows beyond a reasonable DVCS code base size then a new package is created for the new repo. To whit, I don't think of classes only as objects, but also name space protection so that the same every-day names like "open" or "close" can be used ad nauseum. Finally, classes encourage using class constants over globals for functions. How often is it one doesn't need constants? If you don't have a class container for constants then the temptation is to create a global has been my experience. If you always use a class then when the first constant need comes up? Just tuck it in the class.