23 votes
Accepted

Avoiding repetition when using the "snprintf idiom" to write text

@vnp's code is solid and helpful, but his stringify_state_helper is a single-purpose function, and still leaves a degree of repetition and memory management in <...
  • 33.2k
12 votes

Conversion of hexadecimal string to string

I don't think there is a built-in method. Yours is pretty good but we could make some improvements: Parameters should be camelCase => hexString. You should favour ...
  • 16.7k
12 votes

Numbers to byte-arrays and back

First of all, I agree with others, you could replace lines var size = 4; var requiredSize = 8; with ...
  • 4,579
12 votes
Accepted

Decoding assembly instructions in a Game Boy disassembler

I have some ideas about how you might be able to improve your program. Avoid problems Rather than trying to deal with the problem for every instruction, one approach is avoiding it entirely. One ...
  • 64.9k
11 votes
Accepted

Simple Generic output for Deserializer

Here are a few remarks. I'm not perfect or write perfect code but I hope these tips will help write better code: Naming consistency: It would be easier to understand if the names of your two methods ...
  • 5,553
11 votes
Accepted

Conversion of hexadecimal string to string

The method does two different things and thus should be split in two: Interpret a hex string as a sequence of bytes. You can find many possible implementations at How do you convert Byte Array to ...
  • 2,670
11 votes

Converting a SecureString to a byte array

Although you have done a decent job, you could do this in a better way, without even to use unsafe. First thing to mention, you should always use braces ...
  • 50.1k
11 votes
Accepted

Save and load the state of a role-playing game using Pickle

Comments You have #Player Class and #Enemy Class as comments. Comments should be used to clarify something that may otherwise ...
  • 3,777
11 votes

Avoiding repetition when using the "snprintf idiom" to write text

Consider factoring it out into a function: ...
  • 54.4k
10 votes
Accepted

Optimize a generic foreach method that converts Datatable to my object using Reflection

A few points tickle: Why is it a static method? None of the comments are helpful. Good comments say why, not what. I'd remove them all. Bracing is inconsistent. ...
10 votes

Menu to save and load football team information

DRY Let's start with your methods arsenal(), astonVilla() and so on. From the title of the question, I think you're already ...
  • 5,724
10 votes

Numbers to byte-arrays and back

I don't find many things to complain about :-) but this bothers me... I would change the name of those variables: var requiredSize = 4; var size = 4; to ...
  • 44k
10 votes
Accepted

Format of hexeditor

I've just got a few little tips for this tiny little program: Use consistent spacing. You mostly have a = b, but in one place you have ...
  • 5,473
10 votes
Accepted

Reading bytes from packet

One things for certain... an array of tuples which is basically being used as a glorified dictionary is never going to suffice as an acceptable data model. Moreover, an array of bytes isn't really ...
  • 25.2k
10 votes
Accepted

Serializing objects to delimited files

readonly will not make members of your static serializers readonly. While you cannot reassign another serializer to replace it, its members can still be modified. ...
  • 3,126
10 votes
Accepted

Writing a bitmap image from C++

Not bad! Let's go through it line-by-line. typedef unsigned char BYTE; This is fine, but just so you know, starting from C++17, there is a ...
  • 9,431
10 votes
Accepted

Serializing (nested) data structures in a human-readable format

A few things I noticed: Since supported is a superset of singles I would recommend the following assignment: ...
  • 3,443
9 votes

Structure to ByteArray Extension

I haven't used it, however all of the documentation seems to suggest that you need explicitly free the memory allocated through: ...
  • 11.6k
9 votes
Accepted

reinterpret_cast vs bit shifts for extracting 32-bit integers from bytes, with either endianness

You are correct to be concerned about the first method. It generates UB if buf[offset] doesn't happen to be at the right alignment boundary for a 32-bit value. The ...
  • 9,431
9 votes

Avoiding repetition when using the "snprintf idiom" to write text

The GNU libc already provides asprintf, which avoids exactly the repetition you are concerned about. I haven't looked at the solutions of other operating systems (...
  • 21.1k
8 votes

Rendering an HTML form based on a specification in a string

Before we start, take a look at this comment of yours. It's a prime example of why you shouldn't always trust the comments. ...
8 votes
Accepted

A tiny library for textual serialization of lists in Java

Factory is a terrible name for a class. What does it make? As best as I can tell, it doesn't make anything, it just de/serializes. Honestly, I don't think you even ...
  • 5,473
8 votes

Format of hexeditor

This has been thoroughly answered already I'd say, but I'll have a go regardless... You're loading 2 files (I don't know why, but I'll roll with it), and doing the same things with both. That calls ...
  • 32.9k
8 votes
Accepted

Packing and unpacking bits

Bug The swap<T>() method isn't doing what you think it does, because the passed in T obj1, T obj2 aren't passed with the <...
  • 50.1k
8 votes

Parsing shorts from binary file and finding the closest and furthest points

Given that this was for an interview I'll refrain from saying that Javadoc is missing. private static final Point closest = new Point(-200, 300); That's a ...
  • 7,642
8 votes

Converting std::chrono::time_point to/from std::string

Headers and typenames We're missing ...
  • 62.9k
7 votes

Simple Generic output for Deserializer

string fuleFullPath will be a mistake. you should check at DeserializeToObj if the file exists. If it doesn't you should throw ...
  • 50.1k
7 votes
Accepted

Writing data into an image

First off, you seem very confused with your whitespace. In Python, you shouldn't have "padding" around the contents of braces, {[()]}. For example, the line, ...
7 votes
Accepted

Fastest De-/Serialise struct in .Net

Naming Interop should be treated as a single word like in System.Runtime.InteropServices. You should also not name a class the ...
  • 16.7k
7 votes
Accepted

Numbers to byte-arrays and back

I agree with @t3chb0t, looks pretty good. Except... var resultNumber = sourceArray.ToInt32(); var expectedNumber = 0x7F00FFBF; ...

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