New answers tagged

0

If not, are there any good alternatives? In my experience, not really. There are a number of different possible compromises; how suitable they are depends on local circumstance. Martin Fowler described a distinction between Public vs Published methods; roughly, there are methods available in the interface that are not officially supported / "reserved for ...


1

Python itself. More specifically string manipulation functions. Most string manipulation functions are expected to work on characters, not bytes, so they need to know which bytes are to be considered as "one character" to work. This is of course a problem in any programming language. The only alternative is for the programming language to assume a specific ...


2

what would we replace browser and validator with? "The python interpreter" When you call .encode()/.decode() method on as string, the encoding defines how the bits in the file gets translated into Unicode characters.


3

Should error codes be named per-struct The granularity of error codes should fit to the existing requirements of the system. Make them as granular as needed to display meaningful error messages, or to detect certain types of failures required for debugging, but not more. If you don't know how granular you need them yet, start with the simpler approach ...


0

Because an instance method is allowed to use self attributes, and in particular modify them, you can't guarantee correctness of an arbitrary memoized instance method. Additionally, your implementation adds an implicit constraint on your object to be hashable, and cache hit depending of that hash, you are limited on classes you can use it on and fields you ...


0

I think the rule design pattern can work here. What you need is a model of the patiences state that doesn't care about the order in which the rules are applied. For example, if you process the rule that aspirin cures fever before processing a rule that causes a fever you end up with a fever when you shouldn't. So instead of fever being a binary state (...


3

To put things into the terms that your book uses: I think you have no problem understanding that the check for a == b is worst-case O(n2). Now in the worst case for the third loop, every a in A has a match in B, so the third loop will be called every time. In the case where a doesn't exist in C, it will run through the entire C set. In other words, it's 1 ...


3

We will assume that no individual sequence contains duplicate. is a very important piece of information. Otherwise, the worst-case of optimized version would still be O(n³), when A and B are equal and contain one element duplicated n times: i = 0 def disjoint(A, B, C): global i for a in A: for b in B: if a == b: ...


64

The book is indeed correct, and it provides a good argument. Note that timings are not a reliable indicator of algorithmic complexity. The timings might only consider a special data distribution, or the test cases might be too small: algorithmic complexity only describes how resource usage or runtime scales beyond some suitably large input size. The book ...


0

The trick of the optimized method is to cut corners. Only if a and b match, c will be given worth a look. Now you may figure that in the worst case you would still have to evaluate each c. This is not true. You probably think the worst case is that every check for a == b results in a run over C because every check for a == b returns a match. But this is not ...


7

Note that if all elements are different in each of the list which is assumed, you can iterate C only once for each element in A (if there's element in B which is equal). So inner loop is O(n^2) total


-2

Think about it this way, some numbers may be in two or three of the sequences but the average case of this is that for each element in set A, an exhaustive search is performed in b. It is guaranteed that every element in set A will be iterated over but implied that less than half of the elements in set b will be iterated over. When the elements in set b ...


2

I would advise against HTTP 400 for syntactically correct (here a 400 would be misleading), but semantically incorrect (aka invalid) request. But that should not be the topic here. The question is more about validation and DRY. I think, there is no golden rule to follow here. If you are doing a modern web application, there is a tradeoff between double ...


0

The dry way would be do handle multiple types of errors from create_record rather than do validation for each different type of validation error there can be. For example try: record = create_record(inputs) catch InputsValidationError: send_400() catch: send_500()


1

Which way you find more readable, the pytruth ot the pytest way propably comes down to what you are used to. If you are used ot Java, you will find that more readable. It is shared with the community to bring an expressive, consistent assertion style to projects that may be using a combination of unittest, abseil, googletest, mox, and mock—especially to ...


0

I see this as a perfect example of using stream processing pipelines such as Apache Kafka (or Apache Flink). The rationale to use them is that you can add as much producers (Java app) or consumers (Python app) as possible. You also do not have to worry about if they work in different speeds as Kafka will buffer it. Before passing the data to Kafka you ...


3

According to the documentation, PyTruth claims to have more informative failure messages than some other widely-used testing frameworks in Python. (This is of course a subjective measure.) Failure messages are very important in unit testing, and even more so in Test-Driven Development, where the failure message actually partially drives the implementation. (...


5

Some of these, particularly 4, 5 and 7 are "clearly" more readable in the fluent truth style - the assertion days exactly what it does, no brainpower required. It is also worth noting that your #7 does not match the truth example: think about what happens if d contains an element foo. Sure, you can fix it, but if you got it wrong writing the question, would ...


1

This is a data normalization problem. You can handle it by adding a specific step to your program to ensure user input is correct and can be aggregated; otherwise, it will return an error. To make an up to date documentation, you can publish a data model in the form of a python file and/or a documentation generated from a data model. Here is an example: ...


0

Well, making inner joins of multiple objects is not what mongo is for. What you are trying to do is to force a SQL object model inside a NoSQL database. You are left with the following options : Denormalizing heavily your model. E.g. getting necessary details of a user inside each comment. Getting group details into every user. This have drawbacks such as, ...


1

Why not just let both apps read from the same database? Or if you cannot do that, you could write the data to S3 with one app and read it from S3 with the other app. The target app can listen to events in S3 for every file which is written and then just load it. Maybe I am oversimplifying it but it seems easy...(?) There is also Snowflake SQL www....


1

I work on big enterprise application on top of Node.js. But I think, the approach can be the same: Have config/default.py config. Here you can define common variables which are env independent. For instance: config/default.py config = { 'app_name': 'Spotify', 'jobs_num': 2, 'host': 'localhost', 'port': 3000 } Then you can have specific ...


0

Others already mentioned the learning purpose of spikes. What is missing is the underlying agile principle of it which is fail fast. One of the pillars in agile development is to recognize the hard parts and go for proof of concepts, see if you can do it at all. The classic way of working your way through all the tasks in some "logical" order may turn out ...


2

There is a quite stablished practice in Extreme Programing called Spike. This means that it is throwaway code. There is nothing special in it. It is just a Sprint in which the expected result is the knowledge about the throwaway code. The above link has enough information about the good practices, pitfalls of spikes. Your specific case of use seems a good ...


Top 50 recent answers are included