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
3answers
105 views

Printing lines of “*” of various lengths

As a beginner, I tried a programming drill. The method gets an Enumerable that contains numbers specifying how many "*" to print on each line. ...
5
votes
1answer
379 views

Normalize a GSM short message text

I am working to improve this script, which should prepare a text to be sent as a GSM short message using only the GSM 7-bit character coding with Basic Character Set Extension. ...
1
vote
0answers
86 views

PDcurses wrapper module, with mvc or pimpl

I have been writing a library wrapper for pdcurses for a while and implemented each widget/class in it with the pimpl idiom, however I start to see that for large widgets it creates a god object and ...
4
votes
2answers
297 views

Colors for unvisted, visited and hovered/focused/active links

I've created a userscript for Tampermonkey to style unvisited links with blue color, visited links with violet color, and red for hovered/active/focused links. It was created primarily for my ...
1
vote
1answer
78 views

Transforming lists of products to boolean vectors

Task Inputs Lists of products stored in a CSV file, where each line represents the shopping list of a single client: Outputs A CSV file: Header: products names sorted by number of appearances in ...
2
votes
1answer
648 views

Find spiral 2D matrix (List of Lists) of ints in a clockwise spiral

I got this question during my interview with Microsoft. The question called 2D Snake. I'm wondering if my solution 1 passes the test, but if my solution 1 different from solution 2. Let's have ...
2
votes
2answers
70 views

Find the middle of the string

The follow code should correctly run the test cases at the bottom. It works correctly. I just don't feel like this is clearest way I could write it. A lot of the complexity comes from having to ...
0
votes
1answer
39 views

Selecting data from a table based on value in another table (SQL server)

I am using the northwind example database to brush up my SQL server skills. I want to select all the products ordered by the customer with the customer id 'Folko'. My idea is to join the Orders ...
1
vote
2answers
76 views

Performing a sum with Swift

I wrote the following in Swift to perform a sum: let total:Double = session.courses.reduce(0) { $0 + $1.totalPrice() } It's concise, it does the job but it does ...
1
vote
1answer
55 views

Setting Property Values Programmatically in a JSON Object

Through the lens of the SOLID principles, which one of the following makes the most sense? I want to ensure the approach I select keeps everything simple and maintainable as we add properties, modify ...
2
votes
0answers
4k 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 ...
9
votes
5answers
285 views

Applying a string-identified effect on an image

Task: Given an image object and an effect identifier (string), apply the effect identified by the string on the image. The library of effects can grow as the program grows. Code 1: ...
3
votes
1answer
709 views

Find LCM of two numbers

The problem is to find LCM of two numbers. I have tried to solve the problem in two ways. First by using the LCM formula : LCM (a,b)= a*b/GCD(a,b). Second, by ...
6
votes
4answers
14k views

Sorting dates in this format (DD-MM-YYYY)

Is this the correct and an elegant way to sort the dates in the format (DD-MM-YYYY) in ascending order? ...
1
vote
1answer
151 views

OO and non-OO usage of Mysqli

I'm starting to learn the object oriented aspect of PHP. In this regard I made a small "exercise" of sorts "translating" one of my PHP functions into OO mode of PHP. I'm asking if there are there any ...
6
votes
1answer
63 views

Return true from enumerable that calls function unless that function ever returns false

Is there a tighter way to write this code? ...
1
vote
0answers
287 views

Retrieving localized Days of Week in PHP : setlocale VS IntlDateFormatter

I'm trying to find a good way to dynamically print a selection of localized days of week without resorting to an hard-coded array per language, leveraging locale mechanisms instead. Up until now, I'...
4
votes
1answer
82 views

Displaying contacts in PHP, with options to omit some information

I am currently changing some PHP code. The old code looked like: ...
1
vote
0answers
60 views

Comparing two heap sift algorithms in Java

My research question was to find out whether minimizing the number of assignments in a heap lead to any time savings. The "optimized" version stores the element to sift, sift the minimum to its place ...
3
votes
0answers
79 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 ...
-1
votes
1answer
49 views

Better practice of return statement in ReactJS [closed]

What is a better practice, to have an implicit return and something big inside the curly braces {project.name === 'default' ? 'Unassigned' : project.name} ...
3
votes
1answer
101 views

Getting products for category

I have a PR for a bugfix in which the fix is just 4 characters. In this situation we are invited to make some refactoring on the class that we are touching if possible. Venkat Subramaniam's advice is ...
1
vote
0answers
64 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 ...
1
vote
0answers
53 views

Sorting BIGINT column with ascending positive values followed by descending nonpositive values

I have a column flowing in with the full range of integers. Whilst generating keys on the INT column, I need to push the 0's and negatives down (ordered DESC) and ...
1
vote
0answers
39 views

Benchmarking TreeSet in Java against a van Emde Boas tree based integer set

VanEmdeBoasTreeIntegerSet.java ...
3
votes
1answer
95 views

Function to validate data using up to four kinds of rules

Sometimes I end up with a function that requires checking multiple conditions to determine the outcome and the logic can get to be too much to handle on a single line. Here's an example of how I ...
6
votes
6answers
5k views

Verify string format with given pattern

I'm implementing an auxiliary global function which has to check whether a given string has correct format (i.e., it begins with a letter and only contains letters, numbers or the "_" character). ...
1
vote
1answer
47 views

Checking for files that are mentioned as children of other files

I am working in JavaScript on a GruntFile script, and I am creating an object that holds a file class for each one of the following class structure: ...
6
votes
3answers
1k views

Inserting and fetching values slower on an unordered_map in C++ than on a dictionary in Python

I was solving a CodeForces problem, and kept getting Time Limit Exceeded, so as usual in these cases, I decided to try to migrate my code from Python to C++ in order to go faster. I noticed that my C++...
1
vote
0answers
75 views

Anytime algorithm in Java

An anytime algorithm is an optimization algorithm that can be stopped at any time, and when it is stopped, it returns the best result that it found so far. I am trying to implement an anytime ...
1
vote
2answers
5k views

Sorting an ArrayList of Vehicles using quick sort

For an assignment I have to sort an ArrayList of Vehicle objects using the quick sort method. I have come up with two implementations for this, which would be the best to use? Is method 1 considered ...
6
votes
2answers
111 views

Concatenating prefix of one array with the reversed suffix of another array

Given two arrays and two indices, I need to concatenate the prefix of the first array and the reversed prefix of the second array. For example: ...
-3
votes
2answers
103 views

Check if a variable is one of a set of valid strings [closed]

We need to check if a given variable is either "get" or "post". If it's neither then I should throw an error. My teammate and I ...
2
votes
1answer
86 views

Which is the best approach for searching the dictionary items?

We can search for the list of dictionaries using the below some approaches, Can one please help me, which one is the memory efficient approach to use? Provided that: ...
2
votes
2answers
62 views

Copying and filtering Ruby arrays

I'm doing a Ruby exercise to create new arrays with a given filter. Copy the values less than 4 in the array stored in the source variable into the array in ...
1
vote
1answer
819 views

Singleton with a volatile and synchronized instance

I created a singleton to have a unique instance of ExecutorService in my application. I whould like to know which is the better of the two classes below. First one : ...
4
votes
2answers
184 views

Conditionally replacing a placeholder in a form

Given this code ...
1
vote
0answers
456 views

Which function is faster levenshtein() or similar_text()?

Brief I wrote two functions using levenshtein() and similar_text(). The functions will find similar words from the dictionary ...
0
votes
2answers
714 views

HashMap used to store DateTime

I have a scenario where I need to save a string as a key and DateTime as value into a hash map. Also, I need to remove strings older than 24 hours. At the moment the HashMap is implemented as below: ...
5
votes
3answers
65 views

Aggregate summary counts for an array of error objects

I'm doing some refactoring of someone else's code, and just want a second opinion, because of course I think my work makes it better, but some validation (or correction) would be helpful. Starting ...
3
votes
3answers
94 views

Filtering out objects in a CollectionViewSource

I hired a developer as a senior dev. He was the only one that successfully completed my coding test. Now that he's on the project, I'm reviewing some of his code and seeing constructs like this: <...
1
vote
1answer
187 views

Filtering visible map layers based on multiple conditions

I am working on a webapp using OpenLayers. I have written a filter function that I can use to tell whether a given layer is visible. Since there are a bunch of conditions for a layer to be visible, I ...
3
votes
2answers
407 views

Comparing Dijkstra's SSSP algorithm against Bellman-Ford in Java

Single source shortest path In SSSP, we choose a node \$s\$ and we compute all the shortest path starting from \$s\$ towards all other nodes, thus computing a shortest path tree. Two most classical ...
2
votes
1answer
1k views

Makefile for a C++ project using Boost, Eigen, and htslib

I had a Makefile but it doesn't meet the "industry-standard expectation". That was feedback from my client. The old Makefile was rejected. Thus, I'm making a new one. Here is the repository for my ...
0
votes
2answers
224 views

Print every line of file, last to first, with recursion

Had a discussion with a friend to solve this extra credit problem, and we came up with two separate solutions. What are the differences between these two? Is one better than the other? How can I make ...
1
vote
1answer
81 views

Comparator Implementation

I am trying to compare Entries by their frequencies using Comparator. I wanna know if this piece of code would work for this case? ...
8
votes
2answers
742 views

Retry and CircutBreaker the reactive way

I wrote a simple utility for Retry and CircuitBreaker patterns. I implemented it by using ReactiveX because I thought it might actually be the perfect framework for it. I know that there is a project ...
2
votes
1answer
90 views

Find sum of indexes in big list, that satisfies some property

Task: We have this big list of (signed) integers. We are interested in finding every index "idx" (zero-based, of course) in this list, that has the following property: The sum of the integers ...
2
votes
1answer
190 views

Toggle case of a string in Swift

What is benefit of using uppercased() / lowercased() over the following approach ? (Other than making it more readable) Any ...