language-agnostic

What exactly is GUID? Why and where I should use it?

What exactly is GUID? Why and where I should use it? I've seen references to GUID in a lot of places, and in wikipedia, but it is not very clear telling you where to use it. If someone could answer this, it would be nice. Thanks ...

How Does Differential Execution Work?

I've seen a few mentions of this on SO, but staring at Wikipedia and at an MFC dynamic dialog demo did nothing to enlighten me. Can someone please explain this? Learning a fundamentally different concept sounds nice. Edit: I think I'm getting a better feel for it. I guess I just didn't look at the source code carefully enough the firs...

Code Golf: How do I write the shortest character mapping program?

I learned a lot about various languages last time I did one of these, so I figured I'd submit another. Community Wiki of course... All programming languages are acceptable. The goal is to create the program in a language with the least amount of characters. New lines and indenting should be left in for clarity, but not counted. Try ...

Computing a 95% confidence interval on the sum of n i.i.d. exponential random variables.

Let's in fact generalize to a c-confidence interval. Let the common rate parameter be a. (Note that the mean of an exponential distribution with rate parameter a is 1/a.) First find the cdf of the sum of n such i.i.d. random variables. Use that to compute a c-confidence interval on the sum. Note that the max likelihood estimate (MLE...

How do you implement XOR using +-*/ ?

How can the XOR operation (on two 32 bit ints) be implemented using only basic arithmetic operations? Do you have to do it bitwise after dividing by each power of 2 in turn, or is there a shortcut? I don't care about execution speed so much as about the simplest, shortest code. Edit: This is not homework, but a riddle posed on a hacker....

When would you use the mediator design pattern

As the title states when would you recommend the use of the mediator design pattern and where do you see it used incorrectly? ...

Examples of design pattern misuse

Design patterns are great in that they distill a potentially complex technique into something idiomatic. Often just the fact that it has a name helps communication and understanding. The downside is that it makes it easier to try to use them as a silver bullet, applying them to every situation without thinking about the motivation behin...

Why would you use a message based system?

What are the motivations for using a message based system? I'm seeing a lot about service buses such as NServiceBus and Mass Transit and I'm wondering what the benefits of the underlying methodology are. ...

Many threads or as few threads as possible?

As a side project I'm currently writing a server for an age-old game I used to play. I'm trying to make the server as loosely coupled as possible, but I am wondering what would be a good design decision for multithreading. Currently I have the following sequence of actions: Startup (creates) -> Server (listens for clients, creates) ->...

Techniques for building HTML in code.

An html template is compiled into the application as a resource. A fragment of the HTML template looks like: <A href="%PANELLINK%" target="_blank"> <IMG border="0" src="%PANELIMAGE%" style="%IMAGESTYLE%"> </A><BR> %CAPTIONTEXT% i like it like this because the larger resource HTML file contains styling, no-quirks mode, etc. But as ...

What are some other languages that support "partial specialization"?

Partial template specialization is one of the most important concepts for generic programming in C++. For example: to implement a generic swap function: template <typename T> void swap(T &x, T &y) { const T tmp = x; y = x; x = tmp; } To specialize it for a vector to support O(1) swap: template <typename T, class Alloc> void swa...

Why the use of both a base class and an interface in polymorphism?

In the C# example of polymorphism, there is a Cat class which inherits a class called AnimalBase and an interface called IAnimal. The link in question is: http://en.wikipedia.org/wiki/Polymorphism_in_object-oriented_programming My question is, why is both a base class and an interface used? Why not one or the other? I was of the schoo...

How can I best apply OOP principles to games and other input-driven GUI apps?

Whenever I try to write graphical programs (whether a game or really any GUI app) I always wind up with one or two god classes with way too many methods (and long methods, too), and each class having far too many responsibilities. I have graphics being done at the same time as calculations and logic, and I feel like this is a really bad ...

What naming convention do you use for member variables?

What do you use to denote a member variable in a class? The most common time this is a problem is when you have a parameter passed into a constructor to set a member variable. Here is an example: public MyClass(string name) { name = name; // arghh!! } I've used m_name before, but that stinks of Hungarian. I've used _name before...

Why do I sometimes hear the term "lexical variable?"

I've seen the term "lexical variable" a few times, mostly in the context of closures. Paul Graham uses the term in his books on Lisp referring to variables defined using the let expression. I understand that lexical scoping is another name for static scoping. Is lexical variable just a variable that is visible in a program unit's refer...

How can threads be avoided?

I've read a lot recently about how writing multi-threaded apps is a huge pain in the neck, and have learned enough about the topic to understand, at least at some level, why it is so. I've read that using functional programming techniques can help alleviate some of this pain, but I've never seen a simple example of functional code tha...

Separate Class vs Method

Quick design question. ClassA has a method called DoSomething(args) In DoSomething(), before it can actually do something, it needs to do some preparatory work with args. I believe this should be encapsulated within ClassA, (as opposed to doing the prep work outside and passing it in) as nothing else needs to know that this prep work ...

When would you use Infinity?

So in Ruby there is a trick to specify infinity: 1.0/0 => Infinity I believe in Python you can do something like this float('inf') These are just examples though, I'm sure most languages have infinity in some capacity. When would you actually use this construct in the real world? Why would using it in a range be better than just us...

Assertion messages: assume failure, or assume success

When testing in any language, how does everybody phrase their assertion messages? I see three obvious ways: # assume failure assert (4-2) == 2, "Subtracting 2 from 4 doesn't equal 2" # describe success assert (4-2) == 2, "Subtracting 2 from 4 should equal 2" # be vauge with failure assert (4-2) == 2, "Subtracting 2 from 4 is broken" ...

Code Golf: Print the entire "12 Days of Christmas" song in the fewest lines of code.

Print all 12 verses of the popular holiday song. By 12 verses I mean the repetition of each line as is sung in the song, ie Verse One: On the first day of Christmas my true love gave to me a partridge in a pear tree. Verse Two On the second day of Christmas my true love gave to me two turtle doves and a partridge in a pear tree. ... ...