Skip to main content
24 votes
Accepted

FIFO data structure in pure C

None of your QUEUE_* functions validate their input arguments before using them. NULL pointers will be a problem, particularly ...
bta's user avatar
  • 819
24 votes

AsyncDictionary - Can you break thread safety?

The reason why there is no async API for a dictionary is, that all operations on a dictionary are so fast, that there is no need for asynchronicity. For concurrent scenarios there is the thread safe ...
JanDotNet's user avatar
  • 8,598
18 votes
Accepted

Unit testing Video Service class

Welcome to code review and thanks for sharing your code. When writing UnitTests keep in mind that they are documentation. Test code has less restrictions for identifier names. This means that method ...
Timothy Truckle's user avatar
15 votes
Accepted

Triangle area computation and linear transformations

Here are a few of the high- and low-level ideas: too many comments. Remember, comments tend to age and outdate, they need to be maintained as the code changes. And, if they are over-used, they hurt ...
alecxe's user avatar
  • 17.5k
15 votes
Accepted

ExactlyOne extension method

Q&A Is the code readable? ExactlyOne states very clearly what the method is supposed to do. source is null seems odd to me ...
dfhwze's user avatar
  • 14.2k
14 votes
Accepted

indexOf Boyer-Moore String Search algorithm

1. Bug The code in the post does not work! >>> index_of('abba', 'bba') >>> # expected 1 but got None Read on to see how you could have ...
14 votes

Secrets management, operational security, keeping API tokens hidden while streaming

Your main is a classic arrow anti-pattern. You can use guard clauses to make the code flat and easier to understand. Bare excepts are normally not a good idea. Why ...
Peilonrayz's user avatar
  • 44.5k
14 votes

Python strong password validator ( with unit test )

standard libraries are, umm, standard ...
J_H's user avatar
  • 42.1k
13 votes

FIFO data structure in pure C

This looks really nice! Here we go: Is the API well thought and idiomatic? Mostly. For a library as simplistic as this, you probably want to avoid creating a special enum when returning ...
hsdfhsdal's user avatar
  • 131
13 votes

AsyncDictionary - Can you break thread safety?

Threading Design Your implementation has a very intrusive lock for all read and write operations, using the SemaphoreSlim with max concurrency 1. ...
dfhwze's user avatar
  • 14.2k
12 votes
Accepted

Flatten an array of integers in Python

Python normally promotes duck typing, yours is more statically typed. You may want to use yield, as your current code possibly uses more memory than needed. You can ...
Peilonrayz's user avatar
  • 44.5k
12 votes
Accepted

Program to see how many points lie strictly inside a convex polygon

Data types Why not use a simple point struct instead of std::pair<int, int>? It doesn't have to do anything, just a simple ...
hoffmale's user avatar
  • 6,528
12 votes

ExactlyOne extension method

mhmmm... I'm not so sure about this implementation. @dfhwze's points are valid but still, I find it's overengineered. I prefer chaining these two alraedy available extensions that can do all ...
t3chb0t's user avatar
  • 44.7k
12 votes

AsyncDictionary - Can you break thread safety?

It's pretty hard to break something that uses a global lock around everything. So this seems pretty thread-safe. But that doesn't answer the question of why you'd want to use this. Asynchronous ...
Voo's user avatar
  • 525
12 votes
Accepted

Binary Search given sorted array Unit test

BinarySearch The BinarySearch class should be public since it contains utility methods that are generally useful. To do this, ...
Roland Illig's user avatar
  • 21.9k
11 votes
Accepted

Controlling the order of unittest.TestCases

A search for "python sort unit test order in method definition order" got me here, and the documentation isn't particularly useful either ("Function" it says, what is it passed, what is it expected to ...
Keiji's user avatar
  • 225
11 votes
Accepted

Stopwatch dependency for unit-testing

I would not return IStopwatch from Start/Stop/etc. This IStopwatch is not an immutable Value Object, like String for example: it would be easier to set expectations by having just this: ...
Dmitry Nogin's user avatar
  • 6,131
11 votes
Accepted

Building Slack message

I've come back to this question about 4 or 5 times since it was originally posted, started writing up an answer, started doubting my alternative implementation, scrapped it, and then come back about a ...
Dan Oberlam's user avatar
  • 8,049
11 votes
Accepted

Recursive search on Node Tree with Linq and Queue

Reading Material .. any reading material about searching algorithms on trees These are the most common tree walkers: Breadth-First Search Depth-First Search Review There is a bug with IsRoot. Also,...
dfhwze's user avatar
  • 14.2k
11 votes

ExactlyOne extension method

This is for dfhwze as per comment: ...
Jesse C. Slicer's user avatar
11 votes
Accepted

Unit test for a maximum-finding function

I'm not a C++ developer, and can't comment on the details of the code. But I can comment on the test cases and the general style of the code. A good test should be enough to recreate the code from ...
Polygorial's user avatar
10 votes

FIFO data structure in pure C

When you have queued a pointer you can never get that pointer again. It is also very difficult to know when that pointer has been dequeued. This is a recipe for leaks. Instead returning the pointer ...
ratchet freak's user avatar
10 votes

Secrets management, operational security, keeping API tokens hidden while streaming

...
AJNeufeld's user avatar
  • 35.3k
9 votes
Accepted

Simple Unit Test in C

Statement-like macros should normally be wrapped in do...while(0). They should also avoid multiple expansion of arguments. So ...
Toby Speight's user avatar
  • 88.3k
9 votes
Accepted

AsyncDictionary - Can you break thread safety?

If you modify the AsyncDictionary while enumerating its keys/values it throws InvalidOperationException (if the backing ...
Johnbot's user avatar
  • 3,084
9 votes

Mocking pathlib.Path I/O methods in a maintainable way which tests functionality not implementation

Mocking system calls, especially those with side effects (mkdir()), is difficult and error prone. I would rather use a temporary directory for test purposes. This ...
etene's user avatar
  • 461
9 votes
Accepted

Mocking pathlib.Path I/O methods in a maintainable way which tests functionality not implementation

I'm no professional when it comes to testing. But it looks like your code is a perfect example on non-test friendly code. And is why SRP, single responsibility principle is such a big thing. From my ...
Peilonrayz's user avatar
  • 44.5k

Only top scored, non community-wiki answers of a minimum length are eligible