Skip to main content
The 2024 Developer Survey results are live! See the results
30 votes

Perl CGI script to serve a PDF file

I will go through your code line by line and give feedback. We will skip the general advice on don't use CGI as it's actually suited for what you are trying to do here. I wrote this answer in two ...
simbabque's user avatar
  • 993
25 votes
Accepted

Explicit song lyrics checker

I recommend practicing Python 3 rather than Python 2 these days. According to PEP 8, isClean() should be is_clean(). One or ...
200_success's user avatar
25 votes
Accepted

Transcode UCS-4BE to UTF-8

Efficient file I/O By default, files opened with fopen() are buffered, meaning that not every call to fread() or ...
G. Sliepen's user avatar
  • 58.9k
24 votes

Transcode UCS-4BE to UTF-8

log is already declared in <math.h>. You don't need to declare it yourself. In fact, it could be harmful. As stated in ...
vnp's user avatar
  • 56.8k
22 votes
Accepted

92 Spoons AI, sort of an AI in C++

There's a lot to say here, so let's not waste any time and jump right into it: You said that you didn't want to hear the using namespace std;-drill, but ...
Ben Steffan's user avatar
  • 5,228
21 votes

Explicit song lyrics checker

Splitting line into words using words = line.split(" ") will only split the line on space ...
AJNeufeld's user avatar
  • 33.9k
16 votes

92 Spoons AI, sort of an AI in C++

Here are some things that may help you improve your code. Don't abuse using namespace std I know you said you don't want to hear this, but your code is unusable ...
Edward's user avatar
  • 66.5k
16 votes

Explicit song lyrics checker

Some suggestions: Using argparse to parse arguments is preferable to any kind of interactive input, because it means that it's much easier to automate and ...
l0b0's user avatar
  • 8,917
16 votes
Accepted

A simple error messaging and logging system via macro(s) in C++

You’ve already noted that this could be done better without macros, so I won’t belabour the point. I will note, though, that your goal—“to refresh [your] skills at writing good solid macros”—makes ...
indi's user avatar
  • 12k
15 votes

Markov chains to generate text

Functions Split the code into functions, also split the generation and the presentation. Your algorithm has some clear distinct tasks, so split along these lines: read input assemble chain construct ...
Maarten Fabré's user avatar
15 votes

Program that finds the longest word not containing one of the disallowed characters

I see a number of things that may help you improve your program. Fix the bug There is a subtle bug in the original implementation. It contains these lines: ...
Edward's user avatar
  • 66.5k
15 votes
Accepted

Average spam confidence

Not duplicating any of @Peilonrayz's code review points ... Stop reading entire files into memory when you can process the file line by line in one pass, and stop creating huge lists in memory which ...
AJNeufeld's user avatar
  • 33.9k
13 votes

Read file into vector<byte>

Nice: using bytes = std::vector<std::byte>; I would call it Bytes to make it clear it is a type rather than an object. ...
Loki Astari's user avatar
  • 95.5k
13 votes

Transcode UCS-4BE to UTF-8

This program reads 4 byte codepoints (in BIG ENDIAN) from a file strictly called "input.data" and creates another file called "ENCODED.data" with the relative encoding in UTF8. Needless to say, ...
Maarten Bodewes's user avatar
12 votes

Reading a DHT11 to a file

Here is a list of things I would improve: define constants in upper-case (PEP8 reference) put the main program logic into the if __name__ == '__main__': to avoid ...
alecxe's user avatar
  • 17.3k
12 votes

92 Spoons AI, sort of an AI in C++

Header files You have a lot of implementation code in that header file (files.h). Header files should only contain the function or class headers, the implementation should go into an extra cpp file. ...
Raimund Krämer's user avatar
12 votes

Comparing two large binary files in C

fread (tmp1, sizeof *tmp1, readsz, fp1); fread (tmp2, sizeof *tmp2, readsz, fp2); count += 16; if(memcmp(tmp1, tmp2, readsz)){ … } You are discarding the ...
200_success's user avatar
12 votes

Basic C copy file implementation

You test the return value of fwrite, which is good. However, fread may fail as well. Since ...
vnp's user avatar
  • 56.8k
12 votes

Average spam confidence

I think ask_file_name looks fine without using pathlib. The difference between the two comes down to LBYL vs EAFP. For the most ...
Peilonrayz's user avatar
  • 43.4k
11 votes

Creating index to a file in C

Magic Numbers Don't write things like if (a <= 90 && a >= 65) { /* A = 65, Z = 90 */ if you can just write ...
Ben Steffan's user avatar
  • 5,228
11 votes

Python code that compares two files byte by byte

The code in the post calls os.path.getsize for each block read from the two files. This could be avoided by remembering the value in a local variable. The code ...
Gareth Rees's user avatar
  • 49.6k
11 votes
Accepted

A minimal CLI password storage and retrieval manager

I would pinpoint the major problems in the code which I would address first: do not manually handle provided command-line arguments - there is a great built-in module for it - ...
alecxe's user avatar
  • 17.3k
11 votes
Accepted

Most common words in a text file of about 1.1 million words

This is actually quite good. Good use of the collections module. One improvement I can think of is switching to the ...
Ludisposed's user avatar
  • 11.6k
11 votes
Accepted

CSV file reader in PHP that supports large files (>15k lines)

Performance As performance is your main concern, let's face this first. To complete the example CSV-file with ~36k lines your original script needs around 139s*. The main bottlenecks are ...
insertusernamehere's user avatar
11 votes

Perl CGI script to serve a PDF file

...
choroba's user avatar
  • 1,393
11 votes
Accepted

Counting relevant entries in a large bioinformatics file

In order to speed this up, you'll need to avoid as many string creation operations as possible, because they are expensive. Especially the split operation is expensive. Not only does this create many ...
RoToRa's user avatar
  • 11.3k
11 votes
Accepted

Comparing two large binary files in C

I'm trying to read two sufficiently large binary files, comparing them and printing the offset at which they differ. compare_two_binary_files() is faulty for ...
chux - Reinstate Monica's user avatar
11 votes
Accepted

Basic C copy file implementation

Prefer Symbolic Constants Over Magic Numbers There is a header file that should be included, stdlib.h, that provides some standard symbolic constants such as EXIT_SUCCESS and EXIT_FAILURE. It might ...
pacmaninbw's user avatar
  • 24k
11 votes
Accepted

A utility to swap two files

file1_path == file2_path surely tells that paths refer to the same file. However, even if file1_path != file2_path they still ...
vnp's user avatar
  • 56.8k
11 votes

Robust program to write an array of certain data type to a binary file and read back from it (C++17)

using namespace std; Don't do using namespace std;. It can lead to name collisions and other issues. Typing out the full names (...
user673679's user avatar
  • 11.8k

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