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).
933
questions
2
votes
1
answer
136
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?
...
10
votes
2
answers
760
views
Leap Year Calculator Using If Elif and Else Only
I'm taking the 100 Days of Code (Python) taught by Angela Yu on Udemy. There have been a few other questions revolving around this lesson but I can't find one who came up with my specific question so ...
1
vote
1
answer
70
views
calculating the percentage of distribution of ids per Loc for each country
Which of the two queries is theoretically better and why?
I would like to understand why query 2 takes longer although there is no relevant information in the Execution Plan.
I'm querying a Presto ...
3
votes
1
answer
32
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 ...
6
votes
3
answers
470
views
Implementing a --assume-yes/--assume-no command line flag to affect a `input()` based `confirm()` function
I have a Python command line application that needs to ask the user for confirmation at some point. I want to add a --assume-yes/...
1
vote
0
answers
51
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 ...
2
votes
1
answer
40
views
Comparison of Named parameters and the Java Builder pattern in C++
OK writing a C++ wrapper on top of openSSL.
Setting up the SSL_CTX* object. There are a whole bunch of extra functions to specify functionality on how this object ...
1
vote
1
answer
217
views
Changing an element in a list when a predicate holds
My current project is a Settlers of Catan server in Haskell. I often manage to achieve my goals within Haskell, but the code is getting messier as the project grows.
My question is about the ...
2
votes
2
answers
5k
views
"Finding number of factors" efficiency
I have two functions to find the number of factors of a given number.
I was wondering which one will be more efficient to use?
...
1
vote
0
answers
45
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 ...
13
votes
6
answers
921
views
Assign a variant to a variant
Quick review:
I've been writing API code which receives user input that can come as either an object or a value type - a problem outlined here.
In order to write an unknown data type to a variable, ...
3
votes
1
answer
246
views
Best practice of communicating with instruments using Python [closed]
I have seen two different methods - getter and setter method and property - being used in Python libraries which are written for communicating with instruments via VISA commands. An example is given ...
1
vote
0
answers
55
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 ...
4
votes
3
answers
347
views
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 ...
4
votes
1
answer
105
views
Efficiently use array values and variables in a WordPress template
Is it better to validate and put an array value into a variable at the top of a file or to check the array value directly right before output in the file?
I work at a WordPress shop and we have a ...
4
votes
1
answer
93
views
Spring REST Endpoint for Saving a User Inquiry
Here's a piece of code from codebase I maintain/contribute to.
It is a Spring REST controller, which exposes an endpoint to create user question. The question consists of title, description and ...
7
votes
6
answers
3k
views
Checking if an integer is a palindrome using either a string or a dict
I have solved the palindrome question on LeetCode today, but I wasn't happy with the original solution - I used strings, it worked slowly and used a lot of memory.
So I rewrote the answer using a ...
5
votes
1
answer
105
views
Instance specific code generation
Disclaimer: I've asked this question before on Stack overflow and got a response that this place would be a better fit so I am copy pasting the question here.
I've come up with two different ...
2
votes
1
answer
84
views
Build a message string depending on the type of signature of an invoice
The following method was meant to build a message depending on the type of signature of an invoice. It contains some if-else statements and code duplication.
The original method :
...
3
votes
1
answer
872
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 ...
5
votes
2
answers
9k
views
Calculate GS1 / SSCC / UPC check digit
I try to write a function which calculates the check digit for shipping label based on the algorithm provided by GS1
http://www.gs1.org/how-calculate-check-digit-manually
Version 1: my first try
<...
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,...
2
votes
3
answers
105
views
Wordlist formatter code
I am making a "wordlist cleaner" module that loads a words.txt file, and returns a list of cleaned/sorted words.
Full code:
...
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 ...
2
votes
1
answer
82
views
Logger that can be redirected to switch off output
I am evaluating two implementations of a C++ logging mechanism.
The first implementation, below, unconditionally streams (calls the insertion operator) to the ...
3
votes
1
answer
93
views
rust sort numbered directories (non-lexicographical)
I am very new to rust and have been reading up and playing around to get a better understanding. I was trying to replicate a small task that I have done via bash scripting before, as a way to ...
1
vote
1
answer
122
views
Excluding attributes entirely vs. setting them to None
I am making a program that parses profiles from a website. Some profiles are "public" and others are "private" with limited information. Public profiles contain a lot more data and ...
1
vote
0
answers
109
views
Making Robert Tarjan's offline LCA algorithm run (much) faster (Java)
I have produced this GitHub repository that compares the performance of:
Robert Tarjan's off-line lowest common ancestors algorithm,
An improvement of the above algorithm.
Typical demo program ...
7
votes
6
answers
1k
views
Compute "negative" version of vector of vectors
Given a std::vector<std::vector<double>> (e.g., representing some points in a space with D dimensions), I want to ...
3
votes
3
answers
93
views
Parse program arguments of the form key=value
I have two proposals for parsing arguments:
Method A
...
12
votes
3
answers
7k
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
2
answers
89
views
Granular vs a aggregated tests when dealing with arrays
I write code in a Test-Driven way and I often build my functions starting with tests for the easy edge cases.
For example, given a flat array of Items that have a <...
3
votes
1
answer
111
views
"Select followed by First" versus "First followed by Select" when summing the data for a student
I am wondering which one I should choose between the following two options when I need to calculate the sum of Data of the student with ...
1
vote
1
answer
568
views
Functional Fibonacci in OCaml
I'm very new to OCaml, and as an exercise I decided to implement the nth Fibonacci algorithm (return a specific Fibonacci number, given an index) in different ways, using what I've learned so far.
I ...
-1
votes
1
answer
158
views
Getting three numbers input interactively and process them
I'm new to Python and programming in general.
Let's imagine I have a simple task:
Given 3 numbers from user input, I need to count negative ones and print the result.
Considering what I know about ...
0
votes
2
answers
215
views
Functional Style if/else in java
I would like to ask the opinion for experts out there. The following code snippet was written by a colleague of mine who is very fond of functional style in Java.
...
2
votes
1
answer
158
views
C/C++ hash looking in flat database compared to PHP
I have a hash table which I would like to query as fast as possible.
The hash table is stored this way :
When I query a hash, I extract first 4 characters then use it to find the file. For instance a ...
3
votes
2
answers
908
views
Convert Rankine temperatures to Celsius
I have this Python Package called ToTemp under development for precise Temperature Conversions and currently thinking in changing the method's implementation to be ...
1
vote
2
answers
102
views
Circular list vs. doubly-linked list: which is faster?
In this post, I will compare performance of a circular list and a conventional list with head/tail -references:
...
5
votes
2
answers
651
views
Recursively calculating powers by squaring
Consider the following function that implements optimised O(log n) exponentiation by squaring:
...
0
votes
1
answer
68
views
Comparison of two ways of looping in Python [closed]
I wrote a small script to demonstrate two ways of looping in Python: with and without using the index. I want to know which way is better. Please see the example:
...
1
vote
1
answer
51
views
Comparing a weak fluent API with a strong fluent API in Java [closed]
I have this simple POJO:
...
2
votes
4
answers
1k
views
Calculate the median value of combining two sorted lists
I have solved a leetcode problem (Median of Two Sorted Arrays), and I came up with two solutions.
Solution 1
...
2
votes
2
answers
93
views
Project sequence to multiple sequences using LINQ (or extension methods)
I'm creating a method that expands a sequence.
This is a sample of how it works:
Input: {1, 2, 3}
Output: {1}, {1, 2}, {1,2,3}
So far, I've been able to solve the ...
2
votes
1
answer
139
views
LeetCode#494 target sum (dart is slower than python)
I'm trying to solve a LeetCode problem target-sum, in two languages: Python & Dart. The difference of time taken is shocking for me"
Python took ~70ms while Dart took ~900ms !! Why does Dart ...
4
votes
2
answers
25k
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:
...
1
vote
1
answer
92
views
Selection algorithms (order statistic) in Java: linear time vs. sorting selector vs. Quickselect
This post is about computing order statistics: given an array \$A\$ (not necessarily sorted), find the \$k\$th smallest array component. The entire repository is here.
...
0
votes
0
answers
72
views
Euler's totient function in Rust, with a performance difference between generic and classic functions
I recently started to program in Rust, having like 2 good years of experience in C++, I thought it would be possible to directly switch to Rust without following a lot of tutorials, especially knowing ...
12
votes
2
answers
17k
views
Get values from Web service asynchronously
I am working on creating some libraries for a project at work and I wanted to make sure I have this pattern correct. Assuming that the GetWidgets() method is what I ...
2
votes
1
answer
152
views
Card game simulations, with a multithreaded version slower than the single-threaded one
I'm new to rust and I'm trying to build a card game simulation to find all of the best actions with all possible hands. This requires a lot of simulations and my first 3 million are already taking a ...