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).
937 questions
6
votes
2
answers
784
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
0
answers
69
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 ...
4
votes
1
answer
58
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 ...
2
votes
1
answer
9k
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
1
answer
2k
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
11
answers
11k
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 nth number in the Fibonacci series.
I used to solve the problem using a for loop; ...
4
votes
1
answer
289
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
0
answers
187
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
1
answer
351
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 ...
5
votes
3
answers
2k
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
1
answer
67
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
2
answers
79
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
3
answers
921
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
3
answers
387
views
Ask the user a number between 2 and 20
Here is my attempt:
...
2
votes
2
answers
83
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 ...
2
votes
3
answers
208
views
Comparing two simple distance calculating algorithms
Is the single method printMaxDistance_a or the two methods printMaxDistance_b AND ...
2
votes
2
answers
78
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
3
answers
309
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
1
answer
134
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
2
answers
176
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
1
answer
839
views
Linked list: removing first element
Method 1:
...
12
votes
1
answer
485
views
Resizable containers with VueJS
A month ago 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
1
answer
77
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
1
answer
160
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++:
...
17
votes
3
answers
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 ...
13
votes
6
answers
978
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
0
answers
49
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
2
answers
1k
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
4
answers
6k
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
1
answer
80
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 ...
4
votes
1
answer
179
views
Random password generator that ensures diversity of character types and absence of confusing characters
I wrote the following password generator, to generate a password in which each character group appears at least at once.
...
2
votes
2
answers
1k
views
A function that returns all letters in the Alphabet except the ones in a pre-defined list
This function should return a string that is comprised from all the letters in the Alphabet except the letters in a pre-defined list in alphabetical order.
Assuming all letters in the pre-defined ...
4
votes
1
answer
2k
views
Decoding of binary data (AIS) from socket
I am currently working on a AIS message decoder written in pure Python. It's just a little project to teach me some things about binary data, decoding, etc. Because I am only programming for about a ...
5
votes
1
answer
429
views
BitBoard class In TypeScript for chess logic
I'm working on writing a Chess Logic Library in JavaScript for learning purposes and was wondering how good these two slightly different implementations of a BitBoard are.
The first stores the board ...
10
votes
4
answers
2k
views
Shuffling multiple iterators in order
I have a Python function w/ specified functionality, and two proposed approaches - which do you prefer, and why? (performance, simplicity, clarity, etc) (both use ...
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:
...
4
votes
1
answer
3k
views
The best way to unwrap the optional in java [closed]
Instead of using the null checks I tried using Optional and safely unwrapping the optional.
Approach 1
My first approach of unwrapping the ...
2
votes
3
answers
3k
views
Classifying integers as "weird" or "not weird"
Problem Statement
Given an integer N, perform the following conditional actions:
If N is odd, print Weird
If N is even and in the inclusive range of 2 to 5, print Not Weird
If N is even ...
2
votes
0
answers
199
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 ...
7
votes
1
answer
277
views
A simple game that keeps track of the number of questions asked
This is just a simple counter, i was able to code it in two different ways but i want to know which way is more efficient and which way is more readable.
and which set of code is more "correct" in ...
1
vote
1
answer
142
views
LeetCode: House Robber I C#
https://leetcode.com/problems/house-robber/
You are a professional robber planning to rob houses along a street.
Each house has a certain amount of money stashed, the only constraint
stopping ...
3
votes
0
answers
132
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:
...
4
votes
1
answer
279
views
LeetCode: Symmetric Tree C#
https://leetcode.com/explore/interview/card/top-interview-questions-easy/94/trees/627
Given a binary tree, check whether it is a mirror of itself (ie,
symmetric around its center).
For ...
2
votes
1
answer
64
views
How to differentiate web fonts font-face font-weights?
What do you guys think:
OPTION #1 (same font-face name and change font-weight)
...
14
votes
2
answers
734
views
Get the encrypted payload from an unencrypted wrapper PDF document
This is code, written by our dev team, and SonarQube tells me that the Cognitive Complexity is too high: 21, and the current (default, out of the box) metric limit is 15. I've had a go at reducing the ...
1
vote
0
answers
986
views
Polling an SFTP server to list files in a directory
When is it better to instantiate the sftp client globally vs inside a function as shown below? What considerations favor one method over the other?
For a long ...
8
votes
1
answer
110
views
Resolving Git conflicts with Javascript
Challenge:
Resolve git conflict by resolveGitConflict(linesArray, resolveMode), where
linesArray is an array of strings
Example:
...
1
vote
0
answers
50
views
Store tweets to a local MongoDB server
I use NodeJS along with the MongoDB NodeJS Driver to store tweets into my local MongoDB server. In the following setup, mongos insertOne method gets invoked quite ...
5
votes
3
answers
224
views
PHP classes with functions used for building a web application
The following class is set of functions I use for web development(examples below) and I was wondering how to structure it.
Examples:
...
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:
...