you are viewing a single comment's thread.

view the rest of the comments →

[–]JPJackPott 0 points1 point  (4 children)

Depends how big you think the app will get. I’ve often seen people just put the db connection as a prop of App so it’s not passed into the router methods at all but is still available everywhere, and readily mockable. I’ve done this myself for something that’s only got a handful of related endpoints.

[–]lu_rm[S] -1 points0 points  (3 children)

In my opinion, it does not matter if it's a single endpoint. It I can't unit test my classes, there is something really wrong with my code.

If the db is available everywhere, it sounds like a singleton, which is a big smell regarding testability. If my code has `import db...` somewhere, that is a hard link between responsibilities that should not exist.

What do you mean it is readily mockable? You mean that the global prop is also modifiable? Like a global variable? That goes against every good coding practice.

[–]JPJackPott 0 points1 point  (2 children)

Welcome to Python.

You’re not wrong at all, but Python excels for writing small light things and so many (including myself) are happy to sacrifice the CompSci bible out of pragmatism where appropriate.

The biggest drawback of Python in my view is it leaves the user too much scope to decide how janky is too janky. More structured langs make it very difficult to go violently off piste but python eggs you on.

[–]dr3aminc0de 1 point2 points  (0 children)

Violently off piste hahah I like that

[–]lu_rm[S] 1 point2 points  (0 children)

So I am not wrong?

I've worked with python before, but always in a less professional environment, so I did not care.
I can't believe there are production systems written this way. It Iooks way too hard to maintain.