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
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 ...
-3
votes
1answer
1k views

c# Linq vs foreach [closed]

which better in performance consider that case I have an array of objects (DocsOrder), I looped throw that array to match exists of passed data ...
1
vote
0answers
26 views

JavaFX FreeTTS program lags on MacOSX. Load wheel

I am working on a personal project and I am new to app development in general also java and javafx. I have some code that works. Only, I am unsure why I get the mac loader wheel once my button to play ...
14
votes
5answers
22k views

Simple countdown programs to print “3, 2, 1, Action!” using while loop

My program is a simple while loop making a countdown starting from 3 and shouts "Action!" upon reaching zero and then breaks. I would like to know which of the following ways is better in means of ...
2
votes
0answers
214 views

Which JavaScript snake-game implementation is better?

I was sort of bored and wondered how that Youtuber (Max Wihlborg) implemented his snake-game, so I went on and took a look at his code, and then I and edited his code. I made some minor changes, but ...
3
votes
2answers
98 views

Python file overwriting script

I am fairly new to Python and I'm trying to make a script that does three basic things: prints the contents of a file, overwrites it with your new lines, and prints the new file. I rewrote the script ...
0
votes
1answer
1k views

Return a Promise for a JSON POST

Given this method, we don't know which syntax is the more appropriate. ...
-1
votes
1answer
2k views

SQL connection string builder, initialized in two ways [closed]

For a while now I have been using string builders in my code. The way I currently do this is using the code below: ...
5
votes
2answers
1k views

Two approaches to print all permutations - returning versus passing through the “result” list

I have noticed many of the backtracking problems have two ways of solving. One is to return "whatever's the required list", vs passing-through the "result" to every call and appending to it. What is ...
3
votes
1answer
648 views

Notify one of hundreds of viewmodels with MVVM Light messenger

Assume a viewmodel for hosting a collection of item viewmodels. There can be some hundreds of items in the collection. The items are part of the business model and have an id and a name. The name for ...
6
votes
3answers
14k views

Splitting URL query string to key-value pairs

I have a URL query string "key={value}&key2={value2}&key3={value3}" and have to produce a key-value pair of the string by splitting ...
2
votes
1answer
117 views

Validating and saving a user profile, using fat model vs. view code

I heard that fat models are good idea and I should avoid operations on database in my views so I do something like this below. Can you tell me if it's good idea and which version is better? Please ...
-2
votes
1answer
66 views

Memory allocation in Caesar cipher

...
7
votes
3answers
8k views

Counting characters inside of a textarea using Angular

I have a textarea and need to calculate how many characters have been typed into it. Both of the following solutions work correctly—which would be preferable,...
1
vote
1answer
1k views

Resizing an `IList<T>`

I need to resize an IList<T>. I have written two versions and would like to have a review of those. I am particularly interested on which of the two is to be ...
4
votes
1answer
140 views

Comparing three C++ data structures for discrete sampling with probability distributions

Introduction A probability distribution data structures receives pairs \$\langle e_i, w_i \rangle_{i = 1}^n\$, (\$e_i\$ is an element and \$w_i\$ is its respective positive weight) and provides a ...
3
votes
2answers
166 views

Cor.test inside for loop is very slow for large matrix processing

I have a matrix of 36,000 genes measurements for 60 samples. For calculating most correlated genes of the first gene in the matrix, my following program gives the result. However processing time is ...
2
votes
3answers
286 views

Next and Previous navigation

I'm sorry, maybe this question is really stupid but I have really been thinking a lot about it recently, thinking of which type of <prev | next> web ...
0
votes
2answers
37 views

ActiveRecord query for coaches a client has bookmarked

I'm trying to figure out the best way to set up an ActiveRecord query. Models There are three relevant models involved: ...
3
votes
2answers
256 views

Counting terms in Collatz sequences until 1 is reached or a limit is exceeded

My friend and I are into competitive programming and we wrote two very similar programs for a problem. His got accepted with a runtime of 0.6 s while mine didn't get accepted even after 3 s. I was ...
5
votes
1answer
47 views

Comparator classes supporting operations on sets

I have a class Comparator that does several operations (union, intersection, etc) on 'sets'. In this specific case each 'set' is a 3 dimensional array. in order ...
2
votes
2answers
78 views

SQL Server Stored Procedure quality

I'm beginner in programming and I have recently written quite an advanced stored procedure. Based on parameters with which I call it, it returns data and groups it, but that is not the most important ...
3
votes
0answers
148 views

Python code for a basic AI with voice recognition for retrieving news articles

I wrote a program for a basic AI with voice recognition that makes request to News API to retrieve metadata for the headlines currently published on a range of news sources and blogs. For now it does ...
6
votes
2answers
393 views

Shifting an 128-bit integer consisting of four 32-bit integers

For a little project of mine I have written two versions for shifting a 128-bit unsigned integer consisting of four 32-bit unsigned integers in x86 assembly. I cannot really decide which is better in ...
4
votes
3answers
122 views

Associating a string with a derived class

I am using the following code to get a string that is associated with the class of an instance: ...
2
votes
1answer
431 views

Open/Closed Principle with calculating the total cost of items in a shopping cart

I came across the below example in a tutorial for the open-closed OOP principle. This example demonstrates function of calculating the total cost of items in a shopping cart. I have provided code for ...
2
votes
2answers
1k views

Censor words in a sentence

I wrote three versions of the same code using Reduce, a functional approach and also a regex pattern approach. I'd like to get feedback, especially from the functional one since I'm learning ...
3
votes
3answers
757 views

Readability of array_* vs foreach in PHP for filtering and extracting

With functional programming all the rage, I feel I should be using PHP's array_* functions more. But when I compare these two identical implementations, I can't ...
0
votes
2answers
140 views

Age converter for some planets

I was wondering if it is better to use: ...
1
vote
2answers
245 views

Musical graph algorithm, with an inlined lookup helper function

I am working with bit strings in clojure. My question is less about performance and more about how one should go about it (in particular see the last inlined version) The tonnetz-array represents an ...
2
votes
1answer
73 views

Modeling Cash-Case differences - should WebAPI DTO's be flat?

I have an n-layer application with domain models and DTOs models. My DTOs are going through entire application(every layer) and also I return them from my WebAPI. It is good approach? Basically, if ...
2
votes
1answer
147 views

Extension vs Class For ViewModel

What the advantages & disadvantages to each of these approaches pertaining to creating file that takes care of the view configuration to reduce a controller's file size. Main Purposes Are: ...
1
vote
0answers
37 views

API separate request vs logic

Is it a good practice to separate Logic from Request controller in an Api ? Without separation: ...
3
votes
2answers
978 views

Project Euler Problem 5 Performance

I'm hoping for suggestions of a concise way to write my list comprehension filter in the first solution. I would also appreciate insight on the underlying reasons for some performance differences in ...
1
vote
1answer
54 views

MySQL queries to select messages related to a user, using UNION vs. OR

I'm just wondering if there is any improvements that can be made on my queries, as i've looked around and posts are saying to use UNION ALL instead of ...
3
votes
4answers
448 views

Finding anagrams in Java (space-optimised)

I've lately been asked in a job interview to program a solution for the well known anagrams problem: given two strings s1 and s2,...
0
votes
2answers
114 views

Two implementations of a PHP sign-up page

I want the most secure and well-written version for my sign-up page. I'm adding AJAX to it for validation, too. I'm still writing it. If you have tips on AJAX or on how to improve this PHP code for ...
0
votes
1answer
115 views

find the maximum occur number in an integer [closed]

Write a function named maxOccurDigit that returns the digit that occur the most. If there is no such digit, it will return -1. For example ...
3
votes
4answers
4k views

Which is cleaner: a constructor with many parameters or many setters after construction? [closed]

I'm trying to work out which is cleaner, having a large constructor or having to use many setters on a new object before doing some work with it. Large constructor: ...
4
votes
1answer
707 views

Checking if an array is unimodal

Codeforces problem 831A says: Array of integers is unimodal, if: it is strictly increasing in the beginning; after that it is constant; after that it is strictly decreasing. The ...
3
votes
1answer
221 views

Standard primitive types vs custom structs in public API

I am writing a .NET library and have a lot of properties like this: public ??? SomeProperty { get; set; } where valid values are 0-15 (or from 00000000 to ...
2
votes
1answer
2k views

Check if item exists

I have a service to Insert TagName , I dont want to insert duplicate tags I used this : ...
4
votes
1answer
83 views

Three variations on a Webpack build script

I am new to "modern" Javascript, and I am reviewing some code from a frontend contractor. I'd like to make the sequential code more descriptive/procedural. The following code is a from a file called <...
1
vote
1answer
56 views

Two approaches to count occurrences of one char in a String in Java

I have two approaches: First Approach: ...
2
votes
1answer
52 views

Extract integers from a string that is split at given positions

I am writing a program which runs quite slow and on profiling I found that the bottleneck is to split a given string at given positions. The first and short version I wrote was (80% of 67 sec, i.e. ...
0
votes
1answer
394 views

Foreach vs Iterator [closed]

I have implemented a trim method which removes objects having empty properties. This list has average size of 3 or so. Probably, the max length is 7 or 8. I ...
2
votes
2answers
355 views

RTL management HTML & CSS

I've been working around a solution to easily manage LTR and RTL on the same interface. The different solutions I knew at first: Override CSS according to direction. Use a program to transform your ...
1
vote
2answers
107 views

Writing if..else construct without long condition checks to increase maintainability [closed]

Should writing if..else construct in the following manner be flagged for correction in peer code review? Existing Code ...
0
votes
0answers
66 views

Using a boolean column as an index to process rows vs partitions or other mechanisms

I receive files from many sources (SFTP, REST, SOAP, etc.) in many formats (CSV, JSON, XML, etc.) and then process them at a later time in a ...
1
vote
3answers
380 views

Checking if a string is a palindrome

This is the code for checking if a string is a palindrome. The execution time, for sample cases, is 0.40358 seconds. What must be done to increase the performance? ...