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
39
votes
10
answers
10k
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 ...
36
votes
3
answers
11k
views
Ensuring user input is an integer in a range
I have isolated a little bit of code that was causing a small debate between myself and another user. I have taken some of the things that he said and meshed it with the code that was being reviewed ...
33
votes
6
answers
3k
views
To 'this' or not to 'this'?
I was given a homework and I have 2 solutions: one that uses this and other one that doesn't.
I tested both solutions on jsPerf but sometimes it says the version ...
30
votes
9
answers
58k
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:
...
30
votes
3
answers
2k
views
Java method - levels of abstraction
In his Clean Code book, Robert C. Martin states that functions should do only one thing and one should not mix different levels of abstraction. So I started wondering whether the code below meets ...
27
votes
4
answers
102k
views
Filtering a list of vertices that lie inside a cylinder, with and without LINQ
Since I don't know how LINQ works under the hood, I can't decide what version is best to use in term of rapidity of execution. I've done some testing with my testing data (Point Cloud) but I can't see ...
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; ...
23
votes
5
answers
2k
views
When a constructor calls a helper function, should the helper mutate the object or return part of the object?
I have a private method that is called from the constructor to instantiate a bunch of objects.
I can do it two ways.
...
19
votes
2
answers
597
views
Count the occurence of nucleobases in DNA string
Inspired by this meta question I decided to take a look at Rosalind. Their first challenge seemed easy enough:
An example of a length 21 DNA string (whose alphabet contains the symbols 'A', 'C', 'G', ...
18
votes
4
answers
11k
views
20 Ways to do Random Sampling
Here is a (small project) code for practicing Python, it comprises 20 variety of functions that each works to return \$n\$ random samples from a set of data.
The code mostly uses the ...
18
votes
11
answers
1k
views
Reversing a string
I had this as an interview question, and the interviewer pointed this out. Here's what I wrote:
...
18
votes
1
answer
3k
views
Subclassing pathlib.Path
This arises from the SO Question subclassing pathlib.Path.
The pathlib sources show that Path, when invoked, selects one of ...
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 ...
17
votes
3
answers
4k
views
On Knuth's "Algorithm L" to generate permutations in lexicographic order
I needed a method to generate all permutations of given elements, so I decided to
implement "Algorithm L (Lexicographic permutation generation)" from
Donald E. Knuth, "GENERATING ALL PERMUTATIONS"
in ...
16
votes
4
answers
3k
views
Sieve of Sundaram for Project Euler 7: Python implementation slower than C++ and R
A friend of mine recently started learning R, and she complained to me that R is very slow. She was working on Project Euler Problem 7, which asks for the value of the 10001st prime number. For ...