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).

Filter by
Sorted by
Tagged with
1
vote
0answers
51 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
93 views

String comparator as a lambda

I am writing a Comparator for my TreeMap. It looks like this: ...
-2
votes
1answer
67 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 ...
8
votes
4answers
2k 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
77 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
49 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
2k 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
55 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
84 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 ...
5
votes
2answers
127 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
445 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
68 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
221 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
84 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
146 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: ...
3
votes
0answers
32 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
4k 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
843 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
3k 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
99 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 ...
11
votes
1answer
330 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
628 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 ...
5
votes
4answers
3k 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. ...
4
votes
3answers
552 views

Sub that compares 2 columns fast

This is an answer to this SO question: Vba comparing 2 columns of data. In that question the OP code is very slow (also not working properly but the problem is fixed) I spent some time to ...
1
vote
1answer
110 views

Translating a Haskell data to Python

I've been working on a project in python, and I needed to represent a certain numeric type. I need to represent the concept of some or all. Then I need to be able to add these amounts. Coming to ...
4
votes
3answers
426 views

Using an offset variable to keep track of the next item in a Rust array

I am using an offset variable to track the iteration position, and modifying / returning it. Is the below considered bad practice in Rust? I ask this because I don'...
7
votes
1answer
151 views

Counting occurrences of “A…Z” substrings

I'm trying to write code in the simplest and cleanest way possible. I've found a few ways to shorten and simplify my code through functions that I've never seen before or through using other methods. ...
2
votes
2answers
162 views

Click-through rate calculator using jQuery

I created a calculator for CTR with jQuery. The calculator is working just the way I want, but I'm quite new to jQuery and I wonder if I am using jQuery effectively. The goal of the code is that if ...
3
votes
1answer
993 views

JavaScript Blackjack game

I am learning javascript with the course Javascript Getting started by Mark Zaymota. Currently the code is in a script.js file, and I was wondering how could we refactor it to extract classes from it....
3
votes
1answer
584 views

XML design for parsing in C# [closed]

I am trying to design XML with configuration info so I can parse it into this code: ...
0
votes
0answers
14 views

Hiding and repositioning some elements for some WordPress posts

I have to gather a few posts (a Wordpress site) and I need to hide some elements and move some others. There are 2 simple ways to do this, which one of these is better if there is a better one and why?...
1
vote
1answer
5k views

onChange vs onKeyPress for input in React

I have an input form, and when you press enter I want it to call a function. I was wondering what "the right" way of doing this is. Right now I have an input looking like this: ...
3
votes
1answer
116 views

Trigonometric Subplots with Matplotlib

The code consists of 4 functions that result in a figure with 3 subplots: a sine wave a cosine wave and the superposition of both (a bichromatic wave). I have shown in 4 ways, the first two are ...
1
vote
0answers
39 views

Fetching student and teacher data from a given date range

I have two APIs which fetch data of teachers and students from a given date range. I am using forkJoin to get both APIresponse and display the data with a regular interval of 10 ms. This is working ...
2
votes
1answer
103 views

Monad Transformers

I've run into the same scenario involving Monad Transformers a few times now, and I'm looking for some "best-practice" advice. Bear with the introduction, the issue itself is really simple: Say you'...
-5
votes
2answers
467 views

9 ways to generate Fibonacci numbers in C++

This is C++ code that consists of 9 different functions that generate Fibonacci numbers. Although all functions display same result, the emphasis is on practice to use different methods or ways. I ...
5
votes
3answers
771 views

6 ways to find maximum value in C++

This code is part of a project of N-ways to code for one particular task. In this case, this C++ code consists of 6 different functions to return a maximum value from an array of real numbers. Mainly ...
2
votes
0answers
61 views

Composing commands to control virtual machines

I created a function which takes some inputs and builds a specific set of strings. The function is working as intended, however I can't help thinking how ridiculous it looks every time I see it. I ...
5
votes
1answer
293 views

Flask Framework - user sign in

These functions are more or less the same. They are doing the sign in process for a flask application. A user is retrieved from a database (identified through email address) and the password is ...
1
vote
3answers
743 views

Merge sorted lists, removing duplicates

I want to merge two sorted lists of Integers but this is not the general mergesort case because the same number may appear in both lists. (However, each number can only appear once in a particular ...
4
votes
2answers
1k views

Semantic markup for card blocks

I'm using Bootstrap. I'm doing my best to work with more semantic markup and getting away from divitis. Several of these "card" blocks appear on a page, like this. Original: ...
16
votes
4answers
8k views

20 Ways to do Random Sampling

Here is a (small project) code for practicing Python, it comprises 20 variety of functions that each works to return \$n\$ random samples from a set of data. The code mostly uses the ...
11
votes
2answers
3k views

Parsing an email string

My program needs to parse an e-mail string. There are two possibilities to enter an e-mail-address. Either with the alias or without one, plain the e-mail-address. 1st possibity: ...
-3
votes
1answer
52 views

Difference between using WHERE and AND with ON in SQL [closed]

I have a Sql query ...
6
votes
1answer
87 views

Class to clean CSV data so that processed results can be written into a database

I am trying to figure out whether I am following best practices while passing arguments to functions. These are my class definitions (Please note, that I have just provided the high level ...
3
votes
1answer
180 views

Calculate change denominations 3

I am trying to refactor a large application to use more DDD principles as and when I get chance. I am concentrating on the very simple areas first. The app currently has a very simple Domain Service ...
1
vote
2answers
58 views

Linked lists of templated classes vs function ptr

I am designing a library for a hierarchical problem. At each stage of the hierarchy there are several "tools" at hand. If at a state N one tool succeeds, the solution is passed to the next (N+1) state....
0
votes
2answers
3k views

Remove all html special chars

Before saving the input from users in the database, I am using the below function to replace all HTML special chars. All my users will always be using the English Language. Option 1 ...
-1
votes
1answer
3k views

string null check/ trim [closed]

Minor question on String null check and trim. // given a function func() that might return either a string or null String func() { return " hello "; } ...