David Hammen
  • Member for 6 years, 7 months
  • Last seen more than a week ago
  • Houston, TX
5 answers
80 votes
8k views
Guessing a number, but comments concerning
19 votes

Your code is missing several very important comments. Some of the comments you do have are lies, others are trivial, yet others don't say what you should be saying. The most important comment of all (...

View answer
8 answers
20 votes
6k views
First solution to FizzBuzz
12 votes

Two of the key sins in software engineering are scope creep and gold plating. Scope creep is a sin committed by clients and managers. Gold plating is a sin committed by programmers. This is a perfect ...

View answer
5 answers
8 votes
3k views
Find longest lines from a file
Accepted answer
12 votes

This is a bug: else if( record.size() > hash_table.rbegin()->second.size() ) As implemented, insertion stops once your program encounters the longest line in the file. For example, suppose ...

View answer
6 answers
9 votes
4k views
Length of a C string, capped to some maximum
8 votes

The inline keyword has been a keyword in C since C99. Use it! Inline functions are a much better option than macros. Macros are beasts from the previous millennium. Let them rest in peace. The ...

View answer
4 answers
8 votes
17k views
Kelvin-Fahrenheit-Celsius temperature converter
8 votes

If you want to have this conversion as a class, I'd suggest following Morwenn's advice. The posted implementation suggests a very different kind of implementation. The converters set but never access ...

View answer
4 answers
3 votes
979 views
isRotation and isSubstring method
5 votes

char s3[len2*2]; ... s3[len2*2] = '\0'; The above declaration is incorrect. You need to allocate one more character for the null character at the end. You are adding that null character, but you are ...

View answer
2 answers
12 votes
1k views
Gravitational Brute Force N-body Algorithm
Accepted answer
4 votes

You didn't show the value you are using for parameters.law. Given that you used this in the function getDistance, I strongly suspect you are doing it wrong. You either shouldn't have called the ...

View answer
2 answers
4 votes
1k views
C++ Stack implementation using std::list
Accepted answer
4 votes

std::list<int> myList (n); This does not do what you think it does. It creates a list of n elements. If you're using C++11, they're all garbage because those n elements are default-initialized. ...

View answer
4 answers
8 votes
8k views
"Largest power of two less than N" in Python
4 votes

I frequently miss the edge cases like while num or while num > 1. You did that here. What if num is 0 or 1.75? You'll get a TypeError when your function performs num >>= 1 in the case num is 1....

View answer
1 answers
1 votes
79 views
Using custom aliases for physical units
Accepted answer
3 votes

My question is, are there any downsides to this? There's a huge downside. One is that the compiler does not enforce your units. Your type names are aliases. You could pass a variable of type newton_t ...

View answer
4 answers
11 votes
7k views
Next bigger number with the same digits
3 votes

I would have attacked this a bit differently than the other answers. def next_bigger(num) : Minor nit: I would have used a different name for this. next_permutation perhaps. More important is what's ...

View answer
2 answers
4 votes
1k views
Calculating sum of primes using the CPU and GPU
2 votes

It's not surprising that your serial code is faster than your GPU code. You are not taking advantage of the places where GPUs perform exceptionally well, and you are using the GPU in exactly the ...

View answer
3 answers
6 votes
849 views
View programming pattern in C++ without raw pointers
Accepted answer
1 votes

Lesser item first: class View { public: View() = delete; View(const View&) = delete; View(View&&) = delete; View operator=(const View&) = delete; View operator=(View&...

View answer
2 answers
2 votes
13k views
Sorting dates (DD/MM/YYYY) with insertion sort
1 votes

Major critiques: There is no need for your ConvertToWord function. The problem statement does not say to do that. Your ConvertToWord is gold-plating. (Aside: Your implementation has flaws.) Replace ...

View answer
2 answers
3 votes
72 views
Adding and subtracting Matrices based on condition
1 votes

Overall comments: No comments! You should comment some of your code. You should always have a function-level comment that describes what function does. While the code itself should be self-...

View answer
3 answers
3 votes
107 views
Matrix class with lots of tiny methods
0 votes

That's taking things a bit too far. I attacked the problem you pointed me to in this way: def read_matrix (fd) : m, n, steps = [int(x) for x in fd.readline().split()] arr = [[int(x) for x in ...

View answer