Organizing modules and their code
Thomas Passin
list1 at tompassin.net
Sat Feb 4 01:01:45 EST 2023
On 2/4/2023 12:24 AM, dn via Python-list wrote:
> The transform is likely dictated by your client's specification. So,
> another separation. Hence Design 1.
>
> There is a strong argument for suggesting that we're going out of our
> way to imagine problems or future-changes (which may never happen). If
> this is (definitely?) a one-off, then why-bother? If permanence is
> likely, (so many 'temporary' solutions end-up lasting years!) then
> re-use can?should be considered.
With practice, it gets to be more automatic to set things up from the
beginning to more-or-less honor separation of concerns, decoupled
modules and APIs, and so forth. Doing this does not require a full,
future-proof suite of alternative database adapters, for example, right
from the start. On top of everything else, you can't know the future
perfectly. And you can't know enough at the beginning to get every
design and architectural path optimal. You learn as you go.
I have a Tomcat application where I separated the output formatting from
the calculation of results. At the time I wrote only an XML formatter.
A decade later, here comes JSON, and customers are asking about it. I
was able to write a JSON formatter with the same API in about half an
hour, and now we have optional JSON output. Separating out the
formatting functionality with its own API was not an example of wasting
time with YAGNI (You Aren't Going To Need It), it was just plain good
practice that probably didn't even cost me any more development time -
since it simplified the calculation code.
OTOH, you may be just trying to learn how to do the bits and pieces. You
may be learning how to connect to the database. You may be learning how
to make a pipeline multithreaded. You have to experiment a thousand
ways, and in a hurry. Until you learn how to do the basic techniques,
sure, quick and dirty is fine. But it shouldn't be the way you design
your actual product, unless it's just for you and needs to be done
quickly, and will probably be ephemeral.
Why do I get the feeling that the OP was asking about a homework problem?
More information about the Python-list
mailing list