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
10 votes
2 answers
769 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 ...
AGM's user avatar
  • 103
6 votes
3 answers
476 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/...
Lucas's user avatar
  • 161
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
2 votes
1 answer
41 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 ...
Martin York's user avatar
  • 94.3k
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
1 vote
0 answers
48 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
3 votes
1 answer
249 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 ...
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
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 ...
Sergey's user avatar
  • 401
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 ...
user1806687'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
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
2 votes
1 answer
87 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 ...
StoneThrow's user avatar
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: ...
angel's user avatar
  • 35
1 vote
1 answer
124 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 ...
angel's user avatar
  • 35
1 vote
0 answers
110 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 ...
coderodde's user avatar
  • 27k
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 ...
Filippo Bistaffa's user avatar
3 votes
1 answer
97 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 ...
Kyle Price's user avatar
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 ...
Pin_Eipol's user avatar
3 votes
3 answers
93 views

Parse program arguments of the form key=value

I have two proposals for parsing arguments: Method A ...
alirezaarzehgar's user avatar
-1 votes
1 answer
159 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 ...
QLEDHDTV's user avatar
0 votes
2 answers
227 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. ...
office.aizaz's user avatar
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 ...
James's user avatar
  • 41
3 votes
2 answers
909 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 ...
eddyxide's user avatar
  • 141
1 vote
2 answers
103 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: ...
coderodde's user avatar
  • 27k
5 votes
2 answers
651 views

Recursively calculating powers by squaring

Consider the following function that implements optimised O(log n) exponentiation by squaring: ...
saxbophone's user avatar
2 votes
1 answer
139 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
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: ...
Jeremy's user avatar
  • 111
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 : ...
l0r3nz4cc10's user avatar
1 vote
1 answer
51 views

Comparing a weak fluent API with a strong fluent API in Java [closed]

I have this simple POJO: ...
coderodde's user avatar
  • 27k
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 ...
111's user avatar
  • 45
2 votes
2 answers
95 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 ...
SuperJMN's user avatar
  • 233
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 ...
Abhishek Patil's user avatar
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. ...
coderodde's user avatar
  • 27k
0 votes
0 answers
73 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 ...
Teyzer18's user avatar
  • 101
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 ...
PaulEliaz's user avatar
0 votes
1 answer
112 views

Find longest "binary gap" [closed]

I'm doing a few challenges and I found this one on Codility: A binary gap within a positive integer N is any maximal sequence of consecutive zeros that is surrounded by ones at both ends in the ...
GB5's user avatar
  • 101
1 vote
1 answer
64 views

Shortest path in dags: Part 2/3 - the preprocessing and shortest path algorithms

Part 1/3 Part 3/3 I have this library for performing shortest path queries on dags (directed acyclic graphs). This post presents the shortest path algorithms and the topological sorters. Two ...
coderodde's user avatar
  • 27k
0 votes
1 answer
200 views

Show numbers per step count

I have a problem where I need to display the below output 1 23 456 78910 My first solution is ...
teebo's user avatar
  • 103
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 ...
Display Name's user avatar
5 votes
1 answer
309 views

Calculate the number of people occupied at each time interval

The following scripts calculate a list with the number of people occupied at each time interval. The intervals are defined by the timestamps of two consecutive events that come from the sorted list <...
pxaris's user avatar
  • 53
2 votes
3 answers
796 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, ...
Jay's user avatar
  • 214
1 vote
1 answer
572 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 ...
NPN328's user avatar
  • 751
-2 votes
1 answer
182 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 ...
Raging_Jim_Lahey's user avatar
2 votes
1 answer
77 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 ...
AminMal's user avatar
  • 123
1 vote
1 answer
115 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 ...
Joji's user avatar
  • 315
3 votes
3 answers
268 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 ...
zola25's user avatar
  • 140
3 votes
0 answers
799 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
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
1 vote
1 answer
385 views

Constructing routes from imported URL constants

There is a file created with the project paths in a dictionary. Example: ...
Javier's user avatar
  • 113

1
2 3 4 5
19