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
6
votes
4answers
1k views

Computing the item price and vat for a given pricing, order, and exchange rate

How can I improve the readability of the below function using a list comprehension? Also, is there a way to improve items() performance? ...
2
votes
1answer
42 views

Checking inactivity with periodic tasks in Java

I have created a simple HealthCheck service. I have two approaches: Create a task canceling the previous one if the system is active, rescheduling the new task. Create a periodic task and regularly ...
3
votes
0answers
71 views

Extracting member-accesses from an expression in C#

I need to extract all member accesses to expression parameter (and make sure, that they are not nested). For instance, for expression: a => a.A + a.B I need to ...
1
vote
0answers
45 views

LeetCode 200: Number of Islands

I'm posting my C++ code for LeetCode's Number of Islands (which is a famous problem). If you have time and would like to review, please do so. Thank you! Problem Given a 2d grid map of '1's (land) ...
3
votes
1answer
38 views

Laravel Scope get request data/param

I want to pass the param from the request on the scope method in the model and serve it as json to be rendered by select2. Which is better? 1. Pass request from the controller like this controller: <...
0
votes
0answers
52 views

What is the best implementation of a ignore case dictionary In C#

Imagine we have a custom dictionary class which is derived from Dictionary<string, object>. Dictionary is case-insensitive about keys and elements arrange is ...
0
votes
1answer
37 views

Encasing a string in double quotes

I need to add some characters to a String before using it for an API call. The idea is to add a " char both at the beginning and at the end of the String, to make ...
1
vote
2answers
42 views

Smartly joining possibly empty strings

I want to join two fragments into one string with a separator, but when one of the fragments is empty I only want one of them. I have two implementations. The first is long and slightly repetitive, ...
2
votes
0answers
27 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: ...
3
votes
1answer
90 views

In Memory Database in Unit tests, isolate the tests

I have stumbled across these unit tests in a code review that are using in memory db: ...
0
votes
4answers
89 views

Java method refactoring: getting the file name or path

I have been learning about refactoring and I have this method that I'm wondering if I should split into two for code cleanness. First, the method as one, next the method split in two: Method not ...
2
votes
0answers
47 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 ...
1
vote
2answers
37 views

Copying List Elements To Another List And Changing Them

I'm a beginner python programmer..I recently started reading a python book called: "Python Crash Course, 2nd Edition: A Hands-On, Project-Based Introduction to Programming"...And I found an ...
6
votes
1answer
465 views

Recursive LinkedList. Which implementation is better and why?

class Node: def __init__(self, data): self.data = data self.next = None class LinkedList: def __init__(self): self.head = None <...
3
votes
1answer
48 views

Maximum distance between space stations HackerRank

I am just working on Flatland Space Stations problem, and it is not seeming to be a tough question, but my algorithm lags in some aspects, since it solves majority of the test cases but fails for some....
6
votes
2answers
987 views

Python Class Coding Simplification

Main purpose of this code, Take some information for animal features Clasification of user input print those input into txt file My problem is that, I think coding of animal features takes too much ...
3
votes
1answer
36 views

A simple animation in pygame

I'm following a tutorial into pygame. I realized the example code was written for the sake of being easy to understand. I wondered if I could 'improve' the code, with a focus on keeping the exact same ...
4
votes
2answers
60 views

Builder design pattern pass object

Good Morning This is a builder design pattern .. the builder problem is duplication so I want to know from an expert with explanation which is better on quality on this code: (1) ...
6
votes
2answers
393 views

Implementing web scraping in a function and in a class

The goal of my code is to implement a web scraping routine to obtain the name and the price of a product. I want to put this routine separated from the main program file. Sample url to scrape: https://...
3
votes
0answers
49 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 ...
0
votes
0answers
35 views

Report writing, do the formatting work on database or non-database language?

When report writing, sometimes getting the data you need can be quite straightforward in SQL, but getting the data in the exact format you'll need it in for the specific report can be quite tricky. It'...
4
votes
1answer
45 views

Finding missing void keywords in C source code

I'm writing a bash script to search C source files and find the lines where I missed the void keyword (unlike in C++, in C, empty parameter lists have to be indicated with the void keyword). I read ...
1
vote
1answer
88 views

Best practice to initialize instance variables for a POJO when values are null

I am using Java 8. I haven't found another question that fits mine exactly, and I've come across some conflicting information on best practices with what I'm trying to do. I'm creating a POJO which ...
2
votes
1answer
76 views

Simple BST implementation using C++ Struct

I am trying to implement DSs in C++ and this is BST insert and search functions. I tried in two different ways, please review and see if one is advantageous over other. With pointer to pointer ...
23
votes
11answers
6k views

Find nth Fibonacci Number, using iteration and recursion

I'm a beginner programmer and I came upon this problem which is to find the n​th number in the Fibonacci series. I used to solve the problem using a for loop; ...
3
votes
1answer
147 views

Convenience function to save and load pickle objects

I want to come up with a simple convenience function to save and load pickle objects. A secondary objective is to simply execute the function without the above function. I have come up with two ...
2
votes
0answers
148 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 ...
-1
votes
1answer
83 views

abstract base classes versus the curiously recurring template pattern [closed]

Background Apologies for "burying the lead." The questions are in the next section. In my application, the purpose of inheritance is to abstract away complicated logic in the base class template, so ...
6
votes
3answers
208 views

C# Event Manager without allocations

I'm using my own Action-based Event Manager for a while and looking for ways to improve it. Mainly it's used in game development, where excessive garbage generation can lead to severe consequences. ...
0
votes
1answer
57 views

Schedule talks in tracks [closed]

Consider my simple business requirement as follows: There is a list of talks and they need to be scheduled in tracks. Each track has a morning session starting at 9am and an afternoon session starting ...
3
votes
2answers
65 views

Organise method flow

I have something like a shop. It is limited to a checkout page, which will send an email. Nothing big, but a nice thing to learn more OOP. Almost every time I develop new classes I am wondering how ...
7
votes
3answers
560 views

C++/Opengl voxel renderer

I have tried going back to C++ after long time of mainly doing C#. I realize that the code is far from perfect, however I would really appreciate if someone could point of what exactly is wrong and ...
5
votes
3answers
340 views

Ask the user a number between 2 and 20

Here is my attempt: ...
0
votes
2answers
72 views

Implementation of the Selection Sort Algorithm

I have tried to implement the Selection Sort Algorithm in two different ways, and I was just wondering if that is considered to be a valid implementation of that algorithm. Would that be also ...
1
vote
3answers
195 views

Comparing two simple distance calculating algorithms

Is the single method printMaxDistance_a or the two methods printMaxDistance_b AND ...
2
votes
2answers
64 views

Find the next empty column on a chessboard [closed]

I was playing around with the "eight queens" problem, just to see how I could use C++ algorithms to write less code. I figured out a way to find the next unused column using ...
2
votes
3answers
134 views

MySQL/MariaDB Data extraction / String manipulation / “TopN” processing => Performance of C++ vs php vs python

EDIT1: Suspicion that mariadb++ is affecting my performance results compared to the raw "mariadb/mysql Connector-C"?? EDIT2: I did a barebones C-Only implementation and it comes in at 222ms vs the ...
5
votes
1answer
97 views

PHP OOP classes used for building web applications

The following classes are used for web development. And I was wondering if I'm implementing them correctly specially the Base class. This is a version 2.0 of the question the classes are as follows: ...
6
votes
2answers
102 views

OOP design for election board

I am trying to build an OOP design for an election system. A citizen can nominate themselves to be a contender. So all contenders are citizens. I was thinking of keeping the relation ship IS-A by ...
5
votes
1answer
109 views

Linked list: removing first element

Method 1: ...
5
votes
0answers
71 views

Resizable containers with VueJS

I reviewed the code in Resizable split DIVs Vue.js, suggesting that the OP use computed properties and bound styles to simplify the code (at least reducing the need to use ...
0
votes
1answer
61 views

Choosing between 2 Fibonacci alternatives [closed]

Task: Return the fibonacci value at a given index. e.g: input: 6, return: 8. Algorithm 1: ...
5
votes
1answer
141 views

Shoe shine shop model in Rust and C++ - Follow-up

I've just refactored my Rust and C++ code which simulates the shoeshine shop model from this question. What else can be improved? C++: ...
0
votes
0answers
111 views

Recursion on graphs - networkx VS adjacency lists with native lists, sets or numpy vectors ( python )

Hope someone can help me out in reviewing this code to make it faster. My goal is to create a graph recursively: query for a node and its neighbors from a db (not present here) add it and its ...
17
votes
3answers
2k views

Shoe shine shop model in Rust

I'm learning Rust and a few questions did arise during translation of my C++ code to Rust. There are comments in Rust code I'd like to be answered. Is there an idiomatic way to solve this task? The ...
12
votes
4answers
694 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, ...
2
votes
0answers
30 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 ...
5
votes
2answers
115 views

Rotate a matrix, using transposition and reflection

I want to compare two solutions to the following question from Cracking The Coding Interview by Gayle Laakman McDowell : 1.7 Rotate Matrix - Given an image represented by an NxN matrix, where each ...
12
votes
4answers
2k views

Extraction of value from a dict-tree, given a path of arbitrary length

Problem: We read a complex json-file which grants us a tree in terms of a python "dict of dicts". We're then requested to retrieve a specific path from the tree, represented by a list of elements. The ...
1
vote
1answer
41 views

Filter string with min distance in r

I have the following sample data: target <- "Stackoverflow" candidates <- c("Stackflow", "Stackflow", "Stckoverfow") I would like to filter the string from ...

1
2 3 4 5
17