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
2 votes
3 answers
83 views

Returning the other value of boolean enum

I have a class with a "mode" state. There are currently two modes and we are not likely to add more in the future. The class has a CurrentMode property, ...
user avatar
  • 171
0 votes
0 answers
64 views

Vanilla JavaScript Email Obfuscation Defenses Against Bots [closed]

I have been using Cloudflare's Email Obfuscation for a while now but the JavaScript file loaded was causing a pretty substantial increases in Total Blocking Time and Time to Interactive. Then after ...
user avatar
  • 235
-2 votes
1 answer
49 views

Insert row into database using static or non-static method [closed]

I would like to know if there are any benefits of one of the following 2 methods which insert an object into a database The first function calls the Model method statically, creating a new instance of ...
user avatar
2 votes
1 answer
50 views

Batching method implementation - Scala

I need to implement a function/method that operates on a sequence of values, and acts kind of like takeWhile, but with 2 differences, first, it doesn't act on a single element, it is performed on a ...
user avatar
  • 121
1 vote
1 answer
70 views

Categorise amount into "small", "medium" and "large"

I have a super simple function that returns a text label for a range of the input ...
user avatar
  • 275
3 votes
3 answers
188 views

A refactored payment service, handling several payment schemes

I was asked to refactor a class, to make it adhere to SOLID principles, with testability and readability. I thought I had done a decent job, only my feedback was: a) Unnecessary introduction of ...
user avatar
  • 140
3 votes
0 answers
110 views

Return a 2D matrix from a C++ function in Python: ctypes versus pybind11

I found two ways in which I can use a custom C++ function (returning a 2D matrix) in Python. One approach that uses the Python module ctypes and another that uses the Python module pybind11. Approach ...
user avatar
2 votes
0 answers
132 views

What is better - using SerialPort with or without await/async methods?

I'm having an implementation using SerialPort in C# using Visual Studio 2019. I'm using it in a Windows Application, using .NET Framework 4.7.2. When I open and ...
user avatar
1 vote
1 answer
36 views

Constructing routes from imported URL constants

There is a file created with the project paths in a dictionary. Example: ...
user avatar
  • 113
1 vote
1 answer
41 views

Comparing two general LCA algorithms in Java

Now I have two algorithms solving a problem: given a general (multi-way) tree, and any array of node names, find the the node that is the deepest common ancestor. ...
user avatar
  • 25.3k
0 votes
2 answers
58 views

Draw a triangle of stars

I decided to try to write half a pyramid of stars using programming because I wanted to see if I could do it, and I did it. However after comparing it to other people's solutions I started doubting ...
user avatar
  • 119
0 votes
1 answer
48 views

Time complexity of several methods of reversing a domain name string

Note: I'm aware of this existing post which is similar. However, it does not address all my questions sufficiently. I have the following three functions, all of which do the same thing: reverse a ...
user avatar
3 votes
1 answer
276 views

Python function to output a string that is justified to the right

I just solved this exercise from Think Python, 2nd edition: Python provides a built-in function called len that returns the length of a string, so the value of len('allen') is 5. Write a function ...
user avatar
3 votes
2 answers
111 views

Retry read/write until all bytes are transferred or error occurs

Currently I have a wrapper function for the read/write system calls, the purpose of which is to eliminate partial transfer ...
user avatar
3 votes
1 answer
215 views

Format an integer with space as thousand separator

I need to format a number with space as thousand separator in my Java code for Android. How can these functions be improved? What are the pros and cons to the first recursive method? What are the ...
user avatar
1 vote
1 answer
80 views

Show progress bar for different states

I have this working code which shows the progress bar based on different states ("not-started", "progressing" and "done"). Each state will have its own class. I notice it ...
user avatar
1 vote
1 answer
102 views

Comparing a prefix tree against a HashSet of strings in Java

Here, I have made an attempt to find out whether a prefix tree is any more efficient than a simple java.util.HashSet<String>. See what I have: ...
user avatar
  • 25.3k
2 votes
0 answers
43 views

Python: How to best create a dictionary from another dictionary in a library

I have the following code which builds up a dictionary of endpoints that I iterate through later on. Is this the cleanest, most scalable and performant way? I was thinking of adding a list as a key to ...
user avatar
  • 351
0 votes
0 answers
60 views

Leetcode #462 (Minimum Number of Arrows to Burst Balloons), with and without optimization

I have an interesting optimization and I want to get some confirmation on whether it's valid: I was solving Leetcode #452: Minimum Number of Arrows to Burst Balloons (description in footnote [1]) and ...
user avatar
  • 243
4 votes
3 answers
88 views

Destructuring with map and assigning to a constant

I don't know exactly what to name this, but I was refactoring a code snippet and looking at this constant users I thought I'd do this destructuring: Before: ...
user avatar
  • 369
1 vote
1 answer
82 views

Java: Using one class or algebraic data types to model different state?

I'm creating a tool to analyze a card game which is played by three players. A Card is associated with a number of points and looks like this: ...
user avatar
0 votes
0 answers
32 views

Should I replace this request queue?

I just found myself hacking around the limitations of a backend that aborts highly concurrent transactions by queueing the requests using Solution A. I don't like this solution very much, and have a ...
user avatar
0 votes
1 answer
66 views

2 ConvertToBase3 methods with great disparity of execution time

I have two methods to do the same thing: convert a number to ternary. ...
user avatar
  • 109
0 votes
2 answers
133 views

c++ Most clean way to implement duplicate Binary Search Tree for complex type

I have tried to make my own implementation for a BST task I was given for a complex type (Transaction), that should be able to store duplicate values as well. However, I am not sure if I have gone ...
user avatar
2 votes
2 answers
108 views

How can I optimize this pairwise Euclidean distance search algorithm?

x and y are two-dimensional arrays with dimensions (AxN) and (BxN), i.e. they have the same number of columns. I need to get a matrix of Euclidean distances between each pair of rows from x and y. I ...
user avatar
1 vote
0 answers
43 views

Higher-order function to do throttling, written two ways

I have used below method for throttling which is a Higher Order Function (HOF), but find some difficulties to choose which one is better way to write it. Below are both methods. return of the ...
user avatar
  • 141
0 votes
0 answers
56 views

Multiple flatMap style: Nested or sequential?

This question applies to any language with flatMap -- e.g. functional languages -- but I'll use an example in JavaScript. I'm working my way through Functional Programming in JavaScript, which is a ...
user avatar
  • 101
0 votes
3 answers
201 views

C# 'out' keyword in JavaScript [closed]

Since I met the out keyword in C#, I'm trying to find an equivalent in JS. So, please take a look at the code and leave your opinions or suggestions about this. C# ...
user avatar
0 votes
2 answers
68 views

List of objects inside same model vs Factory vs Service [closed]

I am creating a simple Country class. This Country have list of know countries. we can get the list of known countries Country.AllCountries, ...
user avatar
-1 votes
3 answers
83 views

Populate a color table in XCB

This function has 16 repeated calls to the same function, passing in the same handles to each: ...
user avatar
0 votes
1 answer
55 views

Convert string to 10 character string with leading zeros if necessary

I have the below data and am obtaining the expected output column for it. ...
user avatar
  • 149
2 votes
1 answer
189 views

=PRINTF("{1} - {2}", ... ) in Excel without VBA - LAMBDA functions with variable number of arguments

The TEXTJOIN function has a really nice interface: =TEXTJOIN(delimiter, ignore_empty, text1, [text2], …, [text252]) ... where ...
user avatar
  • 1,998
1 vote
2 answers
80 views

Comparison of 2 different ways of writing Merge Sort Algorithm

I have recently learned Merge Sort algorithm in C++ with 2 ways of writing it. 1st Way: ...
user avatar
  • 11
2 votes
3 answers
74 views

URL & HTML encodings on pagination

I wrote this Pagination Section. It shows links to pages 123456789 and so on on SERP (Keyword Search Result Pages). Like you see on Google SERPs. Even though they work, I'm not sure I finished them to ...
user avatar
5 votes
5 answers
663 views

Comparing 2 distinct sieve of Eratosthenes algorithms in Java

In this post, I will present and compare two distinct algorithms for sieve of Eratosthenes: com.github.coderodde.math.prime.PrimeFinder ...
user avatar
  • 25.3k
3 votes
3 answers
125 views

Comparing 8 different Disjoint-Set data structure variants in Java

The Wikipedia page on Disjoint-Set data structures presents \$4\$ distinct algorithms for finding the root node of the tree, and \$2\$ distinct algorithms for performing the union operation. In this ...
user avatar
  • 25.3k
1 vote
0 answers
37 views

Graph stored as adjacency list or as endpoints and intervals

I tried speeding up my Graph class, so I removed the Node class and Edge class, and decided to use arrays and ArrayLists. My 2 implementations seem very similar, ...
user avatar
1 vote
2 answers
105 views

Search for text in a file

I have this implementation of Grep where I use re.search: ...
user avatar
0 votes
0 answers
39 views

Chain the same Runnable using Handler in Android

Which approach to creating repeating Runnables is better? ...
user avatar
1 vote
1 answer
208 views

Which of these two Vuetify Navigation Drawer prevent prop mutation workarounds seem better?

I am very new to Vue.js, I just stumbled on a very hard thing to do (at least for me) where Vue was complaining about mutating a prop (children shouldn't change parent props apparently). I was about ...
user avatar
0 votes
3 answers
91 views

Get the Most frequent element in an array

I have been trying to optimize this: ...
user avatar
2 votes
2 answers
195 views

Counting uppercase and lowercase characters in a string

I created two programs (one with JAVA8) to calculate the total count of uppercase and lowercase characters in given String. After checking the execution time JAVA8 is taking longer execution time than ...
user avatar
3 votes
2 answers
294 views

Parsing custom text file using haskell

I am working on writing code for find difference between two text files that should be ideally same. the format of file is ...
user avatar
3 votes
1 answer
68 views

Posts data to endpoint, trying not to use .Result on async methods

I have a Send method that is working but want to refactor a portion where it is using PostAsync().Result and ReadAsStringAsync().Result. I've never written async methods before and don't feel I ...
user avatar
2 votes
1 answer
75 views

Dose tracker with daily and weekly totals

This is an old script I made a while ago. What it does It tracks your dose of whatever you want tracked (cigarettes, salt, etc), outputs the total for each day, and the full week. What I’m looking for ...
user avatar
  • 181
3 votes
1 answer
106 views

Find the largest decrease in a sequence of numbers

I have written a function that takes as input a list of 5 numbers, then the program's goal is to return the largest drop in the list. It is important to understand that [5, 3, ...] is a decrease of 2 ...
user avatar
3 votes
1 answer
125 views

Using Numba works slower than not using it for my Python code

I thought this community is better place to ask my question so I ask here rather than at StackOverflow. Recently, I learned that Numba can make Python function ...
user avatar
  • 41
5 votes
2 answers
265 views

Spliting Greeter class to multiple small classes

Write a Greeter class with greet function that receives a name as input and outputs ...
user avatar
  • 65
5 votes
1 answer
117 views

Copy Columns Forward Macro: From Procedural to OOP

Background: I had created a macro few years ago and when I was reviewing this now, it was hard to understand. I recently went through all the articles from ...
user avatar
1 vote
2 answers
400 views

URLify a given String - replace spaces with %20

I have written a code to replace all spaces in a String with %20. ...
user avatar
  • 113

1
2 3 4 5
19