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
6
votes
3answers
129 views

Error handling for function calls to parse a GIF file

I'm debating which version would be more suitable in parameters of code length, readability and maintenance. This is a portion of a set of functions which together parse a Gif file. Version 1: ...
8
votes
4answers
489 views

Comparison between two design battle approaches

I've recently been learning about design patterns. Now I decided that I know enough to be able to refactor my inventory code. The question solely exist so I could show my fellow programmers the kind ...
0
votes
1answer
65 views

Selector on every radio button click

I am constructing a selector on every radio button click. Since I am using the table repeatedly on every radio click, I cached it like: var $t1 = $("#tableone"); ...
1
vote
2answers
174 views

Checking for null in delivery functions

In my Repository class: ...
5
votes
2answers
230 views

FIR filters in C

I wrote 2 filters in C for the Altera DE2 Nios II FPGA, one floating-point and one fixed-point. I've verified that they perform correctly and now I wonder if you can give examples for improvement or ...
3
votes
1answer
4k views

Function equivalent to strcmp()

I'm starting out and need feedback in order to discover the things I'm doing wrong. This is supposed to behave like strcmp(): ...
1
vote
2answers
140 views

Multiple independent or layered constructors for TicTacToe?

At first it was like this: ...
3
votes
2answers
602 views

Calculating Czechsum digits for barcodes

Every coder knows that if you give six developers an assignment to write a bit of code that will perform some specific task, you will end up with at least six different ways of doing it. I recently ...
3
votes
3answers
979 views

Validator classes

We're trying to design validation classes with a common interface. This would apply to all validators. We would define a validator interface with a ...
3
votes
2answers
241 views

Designing DAOs that handle composite objects

Suppose I have following elementary DTOs, each DTO corresponding to a database table: class Event { String name } class Player { String name } DAOs for ...
3
votes
2answers
232 views

Nested array-to-dict transformation

I'm looking to let people define arbitrarily nested lists of lists and return a random json document for them. Right now the assumption is that if you have a structure like this: ...
5
votes
2answers
7k views

Sending data through a TCP stream

I've noticed that there are several ways of sending data through a TCP stream. I want to do it the fastest way in terms of latency. One method I became aware of is with a binary writer: ...
12
votes
4answers
25k views

Split Collection to two list depend on criteria

Let's say I have a List contains numbers: 1,2,3,4,5,6,7,8,9 and I would like to split this to two lists: odd numbers even numbers So I can do this two ways: Solution 1: Create two methods: <...
1
vote
1answer
111 views

Reporting duplicate entry for a given set of data

While solving a problem on an online judge, I tried with these two implementations. These two implementations do the same thing. Task is to report duplicate entry for a given set of data. ...
5
votes
2answers
263 views

Defining entries [closed]

I am working on my own PHP MVCframework. Now I want to know where to get and specify my entities. For example, should I do this: ...
3
votes
2answers
362 views

My implementation of lexicographic permutation in F# is 3x slower than C#

Can someone help me with the following micro optimization for the F# code for lexicographic permutation? I have code in C# which runs for 0.8s. As a learning practice, I translated it into F#. ...
5
votes
1answer
341 views

Two keyboard handlers for a video game character

The code below is equivalent. I can see pros and cons for both versions. Which is better: the short, clever way, or the long, ctrl+c way? Short version: ...
3
votes
2answers
2k views

Square root approximations, implemented two ways

Which version is more efficient in calculating the square root ? There are 2 versions I have written to calculate square root programatically. Note reqs strictly state not using library functions ? ...
3
votes
2answers
159 views

Email template referencer

Which is best practice for creating an enum-like lookup for templates? I enjoy being able to bring up my templates with VS IntelliSense so either works for me. Option 1 (...
13
votes
2answers
19k views

Forking with PHP (4 different approaches)

I thought about three (now four) different ways how to execute forks with PHP. What is the faster, maybe better solution and why? PHP script included ...
0
votes
2answers
66 views

Different function test result inquiry

I decided to run a few test on js functions on jspref to see which method of using function is better suited for this small particular example, to get a better understanding. Page with tested ...
3
votes
3answers
679 views

Mimicking T9 cell messaging

Today I solved a question from Google Code Jam: mimicking a cell phone keypad messaging. Here is the program, with goto statements. I know it is an unstructured ...
8
votes
4answers
3k views

Given two sorted arrays, add the elements of the second array into the first

In Cracking the Coding Interview by Gayle Laakmann McDowell, there's a question that asks you to write code for the following: Given two sorted arrays, A and B. Write a method merging the elements ...
14
votes
3answers
5k views

Unit tests for testing error codes

Both unit tests pass and they both test the same thing. The production code uses the right error codes. System Under Test (SUT) ...
2
votes
1answer
254 views

Two JavaScript snippets to allow drawing on a canvas

I sat down to write a demo HTML5-ish page that lets a user to perform following operations on a canvas - draw lines, draw a filled rectangle, and reset the canvas. Each operation is represented by a ...
3
votes
1answer
154 views

Filtering Pinboard API results by tags

I've got a simple sinatra webapp that pulls data from Pinboard's RSS api, parses the info, and re-displays it. There are 4 tasks I need to perform with the data: I need to remove all instances of a ...
27
votes
4answers
94k views

Is the LINQ version faster than the foreach one?

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 ...
1
vote
2answers
4k views

Three ways to sum the values of letters in words

I've created these 3 functions to count the value of letters in a word. All these functions are functionally the same. Apparently List comprehensions (count_word3)...
4
votes
1answer
351 views

Three implementations of mergesort in F#

I would appreciate some quick comments on this basic mergesort code. Am I missing a big block in the langage? First solution ...
2
votes
1answer
3k views

Optimal method for writing bytes to file

I'm making a method to save a byte[] to a file. It's for a Java Helper I'm writing, so it needs to be able to handle any kind of system. I saw on this example the ...
3
votes
1answer
943 views

Which class is best to call .getResource on?

I'm creating a Java Helper Library with helpful static methods. I find myself needing to call ...getResource(...) or ...
2
votes
1answer
3k views

Image-resizing methods

I took a little heat on a method I had to resize an image and I'm hoping I can get a little help on the best way to do it. This is intended for a simple Java Helper Library I'm developing. I have a ...
0
votes
1answer
99 views

Fetching translated strings, keeping in the philosophy of Zend framework [closed]

I have been wondering this for a while. Take this example: <?= Zend_Registry::get('translate')->_('translate me!'); I have my views cluttured with such ...
4
votes
1answer
9k views

Reading a .gz file

I am using Python 2.6.5 and am trying to find the fastest way to print out the contents of a .gz file. It's my understanding that prior to v2.5, zcat was much faster than gzip (see here)....I guess ...
8
votes
3answers
3k views

Linking issues, classifying the relationship as a cause, effect, superset, etc

I first saw this gigantic if and tried to refactor it. Could only end with a endless switch statement. Old code - ...
5
votes
2answers
437 views

Partner mating game

I say this is right because X might happen and Y modification to the code is possible in the future. More senior guy says the sorta similar thing, except along the lines "I'm right, you're wrong." ...
1
vote
1answer
193 views

Encode strings by subtracting one from each character code

I currently have this encoding function which simply subtracts one from each character code: ...
7
votes
3answers
258 views

Enumerating new articles whose publication start date has passed

(cn.PublishEnd == null || cn.PublishEnd < DateTime.Now) vs (cn.PublishEnd ?? DateTime.MinValue < DateTime.Now) Which ...
2
votes
4answers
5k views

Calculating a base price with surcharge conditions

The following code has a lot of conditionals. I am trying to write it in a functional programming way. ...
3
votes
2answers
361 views

Two code snippets involving time-change

I have two snippets that are going to be used in a walkthrough and I'd like some feedback on which one is more easily understandable 1 ...
3
votes
5answers
291 views

Finding array indices that add up to another number

I'm writing a method that takes (1) an array of ints and (2) an int. The purpose of the method is to find the indices of the ...
1
vote
2answers
496 views

Setting the path to toolbarAssociatedXibName, with fallback

I have some code that I've included in a project I want to release. Here is one such block: ...
5
votes
5answers
781 views

Representing the opening and closing time for a business

I have an OpenClose class which just represents the hours of operation of a business by the opening and closing time. It takes the opening and closing times as arguments to its constructor, and each ...
11
votes
4answers
2k views

Generating the sequence of the digits that appear in the sequence of natural numbers

This is a revisit to a question already asked here about a year and a half ago. Project Euler's Problem 40 involves generating the sequence of digits that appear in the natural numbers, all ...
18
votes
11answers
1k views

Reversing a string

I had this as an interview question, and the interviewer pointed this out. Here's what I wrote: ...
4
votes
1answer
2k views

Should I use atexit to close db connection?

I just realized that I could turn: ...
1
vote
2answers
12k views

Reading file contents into a string

Option 1 - nice and simple ...
14
votes
8answers
26k views

Two FizzBuzz solutions

Below are two solutions to the FizzBuzz problem in Python. Which one of these is more "Pythonic" and why is it more "Pythonic" than the other? Solution One: ...
5
votes
1answer
294 views

Interop: Return Parameter Method as Void

For interop purpose, this is something that I always do (C#): public static extern BigObject InteropWithCPlusPlus(); where ...
13
votes
6answers
2k views

“Do you owe the government?” classes

Should my class pass parameters internally or reference class level scoped variables? I'm not sure on the best approach or style for procedure calls that have parameters. Should I go with the class ...

1
13 14 15 16
17