News for hackers. Stuff that matters.
Re:The use of `class` for things that should be simple free ... by Laremere on Thursday May 28, 2020 @03:01AM (#23334328)
I believe you describing at least one of two cases: 1. There are multiple methods on the object (not counting constructor) 2. There are arguments passed to the methods.

Either of these cases are different from the provided example: The example will only ever compute a single value per object, always returning that value from a single method with no arguments (other than self).

Re:The use of `class` for things that should be simple free ... by twic on Thursday May 28, 2020 @03:48AM (#23334615)
Right. I think the article is talking about one very specific case, which is apparently common amongst novice C++ programmers, where there is a single computation, whose only inputs come from the constructor, and which gets done in a method.

There are plenty of cases where it makes sense to wrap a function in an object, but the point of the article is that this isn't one of them!

Re:The use of `class` for things that should be simple free ... by mehrdadn on Thursday May 28, 2020 @03:04AM (#23334347)
Not necessarily. What I said can apply to even a class with with 1 method that takes no arguments... though you might often recognize it as a more sophisticated kind of iterator:

  class BFS(object):
    def __init__(self, origin): self.origin = origin; ...
    def next(self): ...