bignose+hates-spam at benfinney.id.au
Mon Aug 6 09:19:26 CEST 2007
rbysamppi at gmail.com writes:
> (In addition, it probably would make the program somewhat slower to
> have an internal class inside every module, and performance is
> important to me, as I'm planning to use this project in a future
This is known as "premature optimisation", and it's harmful. It's
folly to avoid a core part of the language because you're worried
about hypothetical performance issues.
Instead, write your program so that it's easy to understand and
maintain; then, if it's noticeably slow, *measure* the performance
using profiling so you know exactly what is slow; then, and only then,
work on speeding up the slow parts.
> These modules are not going to have full-fledged object construction
> and so forth. I don't want to construct and use objects at all
If that's truly what you desire, you're using the wrong
language. Everything in Python is an object, even if you don't use
> it seems like a waste of time and memory to me to inherit __new__,
> __del__, and so on.
You've stated that you're a beginner to programming, so you probably
are unaware that this statement has no basis in how class inheritance
actually works. The point is that inherited behaviour is implemented
in *one* place, not that it's repeated everywhere.
Moreover, this is a further expression of your tendency for premature
optimisation. You should aim instead to write code naturally (learning
what's natural when you're a beginner), and only once you have
something that *works* should you think about performance issues.
> All that I want these modules to do is to encapsulate varying
> information and behavior for /other/ objects to use.)
This sounds like an ideal case for seeting up a class hierarchy for
this move behaviour.
> But regardless of if it's the "right thing to do", do you all think
> it's an unintended bug?
Do we think what is an unintended bug?
I think if you go out of your way to avoid the class inheritance
system for implementing what looks strongly like a hierarchy of
behaviour, you will have design bugs. Hopefully now that you're
reading this thread, they won't be *unintended* bugs; whether you
*intentionally* proceed with a buggy design is up to you :-)
\ "With Lisp or Forth, a master programmer has unlimited power |
`\ and expressiveness. With Python, even a regular guy can reach |
_o__) for the stars." -- Raymond Hettinger |
More information about the Python-list