language-agnostic

Is it common to write integration tests before writing unit tests?

Is it common to write integration tests before writing unit tests? Is it conventional, a good idea, or best practice? It just seems like a logical thing to do in my mind, especially when working with some 3rd-party API for the first time: You need to know how to use the 3rd-party software before you can test your own code for proper in...

Is it safe to use floats as keys of hashtables?

I need to store pairs of float,int in which the int value stores the number of occurrences of a float value inside a model I'm using for a tool I'm developing and I was wondering if it's safe to do such things.. Finite precision should be an issue when talking floats used to direct comparisons (or as content to be hashed) so I think tha...

Project Euler 298 - there must be a correct answer? (only pastebinned code)

Project Euler has a paging file problem (though it's disguised in other words). I tested my code(pastebinned so as not to spoil it for anyone) against the sample data and got the same memory contents+score as the problem. However, there is nowhere near a consistent grouping of scores. It asks for the expected difference in scores after ...

Determining edge weights given a list of walks in a graph

These questions regard a set of data with lists of tasks performed in succession and the total time required to complete them. I've been wondering whether it would be possible to determine useful things about the tasks' lengths, either as they are or with some initial guesstimation based on appropriate domain knowledge. I've come to thin...

What is the best way to handle the restriction of an API?

Our core domain so far has an abstraction called PersonName with methods for firstName, lastName, middleInitial etc. As we are expanding the domain to Spain, we figured that they only talk in terms of name, firstSurname and secondSurname i.e. middleInitial etc have no significance to them. The PersonName interface is currently being use...

What is the best way for a programmer to approach learning a new language?

I know that this is quite subjective, but is it something that I have struggled with quite a bit. I have even been hesitant to try to learn a new language because of the reason I will outline below. If this gets closed I guess I will just grin and bear it but this is something I would like to have addressed. When I go to learn a new lan...

Interesting algorithm problem

Hi all, I have an interesting algorithm problem here. The problem is in a way related to simulation of electronic designs. Say for example, I have a structure containing some gates. say a 3-input AND gate. There are 8 possible inputs i.e 000 001 ... 111 Out of these 8 inputs, if I only feed in two inputs (000) and (111), I get both ...

Code-golf: Output multiplication table to the Console

Hi, I recently pointed a student doing work experience to an article about dumping a multiplication table to the console. It used a nested for loop and multiplied the step value of each. This looked like a .NET 2.0 approach. I was wondering, with the use of Linq and extension methods,for example, how many lines of code it would take to...

Coupons and discounts in e-commerce application

Hey! I've developed an e-commerce application, and now I'm adding support for coupons and discounts. I want your opinions on this one though, since it's trickier than I first expected. Where should I keep my logic for all different kinds of coupons? Say I have a coupon code giving me the offer "Buy 3 and get the cheapest for free" alo...

Draw a point a set distance away from a base point

Hey, I'm trying to figure out an algorithm for finding a random point a set distance away from a base point. So for example: This could just be basic maths and my brain not working yet (forgive me, haven't had my coffee yet :) ), but I've been trying to work this out on paper and I'm not getting anywhere. Thanks, Niall. ...

Generic collections & dictionary classes with events

Implementing Document-View pattern I faced the problem: standard generic collections and dictionaries (List<T>, HashSet<T> for example) don't provide events for modification (OnBeforeAdd, OnAfterAdd, OnRemove, Freeze/Unfreeze methods... ) I suppose events were not implemented for optimization purposes but I have to use and listen for s...

What is an appropriate data structure or algorithm for producing an immutable concrete syntax tree in a functionally pure manner?

Given a LL(1) grammar what is an appropriate data structure or algorithm for producing an immutable concrete syntax tree in a functionally pure manner? Please feel free to write example code in whatever language you prefer. My Idea symbol : either a token or a node result : success or failure token : a lexical token from source text...

What are some easy to understand *bad* examples of using inheritance?

I'm looking for bad examples of using inheritance. I'm not very creative so this was the best I could think of: class Car : public Engine {} A car has an engine, but it is not an engine. This would probably work to explain the concept, but I believe there are more illustrative examples? ...

Why aren't whole program optimizations more prevalent now?

Main question: Why aren't general or even specialized whole program optimizers part of our daily lives? I started thinking about this after reading SuperCompilers, LLC's White paper, which discusses their method of "supercompiling" or metacompiling a program's source to (generally) achieve a faster version that does the same functionali...

What is the most accepted/used method to output a CSV string from an array?

Trying to stay completely language agnostic, and avoiding built in methods like Split() and Join(), what are the most utilized or accepted methods to build a CSV string? I run into situations like this a lot, and I'm curious as to how methods like Split() implement this? I usually do something like this: for(int i = 0; i < list.length; ...

I suffer from programming language indecision

Possible Duplicate: How to select a programming language for a project? I'm in the process of starting a new programming project. It is not a large project, it's a rather an academic one. However, all my life, I've suffered from programming-language indecision. And I truly believe this is a pathological condition. I know two t...

"if (expected == actual)" vs "if (actual == expected)"

Possible Duplicate: How to check for equals? (0 == i) or (i == 0) In C/C++ one might prefer the former because of hard to find bugs when misspelling the equality operator as assignment. But in other languages, what are the pros and cons of one vs the other? ...

Convoluted hello world program

What's the most convoluted hello world program you can think of without any bogus lines? That means every single statement has to contribute to the overall program so you can't simply bloat it with useless declarations and the such. Any language is ok, but using the esoteric nature of a language by itself does not count as convolution!...

What is A Domain Model class? How do you create one?

I have seen the ideas of domain models in UML, but I never got the chance to work with them in actual code. Now I see them in databases, particularly SQL coding, from this article And there was a quote that mentions domain model classes: I can design Domain Model classes containing plain SQL as easily as I can design classes tha...

Prim's MST algorithm in O(|V|^2)

Time complexity of Prim's MST algorithm is O(|V|^2) if you use adjacency matrix representation. I am trying to implement Prim's algorithm using adjacency matrix. I am using this as a reference. V = {1,2...,n} U = {1} T = NULL while V != U: /* Now this implementation means that I find lowest cost edge in O(n)....