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

69 questions with no upvoted or accepted answers
Filter by
Sorted by
Tagged with
4 votes
0 answers
317 views

Java multithreading many readers one writer implementations

I have a shared data object with writer threads and reader threads. Number of threads can read from the shared data at the same time (in the code getmethod), and ...
user avatar
4 votes
0 answers
786 views

Kadane's algorithms to leetcode "121 Best Time to Buy and Sell Stock"

I employed the conventional Kadane's algorithms to solve a maximum subarray problem in leetcode Best Time to Buy and Sell Stock - LeetCode Description Best Time to Buy and Sell Stock ...
Alice's user avatar
  • 585
4 votes
0 answers
495 views

Two solutions to leetcode 127.wordLadder

I am working on Word Ladder - LeetCode Given two words (beginWord and endWord), and a dictionary's word list, find the length of shortest transformation sequence from beginWord to endWord, such ...
Alice's user avatar
  • 585
4 votes
0 answers
679 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 ...
Noixes's user avatar
  • 141
4 votes
0 answers
42 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 ...
JohnWick's user avatar
  • 425
4 votes
0 answers
222 views

Get nearest driver from 2.5 millions of data using mongodb

I have created 2.5 millions drivers dummy data, in this case lets say the drivers are moving around in the city. The driver's document look like this : ...
Gujarat Santana's user avatar
4 votes
1 answer
187 views

Time(n) Complexity of Fibonacci Algorithms

It is my first use of classes in Python. I wanted to create something useful and try some new things as I learn this cool language: strategy pattern, testing with nanoseconds precision, curve/poly ...
Alex Lopatin's user avatar
3 votes
1 answer
34 views

maxlist(L, M) that succeeds if M is the max number in the list L

I'm working my way through "Prolog For Artificial Intelligence" by Ivan Bratko, and exercise 3.17 is to write a maxlist(L, M) that succeeds when ...
Avrohom Yisroel's user avatar
3 votes
0 answers
35 views

TestAssignment class that checks for certain Git repository conditions

TestAssignment is a Python class designed to check certain conditions in a Git repository. It has several methods that check for the existence of required files, the initialization of a Git repository,...
Beki's user avatar
  • 31
3 votes
0 answers
793 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 ...
CafféSospeso's user avatar
3 votes
0 answers
225 views

React Higher Order Components - export wrapped component or wrap it in parent?

I've been learning about about how to use context, and how to make a higher order component to provide context values through props. So, I've created my HOC to pass down the props, and it looks like ...
TKoL's user avatar
  • 229
3 votes
0 answers
82 views

Providing a connection pool

I need some opinions about method naming and single responsibility principle. First of all, let's talk about method naming. The class below was created to provide a connection pool and whenever a pool ...
Aitiow's user avatar
  • 131
3 votes
0 answers
67 views

Simple beginner Rust CLI file reader that prints to stdout

Q: Am I approaching writing idiomatic Rust code correctly? Hi CodeReview, I'm a beginner Rustacean coming from Python going through Rust books (The Rust Book, Rust in Action). A lot of the beginner ...
9Q9a5QS's user avatar
  • 31
3 votes
0 answers
120 views

SageMakerTrainingOperator in Airflow

I have made an operator (surrounded by others operators) for training a model in sagemaker in airflow and I have doubts how would it be more readable or more pythonic. First I did this: ...
Javier Lopez Tomas's user avatar
3 votes
0 answers
1k views

Export EXIF data from thousands of images to CSV

I have written a script that retrieves specific fields of Exif data from thousands of images in a directory (including subdirectories) and saves the info to a csv file: ...
Hjalte's user avatar
  • 131
3 votes
0 answers
84 views

Best path using some intermediate points, where cost is either x-axis or y-axis distance

We are given N Cartesian points \$(x, y)\$. Anytime we move from \$i\$-th point to the \$j\$-th, the move costs \$\min\left(\left|x_i - x_j\right|, \left|y_i - y_j\right|\right)\$. The problem is to ...
TheGrossSloth's user avatar
3 votes
0 answers
258 views

Python code for a basic AI with voice recognition for retrieving news articles

I wrote a program for a basic AI with voice recognition that makes request to News API to retrieve metadata for the headlines currently published on a range of news sources and blogs. For now it does ...
Zakar H.'s user avatar
  • 183
3 votes
0 answers
446 views

Two reimplementations of the Underscore _.reduce function

I am working on rewriting the underlying code for some Underscore.js functions. Re-writing the reduce function has been causing a lot of headaches. I have been able to re-write it two different ways, ...
A_A's user avatar
  • 131
3 votes
0 answers
81 views

Methods to add and check elements in a Bloom Filter

I have a working Java implementation of Bloom Filter. These are the methods to addElement and check for an element. ...
sriram manoj's user avatar
3 votes
0 answers
705 views

Comparing linear time strongly connected component algorithms in Java

So I have implemented three linear time (\$\mathcal{O}(V + E)\$) algorithms for finding strongly connected components of a (directed) graph. A strongly connected component is just a maximal subset of ...
coderodde's user avatar
  • 27k
3 votes
0 answers
118 views

Custom MySQL duplicate_key update queries

The goal is to create an activity or update its counter if it's already present. And to be super accurate, the code avoids race conditions with a custom ...
user1035375's user avatar
3 votes
0 answers
296 views

Print the nodes of binary tree column-wise, using recursion and iteration

I am trying to code for both recursive and iterative approach to a problem. Below is a recursive code to print the nodes of binarytree column wise. Basically I have count of root as 0 and if I move ...
Sagar D's user avatar
  • 31
2 votes
1 answer
137 views

Array Implementation In JavaScript

Review I have written my own implementation of Array in JavaScript with the basic functionalities. Can anyone please review this code and point out the mistakes/how to make the implementation better? ...
enigma6174's user avatar
2 votes
0 answers
5k 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 ...
Hans Billiet's user avatar
2 votes
0 answers
51 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 ...
pee2pee's user avatar
  • 360
2 votes
0 answers
42 views

Which of my string indexing functions in Kotlin is semantically closer to my Java one?

I have a working string indexing method in Java and did convert in Kotlin. All methods shown below produce the same result but as I am really new to the Kotlin language I wanted to ask which of my two ...
PerfLearnling's user avatar
2 votes
0 answers
39 views

What is a better practice in bash scripts to test if string is empty: [[ -z ${value//[0-9]/""} ]] or ! [[ ${value//[0-9]/""} ]]?

I test in a bash script if a variable value contains digits only. There are two options, both give the valid results: ...
Eduard Meil's user avatar
2 votes
0 answers
89 views

Why does my Clojure implementation of Conway's Game of Life run so much slower than my Java implementation?

I'm trying to learn Clojure coming from a Java background. I have written a simple implementation of Conway's game of life in both Clojure and Java, trying to keep the overall structure of the code as ...
clojHalp3k's user avatar
2 votes
0 answers
185 views

generic implementation approaches for a recursive function

Let's take the famous fibonacci problem as an example but this is a generic problem. Also, taking scala as the language as it's rather feature-rich. I want to know which solution you'd prefer. we all ...
Maths noob's user avatar
2 votes
0 answers
47 views

Snake string implementations

This snippet uses a string as an output. As we iterate through the input string, I just keep appending a character to the string and I know this just pretty much creates a new string everything I add ...
Dawn17's user avatar
  • 215
2 votes
0 answers
2k views

Fast matrix transpose

I would like to improve the naive matrix transpose algorithm by using a cache friendly algorithm. So far there are 4 variants. Iterate over the source matrix: ...
Catree's user avatar
  • 121
2 votes
0 answers
194 views

Angular forms - reactive vs. [(ngModel)]

I am developing this angular app and it has big forms with 100 + fields. I was thinking about using [(ngModel)] without reactive forms, so that it's easier to do ...
pavithra rox's user avatar
2 votes
0 answers
39 views

Fast algorithms in Javascript for shortest path queries in directed unweighted graphs - follow-up

(See the previous iteration.) Now I have reworked my pathfinder program, and I ended up with this: ...
coderodde's user avatar
  • 27k
2 votes
0 answers
71 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 ...
user avatar
2 votes
0 answers
15k views

Accessing child class variables from its parent class

Requirements The code should be able to call a parent method to read and modify child object variable that is referenced by a pointer inside the Child class. This code is to be run on an embedded ...
CodeBreaker's user avatar
2 votes
0 answers
623 views

A fast integer key map in Java via a van Emde Boas tree

Introduction The following data structure is a dictionary mapping primitive int values to any value type. Basically, under the hood it is a hash table, where a ...
coderodde's user avatar
  • 27k
2 votes
0 answers
299 views

Which JavaScript snake-game implementation is better?

I was sort of bored and wondered how that Youtuber (Max Wihlborg) implemented his snake-game, so I went on and took a look at his code, and then I and edited his code. I made some minor changes, but ...
doubleOrt's user avatar
  • 263
2 votes
0 answers
16k views

Reset an input field after submission

i have some issues dealing with a simple case in my redux-react app: i want to reset an input text after an asynchronous operation ignited by a button. Let’s say we have an input text in which you ...
Giggioz's user avatar
  • 21
2 votes
0 answers
2k views

HackerRank - Matrix Rotation

Problem statement Given a matrix (up to 300 × 300), rotate each element R steps anti-clockwise along concentric rectangular paths (R up to 109). The algorithm is rated as hard on HackerRank. On ...
Jianmin Chen's user avatar
  • 2,396
2 votes
0 answers
84 views

Simple JavaScript module to manipulate CSS

After posting some of this code on Stack Overflow I was told to have a look here and get some feedback. I am having fun building a light JavaScript framework and have copied this pattern. It works ...
Daniel's user avatar
  • 121
2 votes
0 answers
446 views

Comparing three packet routing algorithms via simulation in Java

Inspired by my question Simulating a random packet routing algorithm and printing packet statistics in Java I decided to implement two more packet routing algorithms: one that computes all the ...
coderodde's user avatar
  • 27k
2 votes
0 answers
67 views

Retrieving the most recent posts from the users someone is following

I have two different implementations for retrieving posts from the users someone is following and I want to know which one you would recommend using. First I'll show you the tables, and then the two ...
khakis's user avatar
  • 121
2 votes
0 answers
150 views

Better way to toggle between the state of show() and hide() in jQuery

I have the following code which switches between the states of hide() and show() of show prices ...
Mustafa Ujjainwala's user avatar
2 votes
0 answers
768 views

Interactive transition between view controllers

I have made an interactive transition controller in Swift in two different ways. This interactive transition controller is the parent class and I have few child classes which adapt the parent for ...
Nico's user avatar
  • 199
2 votes
0 answers
399 views

Updating a list of a few dozen document resources in MongoEngine

This is my model: ...
latusaki's user avatar
  • 251
2 votes
0 answers
67 views

Rewriting authentication controller using promises

I am in the process of refactoring some complex code that uses callbacks to instead use promises. I am trying to figure out if my proposed approaches make sense. ...
Kevin's user avatar
  • 121
1 vote
0 answers
52 views

Combined or separate data-cleaning routine

I am a junior data engineer that have 3 years of experience with Python. I write a lot of Python code for my job and I came up with this question I can't solve by my own. I don't have the chance to ...
Izem's user avatar
  • 11
1 vote
0 answers
46 views

Revised: best practice of communicating with an instrument using Python

This is a revised version of the code from the previous question. It corrects the spelling errors, add in appropriate comments for argument types and doc strings, rewrite number representation, and ...
cloud chang's user avatar
1 vote
0 answers
56 views

Calculate total running time for movie series

Which of these 2 functions is better and more readable and why? (Both functions do the same thing). My goal is to get the total time of a series, using the TMDB API (which has a limit of 20 different ...
jofyavoydo's user avatar
1 vote
0 answers
25 views

Dividing the page into 2 sections using flexbox

I want to have a layout for desktop screens, so mostly wide screens with 4:3 or 16:9 aspect ratio. The layout is made out of 2 sections: right and left. The left section takes 2/3 of the width and the ...
pileup's user avatar
  • 361