language-agnostic

Three customer addresses in one table or in separate tables?

In my application I have a Customer class and an Address class. The Customer class has three instances of the Address class: customerAddress, deliveryAddress, invoiceAddress. Whats the best way to reflect this structure in a database? The straightforward way would be a customer table and a separate address table. A more denormalized ...

What's the best way to generate a unique number which has to follow certain rules?

Some background: In Germany (at least) invoice numbers have to follow certain rules: The have to be ordered They have to be continuous (may not have gaps) Since a few months they are allowed to contain characters. Some customers want to use that possibility and customers don't know that or are afraid and they insist on digit-only inv...

Algorithmic Trading API

Anyone have experience with algorithmic trading (like stocks)? Any good services to use to get quotes and to make trades? ...

Does anyone use Virtualization to create a quicker disaster recovery of a development environment?

I'm getting pretty tired of my development box dying and then I end up having to reinstall a laundry list of tools that I use in development. This time I think I'm going to set the development environment up on a Virtual Box VM and save it to an external HDD so that way I can bring the development environment back up quickly after I f...

What is the "SDK vs. 'bits on the wire'" debate about?

There appears to be some debate about "the divide is between wanting an SDK and wanting to know the underlying protocol" (see http://www.tbray.org/ongoing/When/199x/1999/08/18/BitsOnTheWire). I don't really understand what this is referring to, or why they are mutually exclusive. What is the philosophy of each approach and why do they ...

Running time of set union operation

Given two sets A and B, what is the common algorithm used to find their union, and what is it's running time? My intuition: a = set((1, 2, 3)) b = set((2, 3, 5)) union = set() for el in a: union.add(el) for el in b: union.add(el) Add checks for a collision, which is O(1), and then adds the element, which is (??). This is do...

Working out the previous and next index in an array

I've got a 1-based array of four items which I need to traverse. For a given index in the array, I need to work out the index of the next item, and the index of the previous item. This sounds simple but the array needs to wrap around. So when you are at the beginning of the array, the previous item is considered to be the last item. Like...

Is "IF" expensive?

I can't, for the life of me, remember what exactly did our teacher said that day and I'm hoping you would probably know. The module is "Data Structures and Algorithms" and he told us something along the lines of: The if statement is the most expensive [something]. [something] registers [something]. Yes, I do have a horrible me...

What's a good way to rewrite this non-tail-recursive function?

For some reason, I am having trouble thinking of a good way to rewrite this function so it uses constant stack space. Most online discussions of tree recursion cheat by using the Fibonacci function and exploiting the properties of that particular problem. Does anyone have any ideas for this "real-world" (well, more real-world than the Fi...

When is overengineering desirable?

I just got my copy of Code Complete by Steve McConnell, and there's one area I'm a bit confused about. On page 51, he says: Robustness is the ability of a system to continue to run after it detects an error. Often an architecture specifies a more robust system than that specified by the requirements. One reason is that a system co...

What ever happened to Aspect Oriented Programming?

I remember that in the late 1990s and early 2000s Aspect Oriented Programming (AOP) was supposed to be the "Next Big Thing". Nowadays I see some AOP still around, but it seems to have faded into the background. ...

Is a double really unsuitable for money?

I always tell in c# a variable of type double is not suitable for money. All weird things could happen. But I can't seem to create an example to demonstrate some of these issues. Can anyone provide such an example? (edit; this post was originally tagged C#; some replies refer to specific details of decimal, which therefore means System....

Functional alternative?

Hi all, As I continue my quest of learning functional programming, I've come to wonder if there may be alternatives to my default "procedural" way of thinking. To be more specific, I'm looking at a function I wrote. Here is what it does: Swap two elements of an unordered list of numbers, such that one of the elements is now in the r...

Registering derived classes with reflection, good or evil?

As we all know, when we derive a class and use polymorphism, someone, somewhere needs to know what class to instanciate. We can use factories, a big switch statement, if-else-if, etc. I just learnt from Bill K this is called Dependency Injection. My Question: Is it good practice to use reflection and attributes as the dependency injecti...

Solving "Who owns the Zebra" programmatically?

Edit: this puzzle is also known as "Einstein's Riddle" The Who owns the Zebra is an example of a classic set of puzzles and I bet that most people on Stack Overflow can solve it with pen and paper. But what would a programmatic solution look like? Based on the clues listed below... There are five houses. Each house has its own unique...

How many function parameters is too many?

I was just writing a function that took in several values and it got me thinking. When is the number number of arguments to a function / method too many? When (if) does it signal a flawed design? Do you design / refactor the function to take in structs, arrays, pointers, etc to decrease the amount of arguments? Do you refactor the da...

Sorting structures in order of least change

This came out being incomprehensible. I will rephrase Is there an algorithm or approach that will allow sorting an array in such a way that it minimizes the differences between successive elements? struct element { uint32 positions[8]; } These records are order-insensitive. The output file format is defined to be: byte present; ...

Ordering a dictionary to maximize common letters between adjacent words

This is intended to be a more concrete, easily expressable form of my earlier question. Take a list of words from a dictionary with common letter length. How to reorder this list tto keep as many letters as possible common between adjacent words? Example 1: AGNI, CIVA, DEVA, DEWA, KAMA, RAMA, SIVA, VAYU reorders to: AGNI, CIVA, SI...

I've heard of DRY and KISS, what other maxims do I need?

Being a self taught programmer, I base most of what I do on KISS and DRY. For me they encapsulate complex ideas well and DO help me to write better code. What else should I know? ...

Dynamic Scoping - Why?

I've learned that static scoping is the only sane way to do things, and that dynamic scoping is the tool of the devil, and results only from poor implementations of interpreters/compilers. Then I saw this snippet from a Common Lisp vs. Scheme article: Both Lexically and Dynamically Lexical scope only, per the standard. scoped spec...