New answers tagged

0 votes

Trigonometric functions calculator

User input Others have mentioned that conio.h is platform specific and outside of the C standard. That's not necessarily a problem per se if the program is not ...
  • 1,948
0 votes

rustymines - a mine sweeping game with a shenanigan

Regarding Board::visit_neighbors I refactored it to using a HashSet rather than a HashMap, ...
5 votes

Python tool to organize downloaded media files

Adding to all answers, you have a really nasty bug: ALL folders are hardcoded. The problem Windows lets you move the location of the following folders: 3D Objects Contacts Desktop Documents Downloads ...
1 vote

rustymines - a mine sweeping game with a shenanigan

I don't have time for a complete review right now, so I will just make some observations. First of all: That's a solid improvement over the already good code you submitted last time! Your main begins ...
  • 424
0 votes

Javascript date / time display

elements.map(x => doubleDigits(x)) Array.map takes a function as an argument. You create a function which just calls another ...
  • 1,104
1 vote

Trigonometric functions calculator

How about some math related feedback? Much non-math issues already covered by others. float vs. double ...
6 votes

Python tool to organize downloaded media files

1. Coding style There's a style sheet called PEP8 ("How to write beautiful code with PEP 8") that is strongly recommended for any Python programmer. Your code violates a few of the ...
  • 458
16 votes

Python tool to organize downloaded media files

I'm sure Peter is a nice guy, but you shouldn't write programs only for him. Use a parametric home directory. Some of your extensions support either case and some ...
  • 53.6k
9 votes

Python tool to organize downloaded media files

PEP-8 This already looks very readable. You use snake_case as per PEP-8 for variables and functions. However, the global constants should be in ...
6 votes

Mathematical expression evaluator (C++)

For a beginner this already quite advanced and well-written code. Improving custom exceptions It's great that you have custom exceptions that derive from ...
  • 35.7k
5 votes
Accepted

Grabbing youtube thumbnails from urls

Prefer constants Rather than defining HD and SD as mutable variable, please prefer constants I think there is a typo in your ...
  • 6,114
1 vote

Trigonometric functions calculator

Minimise use of non-standard libraries #include <conio.h> prevents this program compiling here. But we shouldn't need any libraries other than the Standard ...
  • 60.7k
0 votes
Accepted

Asking multiple choice questions in Python using an API

This is a good beginner project and a good API to practice writing a client. Add type hints to your function signatures. Python has a weak type system, and the more you can do to strengthen it, the ...
  • 53.6k
2 votes
Accepted

Trigonometric functions calculator

Don't use arguments just to declare the variable You have unsigned int getOperation(unsigned int op) then inside the function, you print some strings that don't ...
  • 21.1k
3 votes

Trigonometric functions calculator

It's clear that you care about precision, since your M_PI is specified to 38 (!) decimals. It would take a 128-bit floating point number, aka. "quad precision&...
  • 53.6k
3 votes
Accepted

Tic-Tac-Toe Code

Where to start… tuple assignment ...
  • 32.2k
1 vote
Accepted

General purpose 2D grid

That code is already of utterly high quality for a "beginner" in Rust. I think you should be proud of yourself here! Highlights: you use an initializer function in the constructor! your ...
  • 424
4 votes
Accepted

K&R Exercise 5-11. Modify the "detab" - to accept a list of tab stops as arguments

how to improve it to take it "further?" User input is evil. getstops(char *cp), which should be ...
3 votes

K&R Exercise 5-11. Modify the "detab" - to accept a list of tab stops as arguments

General Observations The code is mostly readable. Command lines may contain flags so the command line processing should check for them. There may be more error conditions that you aren't checking for. ...
  • 19.5k
0 votes

Efficient List comprehension with multiple conditions using shift?

Without even materially changing anything, the indentation of this code is impenetrable, and I had to do this to have any idea what the code is doing: ...
  • 53.6k
3 votes
Accepted

Pick two random cards from a standard deck

There is a bug A return statement is missing when making the recursive call when the same card is picked twice. Don't use recursion to repeat an operation To repeat ...
  • 110k
1 vote
Accepted

Quadratic equation solver using ABC and PQ formula

For one, the special case of a=1 is not very interesting. You could as well remove the branch and just use abc everytime. Instead you could check if a is close to 0 and choose a different formula that ...
3 votes

K&R Exercise 5-10. reverse Polish calculator

Be careful with <ctype.h> functions Look at this code; do you see the bug? int c; ...
  • 60.7k
5 votes
Accepted

Convert integer to Roman numeral string

For a beginner it seems fine. There are some improvements that can be made. The points below are analysis of the given code. Obviously there are examples of simpler implementations - e.g. see answers ...
3 votes

K&R Exercise 5-10. reverse Polish calculator

Comment the prototypes, not the functions I like the overall code organization with main at the top, but I think it's nicer to have brief comments next to the function prototypes rather than near the ...
  • 1,948
4 votes

Split string into same consecutive characters

Nice tidy code, and you've provided a test - that's good. You didn't mention warning options when compiling; I used ...
  • 60.7k
4 votes

Split string into same consecutive characters

Avoid memory allocations, Part 1. Your function takes a std::string_view in input, why does it return a std::string? It would be ...
  • 3,553
3 votes

Split string into same consecutive characters

You could convert the while loop to a for loop: ...
  • 110k
3 votes

K&R Exercise 5-10. reverse Polish calculator

Contrary to popular belief, dividing by zero is not an error in IEEE 754 floating-point arithmetic. By forbidding that special case, you've put extra effort into making the program less useful.
5 votes
Accepted

K&R Exercise 5-10. reverse Polish calculator

General Observations Nice comment block at the top. The comments on the include files are unnecessary. What happens with 2 digit numbers? Example 15 10 *? Avoid ...
  • 19.5k
1 vote

C# Console, Connect 4 Game

Single Level of Abstraction Currently your Main method contains the call to Intro() and then the game loop. It would be easier to understand the code from a high ...
1 vote
Accepted

Simple ISO date, time and datetime implementation

welcome to the Rust community! Your code is quite good. There are a couple areas where the code could be improved, but not by much. It would be helpful if you implement more code for review all at ...
0 votes

Battleships console game - my first code in c++ using classes

Edward's and Martin's answers covered a lot; I agree with the vast majority of their points and won't repeat them here. void Show() and ...
  • 2,707
9 votes

Battleships console game - my first code in c++ using classes

Here are some things that may help you improve your code. Don't abuse using namespace std Putting using namespace std at the top ...
  • 64.6k
4 votes

Battleships console game - my first code in c++ using classes

OverView Good start. I like how you have encapsulate the code into a class. What I don't like is all the work being done in main(). You could split this out into ...
  • 92.1k
1 vote

Android + Kotlin advanced color picker (HSV and RGB)

Reduce nesting of if's, that surround whole method, I suggest you instead use negative if's with return in onDraw. Or you can at least merge them into single if (or combine as I did): ...
  • 1,430
3 votes
Accepted

Drawing a pair of triangular walls for CS50 Mario

Global variables are not called for here. Since it's such a simple program, there isn't a lot of value in pre-declaring your function signatures; just write out the full definitions in order of ...
  • 53.6k
3 votes

Calculator for multiplying price and quantity

General Observations The variable names are generally very meaningful. There is no error checking on user input. Avoid using namespace std; If you are coding ...
  • 19.5k
2 votes
Accepted

Linked List implemented in C++

Defeating namespacing Don't using namespace std; ever! It pollutes your local namespace. If the standard ever added std::Node, ...
  • 32.2k
1 vote

Created a basic User Profile List using an API (React)

I can see it's an older query. I think I can add some more points cause it's a generic quest for newbies. Few standard points to consider if we see how much React/Javascript has evolved in past few ...
2 votes
Accepted

Hangman game succesfully built

PEP-8 First off, as mentioned by GregOliveira in the comments, by PEP-8 you don't need the entire program indented (and indeed, it won't run as written). You do, however, need spaces before/after ...
2 votes
Accepted

Library system in Java with OOP

It is not a good idea to hold a map of books to booleans in this case. Why would we want to store a false when we can just store nothing at all? Use a set instead. ...
  • 53.6k
1 vote
Accepted

6502 Emulator in Rust

This is an attempt at my answer. Since I am not familiar with the 6502, I can only comment on more obvious code smells. I already left a comment under your post regarding clippy; I will therefore not ...
  • 424
15 votes

A Simple Calculator

Variable Names Your variable names need some improvement. When I see x, y, and z, I ...
  • 32.2k
3 votes
Accepted

K&R Exercise 1.22 - "fold" long input lines

I didn't get the expected output - some words were split by newlines, and extra newlines are added after the newlines present in the input: ...
  • 60.7k
6 votes

Card game simulations, with a multithreaded version slower than the single-threaded one

Your multithreaded code is slow because you use Mutex. ...
2 votes
Accepted

Create a Grid From User Input and Change Square Color on Mouse Over - The Odin Project: Etch-a-Sketch

Use prettier and eslint Code auto-formatters are awesome. Try one at https://prettier.io/playground and look into adding it to your build which will make your code easier for other developers to read. ...
  • 2,983
5 votes

Optimize memory and disk usage for sequences of n-bit values

Design review Your requirements are a bit vague; or rather, a bit contradictory. You say you want maximum memory efficiency (in the first paragraph)… but then you say you don’t, really (in the first ...
  • 9,036
4 votes

Optimize memory and disk usage for sequences of n-bit values

You're missing the header includes to provide std::array, std::pair, std::addressof(), ...
  • 60.7k
4 votes

Optimize memory and disk usage for sequences of n-bit values

Consider using a proper compression algorithm Your method saves 25% of storage space, and is relatively simple to implement, but if the goal is to reduce memory and disk usage as much as possible, you ...
  • 35.7k

Top 50 recent answers are included