Skip to main content

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).

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 ...
arc4randall's user avatar
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 ...
Malachi's user avatar
  • 28.7k
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 ...
Rahul Desai's user avatar
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: ...
Rohit's user avatar
  • 1,066
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 ...
cafe_'s user avatar
  • 465
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 ...
Jean-François Côté's user avatar
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 n​th number in the Fibonacci series. I used to solve the problem using a for loop; ...
David Peterson's user avatar
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. ...
dwjohnston's user avatar
  • 1,308
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', ...
Mast's user avatar
  • 13.4k
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 ...
Redsbefall's user avatar
  • 1,132
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: ...
Billy ONeal's user avatar
  • 1,460
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 ...
Carel's user avatar
  • 301
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 ...
rogday's user avatar
  • 403
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 ...
Martin R's user avatar
  • 23.3k
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 ...
castle-bravo's user avatar

15 30 50 per page
1
2 3 4 5
63