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
0
votes
1answer
94 views

Using method which return a String or creating wrapper for String

Which approach is better and why? First approach (inner class for wrapping): ...
0
votes
1answer
175 views

Make sequential fadeIn() promises more manageable

I've two versions of promise code. The page is a simple one - an unordered list with a few items. I am trying to make the items show up (fadeIn) one-after-another ...
2
votes
2answers
1k views

SPOJ problem: Life, the Universe, and Everything

Your program is to use the brute-force approach in order to find the answer to Life, the Universe, and Everything. More precisely, rewrite small numbers from input to output. Stop processing input ...
0
votes
1answer
176 views

Approximate integral in one line of code

This is what I came up with: Version 1: ...
6
votes
3answers
125 views

Two implementations of file-reading

I work quite a lot with file reading and writing in C/Win32 and I started wondering if my code is completely ugly and how I can improve it. I wrote two simple examples of reading a file, and I wonder ...
0
votes
2answers
97 views

Enabling or disabling a login view based on authentication state

Is it good to have this: ...
3
votes
1answer
94 views

Calculating set difference of lists with or without intermediate variables

Which form of the method do you find more readable? Version with local variables: ...
2
votes
3answers
1k views

Just require a file, or check if_readable first?

I'm writing a simple front controller, index.php is the main file. In my index.php, first thing loaded is ...
6
votes
3answers
944 views

For a query over multiple databases, is it faster to do GROUP BY first or UNION first?

Having several databases with the same table, I need to group the union of the records. The xTables are stored in separate databases named by the year (this is by ...
5
votes
1answer
1k views

Function to run MySQL SELECT queries with no leaks

I am upgrading an old massive website that is a Classic ASP \ ASP.NET hybrid. I still have a long way to MVC. Right now I want to convert all code that uses ODBC to the mysql connector specific code. ...
0
votes
2answers
347 views

Pick a column for each row by column-header name

I am parsing a table: |-------| |Bar|Foo| |-------| | 5 | 6 | |'f'|'g'| | 1 | 8 | |_______| I've tried a number of ways of writing a <...
10
votes
4answers
7k views

Trimming fgets(): strlen() or strtok()

After a successful fgets(buffer, ...), it is often desirable to trim a potential End-of-Line '\n'. Of the following 2 methods, ...
2
votes
3answers
3k views

Chain of Responsibility Design pattern in C++

I am learning design patterns from Design pattern for dummies. From that book I have written a chain of responsibility pattern with two programs. Can someone review and let me know which one is proper ...
4
votes
1answer
2k views

Fast regex to extract strings before and after a time

I want to get text1 and text2 by splitting time format Text1 10:24:02 Text2 Of the two ...
2
votes
2answers
393 views

Comparing equivalent Scala and C# string-manipulation code - with Scala running much slower

I am very early in my journey of learning Scala, and I was doing challenges on hackerrank.com to get used to the syntax. As I finished one (very trivial) challenge, I noticed that the run times seem ...
2
votes
1answer
181 views

Correct way to refer to a view in Android

What is the correct way of referring to a view (a) or (b).? (a). TextView textView = (TextView) rootView.findViewById(R.id.text); textView.setText("Some Text"); ...
12
votes
2answers
16k views

Async/await and Task vs Task.Factory.StartNew and Result

I am working on creating some libraries for a project at work and I wanted to make sure I have this pattern correct. Assuming that the GetWidgets method is what I ...
6
votes
2answers
415 views

Lopsided Trees and Recursion

The original problem is: Define the height of a binary tree to be the number of nodes in the longest path from the root to a leaf. The empty tree is considered to have height 0. A node is k-...
8
votes
3answers
14k views

Generating a not-the-same-as-last-time random number

I have to generate random number which differs from the number generated last time. Which of these two variants is better? Or maybe you can suggest better implementation. ...
4
votes
2answers
1k views

Assigning a value to a class variable

I have tried the following code: ...
4
votes
1answer
348 views

CodeEval Sequence Transformation

I've been working on this challenge for a week: There are two sequences. The first sequence consists of digits "0" and "1", the second one consists of letters "A" and "B". The challenge is to ...
8
votes
3answers
2k views

Indentation on a long (ish) linq chain

I have some code that loops through directories named for years (e.g. /2011/, /2012/ etc) which each contain files whose names ...
5
votes
3answers
771 views

Comparison between strings

This review is very short and very straight-forward. There are two people in the team and the checked-in code looks as follows. ...
6
votes
2answers
32k views

Inserting multiple rows in MySQL

I am building a store. When a user decides to make a purchase I need to store it in the database, but since the purchase might be of more than 1 item I'm wondering which way is the best to insert ...
9
votes
1answer
515 views

Horridly Inefficient Project Euler #14 in Python - Collatz Sequences

I created this solution a while ago, and have been going back over my problems to try to make them all more efficient. I have been stuck on this one, and have tried a few different ideas. So far, my ...
3
votes
3answers
1k views

Parsing and formatting a time two ways (perfectionistic approach)

I'm still not satisfied by the readability of the code. The wanted behavior which would be self descriptive would sound like: "I've two fields; one is for the date and one for the hour. This two ...
4
votes
2answers
1k views

MySQL query to find country and state of active users

Is there any reason NOT to wrap a long query over multiple line via new lines vs using concatenation? For example, consider this: ...
1
vote
1answer
83 views

Conditional AND statement- which is more readable? [closed]

Does this function automationStatusIsSuccessful = (data) -> data.Automation.Status isnt "FAILED" and data.Automation.Status isnt "COMPLETEDWITHERROR"` ...
3
votes
1answer
157 views

Correct practice for Python properties that depend on other attributes

When a property is essentially a boolean value for whether or not an attribute exists or is set a certain way, is it more appropriate to create an object that does not list the option attribute in its ...
3
votes
1answer
500 views

Comparing different string-matching functions

Here is a problem came from codingbat: Given 2 strings, a and b, return the number of the positions where they contain the same length 2 substring. So "xxcaazz" and "xxbaaz" yields 3, since the ...
2
votes
1answer
638 views

Which is a better implementation of a stack data structure (based on an array)?

This is a version I made: ...
3
votes
2answers
128 views

Comparing two bubble sort algorithms

I'm learning C and I've got to a point learning about different sorting algorithms. Before seeing how it was done, I wanted to try doing it myself based on what I read on how it's working. ...
3
votes
1answer
2k views

Extracting data from an array of arrays

I was browsing Stack Overflow recently and saw a PHP question about rearranging an array of arrays for printing. The initial data structure looked like this: ...
1
vote
1answer
99 views

Two implementations of website internationalization

I have attempted to create an internationalization system for my PHP framework that I'm working on. For the purpose I decided I will be using MySQL to store languages and translations. Respectively I ...
2
votes
2answers
146 views

“Reverse Groups” challenge

I'm trying to do the Reverse Groups Challenge on CodeEval: Given a list of numbers and a positive integer k, reverse the elements of the list, k items at a time. If the number of elements is not a ...
4
votes
1answer
235 views

Using temporary variables or calling a method directly

Which of these approaches for a button click is better/faster/more efficient, and why? Approach One: ...
6
votes
3answers
6k views

Comparison of PHP/Yii controllers

I was recently asked to write a Question-and-Answer feature for my company's product pages using Yii 1. It was my first Yii project, and it was a little rough around the edges (Code A). However, when ...
38
votes
10answers
7k views

Which FizzBuzz is better, and why?

I was in an interview and the guy asked me to do the typical FizzBuzz question of printing numbers 1-100, but for each factor of 3 print Fizz, each factor of 5 print Buzz, and each factor of both ...
2
votes
0answers
51 views

Web component design, attribute or content HTML?

Which one of these web components is designed better? Option 1 contains an a tag within the custom element. ...
3
votes
1answer
70 views

Improving fading functions

Regarding these two functions, which do the same thing... Large and confusing: ...
2
votes
1answer
67 views

Readability of two rectangular point function samples

I have two implementations of the same function. Which of these is easier to understand? Code sample A ...
10
votes
6answers
3k views

Getting filtered autolist

Is there a better way to write the following code fragment? I can't have more than 10 conditional statement in my method as it gives cyclomatic complexity. ...
2
votes
4answers
119 views

Java sort by selection: which is better in regards to readability and efficiency?

Which algorithm do you think is better in regards to readability and efficiency? selection(): ...
8
votes
5answers
28k views

Checking if an array is sorted

I've come up with two ways to check to see if array is sorted and return true if it is. ...
28
votes
9answers
57k views

Check a string to see if it is a palindrome

I have written two code pieces to check if a given string is a palindrome: ...
4
votes
3answers
10k views

Codility Frog Jump solutions [closed]

Problem details from Codility: A small frog wants to get to the other side of the road. The frog is currently located at position X and wants to get to a position greater than or equal to Y. The ...
3
votes
1answer
559 views

Three implementations of observable objects

I wonder, what might be the best (most pythonic) way of implementing multiple observerables in Python. There are multiple objects, which should be able to register themselves at one or multiple ...
7
votes
3answers
5k views

Understanding the differences: A direct comparison between Cython and C++ [closed]

Introduction: The following two code samples are a direct comparison of performance between Cython and C++. I pieced them together with the help of others-- I barely understand how they work. Their ...
5
votes
2answers
955 views

Providing const- and non-const overloads of a strstr() implementation

In a question about reimplementing strstr(), I posted an answer. I pointed out a need for const- and non-const versions of the function, and provided ...
2
votes
2answers
140 views

Two-dimensional array allocation in Go

I am creating a two-dimensional array, which I am going to process later in ways similar to image MinFilter, procedural labyrinth generation, etc. -- implying using coordinates and neighbors. Here ...