New answers tagged python
6
votes
Accepted
How to deal with constants that are shared between multiple packages?
Putting all constants into one package is a strategy which mostly works for smaller projects, and may be completely sufficient for your case.
However, that approach does not scale well when a project ...
- 192k
2
votes
How to deal with constants that are shared between multiple packages?
I think a good question to ask yourself is how often will I need to update the constants or list of constants? Will I need to add more? If this is expected to change frequently and needed to keep the ...
- 1,506
1
vote
Software Design: Decoupling when highly dependent on a third party library
You create an abstraction lawyer so the rest of your application is coupled with the abstraction lawyer, but not with the library. The implementation of the abstraction lawyer is obviously tightly ...
- 39.7k
7
votes
Accepted
Software Design: Decoupling when highly dependent on a third party library
heard that coupling is a bad thing and should be avoided as much as possible
I think this is overly dogmatic.
In some cases it makes more sense to just accept the tight coupling. This is especially ...
- 2,358
3
votes
Are interchangeable types a security vulnerability? Are they good vectors for attack?
Am I right to assume the latter probably is more secure?
This is the wrong question. First of all, there's no linear scale of security. There are approaches that are more robust to certain classes ...
- 23.9k
1
vote
Design pattern for constructing and linking up objects that form a graph
I don't really follow why you would want to model this kind of data in this way. The most straight forward way to do with would be to create a set of interactions like this:
i0 = ('A', 'B')
i1 = ('A',...
- 23.9k
1
vote
Are interchangeable types a security vulnerability? Are they good vectors for attack?
Am I right to assume the latter probably is more secure?
No, it is not "more or less secure", whatever that means.
If doWhatever interprets x as an sql string and runs it against a database ...
- 192k
4
votes
Are interchangeable types a security vulnerability? Are they good vectors for attack?
If you're calling a Python API, you're already inside the security boundary. This cannot be a meaningful security risk. Only things from outside the program entirely count as security risks. Such as ...
- 10.1k
0
votes
Design pattern for constructing and linking up objects that form a graph
When I see this:
drug_b = Drug("B", [])
I see two problems. B is unaware that it has a drug interaction with A and the idea that A and B interact needs to be recorded twice.
This boils down ...
- 96.1k
0
votes
Is there an approach to keep a large number of conditionals maintainable
Unfamiliar with Python so please excuse any syntax butchering. One way to tackle this is to recognize that you have inputs, conditions, and questions
Inputs are the attributes like age, gender, etc. ...
- 320
0
votes
Is there an approach to keep a large number of conditionals maintainable
self.job= -9
self.age = 17
The age makes sense, number of years alive.
For job, consider adopting
enum
or one of its several competitors.
self.sex = "Male"
self....
- 684
1
vote
Is there an approach to keep a large number of conditionals maintainable
Is there an approach to keep a large number of conditionals maintainable?
Here's two:
It's ok to use Boolean expressions to set Boolean variables
Early returns are ok in languages that have finally ...
- 96.1k
15
votes
Raising new exceptions in Python backward-incompatible?
Yes, it is backward incompatible.
We can debate about whether theoretically it's backward compatible or not. The problem is that while in theory, both theory and practice agree, in practice, they don'...
- 13.7k
10
votes
Raising new exceptions in Python backward-incompatible?
This depends entirely on what you documented as the behaviour of your library. If at one extreme you had explicitly stated in your documentation that
All methods in this library may throw any ...
- 19k
1
vote
Encoding text to image and decoding back to text
Check the screenshot quality first. The simplest solution may be to get a really small bitmap font (e.g. 5x3 pixel), remove all the line breaks and as much whitespace as you can, then render the text ...
- 10.1k
3
votes
Accepted
Encoding text to image and decoding back to text
If your only way of transporting data in a machine-readable way from one system to another is by making screenshots, your idea of using QR codes is surely an approach which will technically work and ...
- 192k
0
votes
How can I use builders for products with incompatible interfaces?
Without delving into details, since builder design pattern is a solution for object creation, an approach using builders can be a viable one with the straight forward implementation of one builder ...
0
votes
Is there a better way to trigger API calls from an on Prem SQL Server without using a job scheduler?
You can read the transaction and run actions accordingly: https://sqlfascination.com/2010/02/03/how-do-you-decode-a-simple-entry-in-the-transaction-log-part-1/
I have made similar approach with mysql ...
- 101
0
votes
Is there a better way to trigger API calls from an on Prem SQL Server without using a job scheduler?
The best way is to:
find the thing that updates the SQL,
make sure that call goes through an API layer,
get the API layer to push an event to a queue,
have your scheduled task application subscribe ...
- 67.2k
0
votes
How to perform consistent hashing on any Python object that works with hash()?
I realise this question is very old, but in python, as far as I know only strings are not session consistent hashes. So you can do something like this. Note that because string hashes are randomised, ...
- 101
0
votes
Dependency resolution of tasks which have crontab information
cron isnt a great way to schedule stuff when you have complex dependencies and logic.
Even complex 3rd party workflow solutions have limitations like the one you describe with airflow.
If you have ...
- 67.2k
Top 50 recent answers are included
Related Tags
python × 1942design × 147
object-oriented × 147
design-patterns × 125
python-3.x × 96
django × 82
coding-style × 74
java × 72
unit-testing × 63
algorithms × 62
architecture × 59
programming-languages × 57
javascript × 56
c++ × 55
object-oriented-design × 55
programming-practices × 53
web-applications × 40
web-development × 39
testing × 38
php × 37
exceptions × 37
functions × 35
c × 32
ruby × 31
api-design × 30