67 votes
Accepted

Implementing realloc in C

The code leaves a bad first impression because of how it is formatted. In particular, the extra whitespace between the return type and the function name, and that between the variable's type and its ...
  • 4,449
39 votes
Accepted

Count all vowels in string

An alternative route is to use string.replace() and Regular Expressions to strip everything but the vowels from the string. Then count the length of the resulting ...
  • 24.8k
34 votes
Accepted

Is it Friday yet?

This is improper in a few ways: std::string *weekDays = new std::string[7] {"Sunday", "Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday"}; Not ...
  • 34.8k
31 votes
Accepted

If she floats then she is not a witch like we thought

There are several small things that you can improve: double weight = 0; works fine, but double weight = 0.0; would be more ...
  • 19.9k
29 votes
Accepted

To 'this' or not to 'this'?

First and foremost: Anyway, should performance be always the top priority? Definitely not. Don't write things that are needlessly unperformant, but only be overly concerned with performance when ...
  • 426
28 votes

Count all vowels in string

I'm just wondering if there's an easier way to solve this problem without the big blocky code in the if statement. Well, you could put all of those in an array: <...
24 votes

Dungeon Crawl game for the terminal

Overall, this is really well done. You've missed the usual traps of using magic numbers, not creating structures for related items, and other common things. So nice work! I think it could be improved ...
  • 11.5k
22 votes

Is it Friday yet?

I'll just focus on getMonthValue(): ...
22 votes

To 'this' or not to 'this'?

You don't need fancy logic. Good old closure is good enough here. ...
  • 354
22 votes
Accepted

Simple modern C++ string class implementation

Error handling ...
  • 5,570
22 votes
Accepted

Can I slim this UTF8-encoding program?

Efficient file I/O By default, files opened with fopen() are buffered, meaning that not every call to fread() or ...
  • 35.7k
22 votes

Can I slim this UTF8-encoding program?

log is already declared in <math.h>. You don't need to declare it yourself. In fact, it could be harmful. As stated in ...
  • 54.2k
20 votes
Accepted

Isn't this Interest-ing?

Some minor changes I would recommend: Replace the magic numbers with symbolic constants. It will be easier to modify your program when these rates change. ...
  • 2,629
20 votes
Accepted

Python code that sorts books

It looks good and readable IMHO. For brownie points, you could: modify the structure a bit. Not every LinkedList will contain books. Similarly, not every ...
  • 3,948
19 votes
Accepted

Customization of memory class C++

Try to be more consistent with naming I'm seeing camelCase, PascalCase and snake_case all mixed together. Pick one style and stick with it. Furthermore, I see redundant things in names like ...
  • 35.7k
18 votes

Dungeon Crawl game for the terminal

That's an awesome little game! User experience Before we dive into the code, let's talk about the game itself. Random hangs Sometimes, the executable hangs when I ...
17 votes
Accepted

Living off of chocolate

Just a quick glance. But: ...
  • 92.1k
17 votes

If she floats then she is not a witch like we thought

Bugs You calculate the volume of the sphere incorrectly! Style You misspelled the variable bouyantForce. The constant ...
17 votes
Accepted

Sudoku solution without the use of classes

I see some things that may help you improve your code. Don't abuse using namespace std Putting using namespace std within your ...
  • 64.6k
17 votes
Accepted

Huffman Code in C++

Looks pretty readable and I agree with most of your formatting however there are some things that stand out. using namespace std; Kick this habit before it kicks ...
  • 4,452
16 votes

If she floats then she is not a witch like we thought

char again = '\0'; No need for setting a value. You overwrite it before using anyway. ...
  • 110k
16 votes

Naïve RSA decryption in Python

Simple does not mean fast, so you cannot judge performance based on how simple the implementation looks. Usually the most efficient way to perform a non-trivial task is not also the simplest way to do ...
  • 6,759
15 votes

Is it Friday yet?

bool isLeapYear(const int year) { if (0 == (year % 400) || (0 == (year % 4) && (year % 100))) return true; else return false; } This is nitpicky, ...
  • 683
15 votes
Accepted

Enter my Matrix

I will mostly focus on performance in this review because you have specifically asked for it and the other reviews did not cover it yet. Performance The first thing to do when optimizing for ...
  • 4,240
15 votes

Implementing realloc in C

Generally, malloc, realloc and free are all part of the same library. One of the things ...
  • 281
15 votes
Accepted

Phone Book Program in C++

There are a number of things that could be improved, and I hope you find this list of suggestions useful. Don't abuse using namespace std Putting ...
  • 64.6k
15 votes

Count the frequency of items in an array

Answer to the Performance Issue Anytime there are a list of variables named NAMEi where i is an integer, there is a strong chance that a container such as std::array or std::vector should be used. ...
  • 19.5k
15 votes
Accepted

Implementing a rectangle class

PEP-8 Class names should be CapWords, so instead of rectangle you should have Rectangle. ...
  • 32.2k
15 votes

Value store ("optional" type)

About these assignments As someone who’s been teaching C++ for 15 holy shit, almost 20 years now, I have to say that these assignments are pretty terrible… especially the “vector” one. (To be clear, I ...
  • 9,036

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