Stack Exchange Network

Stack Exchange network consists of 174 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [comparative-review]

This tag is used for questions which present a problem and multiple solutions, where the asker wishes to know which solution is best (and why).

0
votes
0answers
10 views

Implementing carryless multiplication using normal multiplication

In carryless multiplication the partial products are XORed (ie addition without carry) together rather than added normally. The partial products themselves are still the product of a power of two (...
0
votes
0answers
18 views

Five functions to get the digits of a number

I'm writing a simple function: given a number, it will return a sequence or a collection of the digits in the number (in the correct order). i.e ...
1
vote
0answers
40 views

Evaluation of a variation of quick-sort (pivot-selection)

Below is a variation of quick-sort where-in the pivot selection is based on calculating the average of the values of the highest and lowest numbers. ...
3
votes
0answers
62 views

Bridge-Pattern or Entity-Component-System

I want to learn how/when/why to use the GoF Design Patterns. These last days are dedicated to the Bridge Pattern, which means: Decouple an abstraction from its implementation so that the two can ...
5
votes
1answer
73 views

process data with numpy seems rather slow than pure python?

In my opinion, Vectorization operation with numpy should be much faster than use for in pure python. I write two function to get and process data in a csv file, one in numpy and another in pure python,...
3
votes
2answers
58 views

Word ladders program in Python

Background information: Given two different strings of equal length, the spacing between them is the number of other strings you would need to connect them on a word ladder. Alternately, this is 1 ...
1
vote
2answers
35 views

Lowest open space in memory

I am writing a simple compiled programming language. Everything but the bytecode interpreter can run as slow as possible, but I would like the interpreter to fun fast, because that's why I made it ...
4
votes
5answers
91 views

Leap year determination using guard clause

I have a function to check the leap year as follows ...
2
votes
3answers
62 views

Speed up weighted average for Leela Chess Zero

Problem: Given a vector of about 40 values m with normal error sd compute the weighted average of the values weighted by the ...
1
vote
3answers
62 views

Printing a table of letter frequencies using Python

What is the recommended (standard, cleaner, more elegant, etc.) method in Python to get a string with all the alphabet letters? Here's three versions of code to generate a dictionary with keys as ...
0
votes
1answer
37 views

CodingBat warm up: conditionally prepending “not” to a string

I solved this CodingBat problem: Given a string, return a new string where "not " has been added to the front. However, if the string already begins with "not", return the string unchanged. Note: ...
2
votes
1answer
56 views

2D Matrix with jagged array isn't faster than one with a multidimensional array

I was trying to use Math.Net's dense matrix class. But, it doesn't support int. So, I have to create a wrapper for a jagged 2d array. I knew that jagged arrays ...
7
votes
3answers
946 views

Reversible tax calculator class

I have a class that contains 2 properties of the same type. decimal NetAmount and decimal GrossAmount I would like to ...
3
votes
1answer
65 views

Given a list of words, remove the shorter word of every pair

This is not a "please do my homework" question. I solved a problem two ways and would like to know which solution is better; better being defined by better readability, lower complexity and lower ...
2
votes
1answer
34 views

PHP Factory Pattern : Should I use `create()` or `__invoke()`?

I currently had a colleague reviewing my code and he had a comment on a factory class I created. It's very simple: ...
1
vote
1answer
53 views

Longest Collatz sequence in Scala

I am trying to find the longest Collatz Sequence: Which starting number, ≤ N, produces the longest chain? If many possible such numbers are there print the maximum one. (1 ≤ N ≤ 5×106) I tried ...
10
votes
1answer
83 views

Counting times a file was committed to Git

A long time ago I implemented some code to walk the git commit graph. I recently updated the accompanying analytics part of the code base to follow file moves/renames in order to get a more accurate ...
1
vote
2answers
62 views

Classic “100 doors” simulation in Clojure

I read this question about the "100 Doors" puzzle, and thought that it would make for a good quick exercise. I ended up with two implementations. The first is more straightforward and uses a vector ...
2
votes
2answers
91 views

Image resizing in Rust

Are there Rust features I could apply to optimize for simple test of a JPEG or PNG resized from 2000 x 2000 pixels to 150 x 150 pixels? ...
8
votes
3answers
313 views

Processing player's move in an ASCII rogue-like game

I'm making an ASCII roguelike game and while writing the code for processing the player's move I can't decide between these two options. I have defined a class named ...
1
vote
1answer
26 views

JS/Node.js .env loader

I needed an environment values loader for a random node project, and instead of just using dotenv, decided to just make one myself and see how it'll turn out. To make this meaningful, here's a rough ...
5
votes
2answers
721 views

Remove the first value for a doubly linked list

You need to remove the first element which contains a given value from a doubly linked list. I created two solutions since I find the edge case of removing the first element to be problematic. So I ...
2
votes
1answer
183 views

n choose k combination in JavaScript

I was asked to solve a problem for \$\binom{n}{k}\$. I did the following implementation and am wondering if there's any feedback. Input: n = Integer ...
1
vote
0answers
49 views

Message loop handler functions, using associative array and using switch

I am using the Windows API to register system-wide hotkeys. This requires a message loop to be created, and a handler to handle the hotkey messages. I have written two pieces of functioning code. The ...
3
votes
3answers
84 views

String comparator as a lambda

I am writing a Comparator for my TreeMap. It looks like this: ...
-2
votes
1answer
63 views

Forward call to method depending on runtime type [closed]

I'm currently trying to build a in-memory read model on application startup. Therefor I use an event store that returns the event data as json. In my read model class there are handler methods for ...
7
votes
4answers
493 views

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

I've written some simple helper functions that read data types from a vector of bytes (binary files) and having a tough time deciding which route to go. Method 1 : reinterpret_cast ...
4
votes
2answers
73 views

Assigning several variables from request URL using regexes

I refactored some of my code: Summary: This implementation works with PSGI/Plack. It gets the URL from $env->{PATH_INFO} and assigns a different variable ...
-1
votes
1answer
47 views

Check Unique Chars in A String

Two solutions to check if a String contains unique characters. Wanted to know if these solutions can be optimized further. The Code: ...
5
votes
1answer
103 views

Reading a config file in python

We're wanting to read data in from a config file and provide it to other python modules in a helpful way. We have found a number of ways to accomplish this that range from the module being easy to ...
3
votes
1answer
52 views

PHP function to evaluate comparisons between two values, with debug logging

The following method works fine but it is rather verbose: ...
1
vote
3answers
79 views

Given a series of characters from stdin, print their squared integer ASCII counterparts

This program in essence is extremely simple, however, it can be written in many different ways. I'm a beginner at C and I've written it in 5 different variations (mostly differing in the use of ...
4
votes
2answers
86 views

ASP.NET HTML code generation, two approaches

I was asked to give more context. So here we go. We want to create some HTML in code behind to add an "add" and a "refresh" button to a grid view header column. Approach #1 does this using string ...
2
votes
2answers
369 views

String Swap-case one-liners (6 ways)

I did this small project where there are six one-liner anonymous methods that can swap case of a given string of any length. For example "heLLo, woRLd" ==> "HEllO, WOrlD". I used this string as the ...
4
votes
1answer
60 views

Three versions of a counting-up timer in JavaScript

I made 3 versions of a counting-up timer in JavaScript: Version #1 All units of time (seconds, minutes, hours, and days) are updated every second, whether they change or not. Pro: Shorter code. ...
4
votes
0answers
111 views

Parallel solutions to N Queens Puzzle

I'm trying to increase the performance of my N Queens Puzzle solution. I'd find some threads on SO already but they don't appear to help me to increase performance. My best solution, however, is a ...
3
votes
3answers
77 views

Transforming XML with null checks vs variables

I'm working on an Spring Integration application that transforms a XML (converted by Jaxb) into a custom Object by checking various information given in the XML. The problem is that I can't trust ...
0
votes
1answer
144 views

Refactoring a class / map of query parameters that are passed between layers

There is an interface: interface JournalCreator { @Async Journal create(Parameters params); } And many different implementations: ...
0
votes
0answers
26 views

Processing RabbitMQ messages with Processors from another system / Interface Segregation

I was reviewing a app that runs as a service and processes messages form RabbitMQ. The app processes the messages using Processors retrieved from another system. ...
0
votes
0answers
32 views

Dispatching calls to user-selected tests

In my codebase I often create structs containing const char* and std::function. In doing so, I can then put these ...
0
votes
0answers
113 views

RGB to HSV image conversion with CUDA, with branching and branchless versions

I have created two CUDA kernels for converting a 3 channel 16-bit RGB image to a 3 channel 16-bit HSV image. The first kernel below performs the usual algorithm in a fairly straight forward manner as ...
3
votes
0answers
30 views

Validating a collection of proxy servers with maximum possible throughput

I am validating a collection of proxy servers and trying to achieve the maximum possible throughput. I've tested a few different methods, such as Task.WhenAll, TPL ...
2
votes
1answer
921 views

Substring vs Split performance test

Some people are telling me that using string.Split is very inefficient since it creates a lot of arrays in the heap. So, what are the alternatives if its real? The challenge? Taking a large string ...
3
votes
2answers
362 views

Python Find the N adjacent digits in the 1000-digit number that have the greatest product

This question was presented to me, adapted from Project Euler #8. The goal is to find the N adjacent digits in the 1000-digit number that have the greatest product. Range of N: 10 <= N <= 50. ...
5
votes
1answer
1k views

MessageFormat.format() with named parameters

I was looking for how to use MessageFormat.format() in Java with named parameters, as a similar option exists in Python, and found this question. Some functions are ...
6
votes
1answer
95 views

Two versions of PDF-Selector

I have basically ended up with 2 versions of a PDF-Selector. Both versions do the same thing. I'm not sure which solution is better. Maybe someone could give me a code review. I use: PDFSharp-Nuget-...
0
votes
1answer
45 views

Null checking a generic type [closed]

Assuming I have a method with this signature public void DoStuffWith<T>(T foo) and I want to allow both structs and classes to be passed as ...
10
votes
0answers
198 views

Testing a list of proxies for validity concurrently

I have a class that tests a list of proxies for validity concurrently, which I have created in 2 different ways, one utilizing Parallel.ForEach and the other using a TPL Dataflow ActionBlock. I am ...
6
votes
2answers
335 views

Counting ambiguous Morse Code encodings, with and without Java Streams

Unique Morse Code Words International Morse Code defines a standard encoding where each letter is mapped to a series of dots and dashes, as follows: "a" maps to ...
4
votes
4answers
1k views

LeetCode “Jewels and Stones”: counting certain characters in a string

LeetCode "Jewels and Stones" You're given strings J representing the types of stones that are jewels, and S representing the stones you have. Each character in S is a type of stone you have. ...