language-agnostic

Where would you use a Builder Pattern instead of an Abstract Factory?

I've seen this question rise here and there a few times, but I never found and answer I was happy with. From Wikipedia: Builder focuses on constructing a complex object step by step. Abstract Factory emphasizes a family of product objects (either simple or complex). Builder returns the product as a final step, but as far as the Abst...

Code Golf: New Year's Fireworks

The year 2009 is coming to an end, and with the economy and all, we'll save our money and instead of buying expensive fireworks, we'll celebrate in ASCII art this year. The challenge Given a set of fireworks and a time, take a picture of the firework at that very time and draw it to the console. The best solution entered before midnig...

What Use are Threads Outside of Parallel Problems on MultiCore Systesm?

Threads make the design, implementation and debugging of a program significantly more difficult. Yet many people seem to think that every task in a program that can be threaded should be threaded, even on a single core system. I can understand threading something like an MPEG2 decoder that's going to run on a multicore cpu ( which I've...

Generating a Not-Quite-Globally Unique Identifier

I've found a number of different questions on generating UIDs, but as far as I can tell, my requirements here are somewhat unique (ha). To summarize: I need to generate a very short ID that's "locally" unique, but does not have to be "globally" or "universally" unique. The constraints are not simply based on aesthetic or space concerns...

Function to determine number of unordered combinations with non-unqiue choices

I'm trying to determine the function for determining the number of unordered combinations with non-unique choices. Given: n = number of unique symbols to select from r = number of choices Example... for n=3, r=3, the result would be: (edit: added missing values pointed out by Dav) 000 001 002 011 012 022 111 112 122 222 I know th...

Code Golf: Lights out!

The challenge The shortest code by character count to solve the input lights out board. The lights out board is a 2d square grid of varying size composed of two characters - . for a light that is off and * for a light that is on. To solve the board, all "lights" have to be turned off. Turning off a light is made 5 lights at a time - t...

Balancing Design Principles: Unit Testing

I am writing a simulation of Bananagrams. Currently, I have a GameMaster class that maintains the common collection of pieces. The deal(Player) method deals a certain number of pieces to that player. I want to write unit tests for this. However, at this point, I have no getters, and thus no way to check the status of the objects. Why n...

Requirements Smells

We've all heard and debated about Code Smells, and occasionally you hear people talking about "design smells", so I've been thinking, why not take it one step further? If you deal directly with customers or have to interpret functional requirements, you'll be familiar with the sensation: It sounds like a really bad idea, it's probably c...

Are long-living transactions acceptable?

I am thinking about using transactions in 2-tier WPF (or windows forms) applications in following way: We can begin new transaction when we open new form for editing data, edit and persist changes transparently in this transaction. Then we can click "OK" button and commit transaction, or "Cancel" button and rollback it. If we want to op...

Iterative hashing

I'm just wondering, is there a reason why some libraries (be it any language) use iterative hashing such that the hashed data is encoded in hex and rehashed again instead of rehashing the actual binary output? ...

What is thread contention?

Can someone please explain simply what thread contention is? I have googled it, but cannot seem to find a simple explanation. Thanks ...

Webservice test isolation - but when to verify the webservice itself?

I am isolating my webservice-related tests from the actual webservices with Stubs. How do you/should i incorporate tests to ensure that my crafted responses match the actual webservice ones (i don't have control over it)? I don't want to know how to do it, but when and where? Should i create a testsuite-testsuite for testdata testing?...

kernel stack vs user-mode application stack

Is the kernel stack a different structure to the user-mode stack that is used by applications we (programmers) write? Can you explain the differences? ...

Advice on running my development tools in a virtual machine

I am starting to get quite sick and tired of setting up all my dev tools every time that I need to move to a new machine, or get a laptop, or screw up my registry with constant installs and uninstalls. So new plan. I have heard of people virtualizing their development environment and this sounds like a great idea. Only problem is that...

Hooking into a wave-out on different platforms

I am going to apologize in advance for being extremely vague, but my knowledge in this area is somewhat limited so I don't know the neccessary "keywords" to make my point/question clear. Sorry. What I want to do is to find a way to obtain access to raw audio data as it is being output, say, when some external application is playing back...

What should every developer know about databases?

Whether we like it or not, many if not most of us developers either regularly work with databases or may have to work with one someday. And considering the amount of misuse and abuse in the wild, and the volume of database-related questions that come up every day, it's fair to say that there are certain concepts that developers should k...

Formatting a String Array to Display to Users

What is the best format to communicate an array of strings in one string to users who are not geeks? I could do it like this: Item1, Item2, Item3 But that becomes meaningless when the strings contain spaces and commas. I could also do it this way: "Item1", "Item2", "Item3" However, I would like to avoid escaping the array elements ...

Reversing every character in a file

I'm in a little trouble here. Can anyone help me implement a solution that reverses every byte so 0xAB becomes 0xBA but not so "abcd" becomes "dcba". I need it so AB CD EF becomes BA DC FE. Preferably in C or C++ but it doesn't really matter provided it can run. So far, I've implemented a UBER CRAPPY solution that doesn't even work (a...

Data source for all the roads in the world?

For no reason in particular, I'm curious what the expected number of feet you would have to walk to find the nearest road is, starting from a random point on the world, facing a random direction. I can write a program to compute this value, given the right data source. Is there any data source containing all the roads in the world? For ...

Randomized algorithm for finding hamiltonian path in a directed graph.

From this Wikipedia article: http://en.wikipedia.org/wiki/Hamiltonian_path_problem A randomized algorithm for Hamiltonian path that is fast on most graphs is the following: Start from a random vertex, and continue if there is a neighbor not visited. If there are no more unvisited neighbors, and the path formed isn't Hami...