language-agnostic

Using Traveling Salesman Solver to Decide Hamiltonian Path

This is for a project where I'm asked to implement a heuristic for the traveling salesman optimization problem and also the Hamiltonian path or cycle decision problem. I don't need help with the implementation itself, but have a question on the direction I'm going in. I already have a TSP heuristic based on a genetic algorithm: it assum...

Whats the difference between C# delegates, Dynamic Proxy, Closures and function pointers?

What are useful definitions for the common methods of passing a method or function as data, such as: Delegates Closures Function pointers Invocation by dynamic proxy and First class methods? ...

Project / code release strategy

Context: I work at a small software company that has traditionally done research-type work, and does not have much experience in the commercial space. We are now trying to push into the commercial world. Due to our origins in research we are used to a very rapid development cycle and very little structure in terms of maintaining proper v...

Where to translate message strings - in the view or in the model?

We have a multilingual (PHP) application and use gettext for i18n. There are a few classes in the backend/model that return messages or message formats for printf(). We use xgettext to extract the strings that we want to translate. We apply the gettext function T_() in the frontend/view - this seems to be where it belongs. So far we ke...

How do you name your filter methods? Do you use "By" or "With"?

I am working on a library that will contain many filter methods. I have seen many project that use this syntax for filters public Foo GetFooByBar(bar); In other project people use this syntax public Foo GetFooWithBar(bar); Since this library will be reused by many other developers I wanted to know which one developers feel more co...

How can you walk through an integer range in an unpredictable order?

How can you loop over a fixed range of integers (say 100000-999999) in a difficult-to-predict order? assume the range may be large enough that it would be impractical to store every possible integer in an array or keep an array of every element you've found so far. you must hit every number in the range once and only once, and be able ...

How would you write this algorithm for large combinations in the most compact way?

The number of combinations of k items which can be retrieved from N items is described by the following formula. N! c = ___________________ (k! * (N - k)!) An example would be how many combinations of 6 Balls can be drawn from a drum of 48 Balls in a lottery draw. Optimize this formula to run with the smallest ...

Book or online resource explaining BDD

The Wikipedia article about Behavior Driven Development gives a nice overview about the topic, and many tools are listed. However, in order to dig deeper and really grasp the mindset of BDD, what other resources are there? Language agnostic material appreciated. ...

Way to encrypt a single int

How can you inexpensively two-way encrypt a 32 bit int, such that every number maps to some other int in that space and back in a way that's difficult to predict? And doesn't require pre-storing 4.29 billion ints in a mapping table, of course. ...

How to tell someone that their mod's to my program are not good?

G'day, This is related to my question on star developers and to this question regarding telling someone that they're writing bad code but I'm looking at a situation that is more specific. That is, how do I tell a "star" that their changes to a program that I'd written are poorly made and inconsistently implemented without just sounding...

If a console program terminates, will the database connections used in the program still remain open?

In Java and C#, they both have something like System.terminate(). If my program has open database connections, database readers, and database command variables, and I terminate my program in a catch clause, will database resources still remain in use? or will they be freed automatically since my entire program has just exited? Normally,...

If you could give yourself programming advice in the past, what would it be?

Possible Duplicate: One piece of advice I was talking with some friends (about C++ programming), and someone ended up saying "I wish I could have known about the STL when I started C++." We got into an interesting conversation on advice we would have given to ourselves had we been able. I thought I would present the question he...

What is the MVC version of this code?

i'm trying to wrap my head around how to enterprise up my code: taking a simple routine and splitting it up into 5 or 6 methods in 3 or 4 classes. i quickly came up three simple examples of code how i currently write it. Could someone please convert these into an MVC/MVP obfuscated version? Example 1: The last name is mandatory. Col...

Private beta test communication and infrastructure

So your commercial app is in the middle stages of development.. enough that it's usable but still needs refinement, extension, bugfixing. It's far from shippable, but it's stable and complete enough that your developers and in-house testers/users feel it's time for more feedback from real users. So you go to a wider but still closed bet...

O(N log N) Complexity - Similar to linear?

Hey All, So I think I'm going to get buried for asking such a trivial question but I'm a little confused about something. I have implemented quicksort in Java and C and I was doing some basic comparissons. The graph came out as two straight lines, with the C being 4ms faster than the Java counterpart over 100,000 random integers. Th...

Should I use composite primary keys or not?

There seems to only be 2nd class support for composite database keys in Java's JPA (via EmbeddedId or IdClass annotations). And when I read up on composite keys, regardless of language, people keep coming across as them being a bad thing. But I cannot understand why. Are composite keys still acceptable to use these days? If not, why not?...

How to unit-test sequential logic?

Suppose I have class Car with following methods: LoadGasoline(IFuel gas) InsertKey(IKey key) StartEngine() IDrivingSession Go() the purpose of Car is to configure and return an IDrivingSession which the rest of the application uses to drive the car. How do I unit-test my Car? It looks like it requires a sequence of operations done b...

Produce a sentence from a grammar with a given number of terminals

Say you've got a toy grammar, like: (updated so the output looks more natural) S -> ${NP} ${VP} | ${S} and ${S} | ${S}, after which ${S} NP -> the ${N} | the ${A} ${N} | the ${A} ${A} ${N} VP -> ${V} ${NP} N -> dog | fish | bird | wizard V -> kicks | meets | marries A -> red | striped | spotted e.g., "the dog kicks the red wizard...

Code Golf: Shortest code to find a weighted median?

My try at code golfing. The problem of finding the minimum value of ∑W_i*|X-X_i| reduces to finding the weighted median of a list of x[i] with weights w[i] (see below for definition). How will you do that with a shortest, simplest and most beautiful program? Here's how my code looked originally (explanation is in the answer to the ques...

Union of All Intersecting Sets

Given a list of objects with multiple attributes I need to find the list of sets created by a union of all intersecting subsets. Specifically these are Person objects, each with many attributes. I need to create a list of 'master' sets based on a handful of unique identifiers such as SSN, DLN, etc. For instance, if Person A and Person...