[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Pylint false positives

Marko Rauhamaa wrote:
> Some of these chores are heavier, some of them are lighter. But where I
> have used Python, performance hasn't been a bottleneck. It it were, I'd
> choose different approaches of implementation.

The point is that creating a class object every time you want a
closure is pointlessly wasteful. There is *no benefit whatsoever*
in doing that. If you think there is, then it's probably because
you're trying to write Java programs in Python.

> But now I'm thinking the original Java approach (anonymous inner
> classes) is probably the most versatile of them all. A single function
> rarely captures behavior. That's the job of an object with its multiple
> methods. In in order to create an ad-hoc object in Python, you will need
> an ad-hoc class.

An important difference between Python and Java here is that in
Python the class statement is an *executable* statement, whereas
in Java it's just a declaration. So putting a class statement
inside a Python function incurs a large runtime overhead that
you don't get with a Java inner class.