language-agnostic

Message Passing Arbitrary Object Graphs?

I'm looking to parallelize some code across a Beowulf cluster, such that the CPUs involved don't share address space. I want to parallelize a function call in the outer loop. The function calls do not have any "important" side effects (though they do use a random number generator, allocate memory, etc.). I've looked at libs like MPI...

Determine how fine-grained an interface should be?

The more detail I put in an interface, the less reusable it is. On the other hand the less detail the more ethereal and useless it seems to become. Is there a standard set of recommendations about how to weigh this for various situations? ...

Converting a math problem into a discrete-event simulation

I am trying to implement the SIR epidemic model. Basically, the way I understand the model is that at each time step, it tells us how many nodes get infected and how many nodes are recovered. I am now trying to convert this into an discrete-event simulation and am confused at a point. The model is generally solved using Euler's method. ...

How exactly do "Objects communicate with each other by passing messages" ?

In several introductory texts on Object-oriented programming, I've come across the above statement. From wikipedia, "In OOP, each object is capable of receiving messages, processing data, and sending messages to other objects and can be viewed as an independent 'machine' with a distinct role or responsibility." What exactly does the s...

My first e-commerce site, or how I learned to stop worrying and love credit card transactions

Sooner or later it's going to happen. A freelance client is going to want an e-commerce website, and while the programming doesn't scare me, the handling of other people's money does. Thing like this should be done right. So, successful e-commerce site builders, what did you learn before and after your first e-commerce site to make you ...

When, if ever, is loop unrolling still useful?

I've been trying to optimize some extremely performance-critical code (a quick sort algorithm that's being called millions and millions of times inside a monte carlo simulation) by loop unrolling. Here's the inner loop I'm trying to speed up: // Search for elements to swap. while(myArray[++index1] < pivot) {} while(pivot < myArray[--in...

Garbage Collection

Hi All, I am not able to understand few things on the Garbage collection. Firstly, how is data allocated space ? i.e. on stack or heap( As per my knowledge, all static or global variables are assigned space on stack and local variables are assigned space on heap). Second, GC runs on data on stacks or heaps ? i.e a GC algorithm like ...

How to find permutation of k in a given length?

How can I find the permutations of for example 2 in a size of 3. For example: The word cat has 3 letters: How can I find all the permutations of 2 in the word cat. Result should be: ac, at, ca, ac, etc... This is not a homework problem. Any language could be used but more preferable: C/C++ or C#. I know how to create the recursion ...

How to draw a tiger with just 3 lines?

Background: An art teacher once gave me a design problem to draw a tiger using only 3 lines. The idea being that I study a tiger and learn the 3 lines to draw for people to still be able to tell it is a tiger. The solution for this problem is to start with a full drawing of a tiger and remove elements until you get to the three parts...

Is there an O(n) integer sorting algorithm?

The last week I stumbled over this paper where the authors mention on the second page: Note that this yields a linear running time for integer edge weights. The same on the third page: This yields a linear running time for integer edge weights and O(m log n) for comparison-based sorting. And on the 8th page: In particular...

Most effective way of dealing with open problems in programming

I program in C++. Sometimes there are 1000 ways to do something, and depending on the inspiration/energy, etc of the moment, I can take "the right one" or not, and spend 10 minutes or three days to solve a problem or find a solution or do a task for the boss. When you are programming, how do you deal with this "open" situations? Use you...

What technique do I use for when I want to check all possible combinations of a set?

I'm working through an interview question that goes like: Given an array of integers and sum, check whether any combination adds up to the sum. What programming technique does one use when they want to try all possible combinations of a set? Even if that isn't the best solution to this problem, I come across problems where I...

How to write a php search script in which words with diacritics match search terms without diacritics, and the results are underlined?

Hi all! I've got this site where there are lots of texts with diacritics in them (ancillary glyphs added to letters, according to wikipedia) and most people search these texts using words without the glyphs. Now it shouldn't be challenging to do this by having a copy of the texts without diacritics. However, I want to highlight the matc...

Pair programming: How should the pairs be chosen?

This topic has been covered peripherally in bits and pieces in some of the other pair-programming questions, but I want to (a) consolidate this knowledge into a separate question, and, most importantly, (b) go into much more depth on the subject. From the perspective of being an effective manager, how should pairs be arranged for pair p...

Integration testing - seeking your knowledge, advice and links!

Hey guys, I'm after some advice and pointers on integration testing for a web app. Our project has been running for a number of years and it's reasonably complex. We're pretty well covered with unit tests but we're missing a decent set of integration tests. We don't have documented use cases or even a reasonable set of test cases beyo...

Open-source echo server

Does anyone know any open-source echo server? I know I could write one by myself, but I'd like something more fancy with ability to listen on certain port(s), send keep-alives etc. so developing this myself would take likely hours. ...

Is the ability to estimate hours an essential quality of a programmer?

Is it possible to be a great programmer without being great at estimating time for a given task? Can you be great at one and not great at the other and still be 'successful'? ...

When does this happen? Thread suspended while in critical section

I'm just wondering, if a thread is in a critical section, can it be preempted? Thread A: Enter CR Thread A: Get suspended Thread B: Wants to enter CR but can't, because Thread A has the lock If Thread A preempted, and so the mutex lock is stuck with Thread A, what can be done about this? ...

Ordering concurrent tasks to minimise waiting

In a system with multiple concurrent tasks operating on data, I want to order the tasks such that there is a minimum amount of waiting time involved. Each task in the system uses a certain set of resources, tasks are issued in a certain order (this order is what I want to calculate), a task will not start until it can get a lock on all r...

"Round half up" on floating point values

We are stuck with a database that (unfortunately) uses floats instead of decimal values. This makes rounding a bit difficult. Consider the following example (SQL Server T-SQL): SELECT ROUND(6.925e0, 2) --> returns 6.92 ROUND does round half up, but since floating point numbers cannot accurately represent decimal numbers, the "wrong"...