69
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 ...
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 ...
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 ...
23
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 ...
22
votes
Accepted
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 ...
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 ...
20
votes
Accepted
COBOL Database Program
ZOMG, that is frightening along so many dimensions.
Disclaimer: Within the last decade I wrote lots of python code to parse production COBOL database record formats. And as an undergraduate I had ...
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 ...
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
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 ...
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 ...
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 ...
16
votes
Accepted
Implementing a rectangle class
PEP-8
Class names should be CapWords, so instead of rectangle you should have Rectangle.
...
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 ...
15
votes
Implementing realloc in C
Generally, malloc, realloc and free are all part of the same library. One of the things ...
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 ...
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. ...
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 ...
14
votes
Accepted
What's the optimal 'pythonic' way to make dot product of two lists of numbers?
The most "pythonic" way of doing this makes use of the sum and zip built-ins:
...
14
votes
Accepted
Vector implementation, which received unhelpful negative feedback from professor
I understand that some of this class is predicated by your professor; However I will review the code as a whole and you can then choose what can be changed and what cannot be changed.
Interface/High-...
14
votes
Accepted
Checking for parentheses balance in C
Bugs
The loop header is wrong:
for(i=0;line[i]!=NULL;i++){
Here, you want to scan until you find a byte with ASCII value 0 (also called an ASCII NUL, and ...
14
votes
Python code that sorts books
A little late here as I just got back in front of a non-mobile device, so let me try to add some new points:
Most importantly (with the caveat that I'm super pedantic), the format of this assignment ...
14
votes
Egg size Prompt Box
The parseInt(eggWeight); calls are not doing anything, because you are not using its return value. And since you aren't using the return value, the comparisons are ...
13
votes
Implementing realloc in C
You are checking if malloc succeeded before calling memcpy, but not before calling memset.
...
13
votes
Checking for parentheses balance in C
The idea is correct, the implementation is not.
Upon exiting the loop you need to test for pilepointer == -1. Otherwise, the strings like ...
13
votes
Egg size Prompt Box
Since you already checked > 69 , if you get to the next else if you don't need to check that it is ...
13
votes
Accepted
Toggle 2 LEDs using a timer XMEGA-A3BU Xplained
The optimizer has a habit of optimizing out my timing loops.
This is (a) a non-surprise, and (b) somewhat of a red flag when it comes to coding practice. If you're writing timing loops that attempt ...
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
homework × 563java × 175
beginner × 127
c++ × 108
python × 94
c × 94
algorithm × 47
performance × 45
python-3.x × 34
object-oriented × 34
strings × 32
array × 27
game × 27
c# × 22
javascript × 17
c++11 × 15
sorting × 15
linked-list × 15
haskell × 14
reinventing-the-wheel × 14
calculator × 14
finance × 14
file × 13
datetime × 11
hash-map × 10