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,538
18 votes
Accepted

Find the first non-repeating character in a string: ("DEFD" → E)

It's easier to do it with LINQ which is in this case virtually a one-liner. ...
t3chb0t's user avatar
  • 44.3k
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

Finding the duplicate with an array with 1,000,000 integers between 1 and 1,000,000

There is already a good answer that describes how you could improve your tests, however, I would like to offer another solution. I had a question that was similar to this on an interview (well, I ...
hacatu's user avatar
  • 462
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.3k
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 ...
dfhwze's user avatar
  • 13.9k
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
  • 43.4k
13 votes

BigInteger formatting for endless tower defense game

Naming Interfaces are usually named starting with a capital I in .NET. ScientificFormatter Here you have ...
Heslacher's user avatar
  • 50.4k
13 votes
Accepted

Mocking UserDefaults in Swift

So first, as CAD97 rightly points out, if you simply define your protocol as identically matching the methods from UserDefaults you intend to use, then making ...
nhgrif's user avatar
  • 25.3k
13 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 ...
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
  • 13.9k
13 votes

Python strong password validator ( with unit test )

standard libraries are, umm, standard ...
J_H's user avatar
  • 29k
12 votes

Find the first non-repeating character in a string: ("DEFD" → E)

Testing more than one thing Looking at some of your tests, you you are testing more than one thing. You are also testing contradictory things. This makes the purpose of your tests less obvious. ...
forsvarir's user avatar
  • 11.7k
12 votes
Accepted

Table Driven Test in Java using Junit4

JUnit 4 has a Parameterized test runner that does most of the work for you. For your tests, it would look like: ...
jonrsharpe's user avatar
  • 13.9k
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
  • 43.4k
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 ...
hoffmale's user avatar
  • 6,498
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.3k
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.3k
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

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
Accepted

Count words in a string

Building Strings with += In your withoutPunctuation method, you are building the String to return by appending each character ...
Tunaki's user avatar
  • 9,233
10 votes
Accepted

Multiple permission checks in web app automated tests

So, thing is, it's GREAT that you made the individual tests. Imagine this method with all those tests inlined. That'd be... really bad. So that part is good. But like you say, something is off. Now, ...
Pimgd's user avatar
  • 22.3k
10 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
  • 7,814
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

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