language-agnostic

Probability riddle: 2 envelopes, switch or keep?

You are shown two envelopes and told that they both contain money, one twice as much as the other. You select one of them at random - it contains $100. Now you are given the choice to either keep the $100 or the contents of the other envelope instead. Question: is it better for you to switch, or better not to switch? This is a case of ...

What do you write in your log book?

Everywhere I've worked, programmers carry about a ruled A4 hard-back note book. To avoid attracting attention, I dutifully carry one also, and once or twice in every meeting I nod sagely and pretend to write down something interesting. Occasionally people leave theirs unattended and I sneak a look. Mostly they seem to be writing a com...

How to separate data validation from my simple domain objects (POCOs)?

This question is language agnostic but I am a C# guy so I use the term POCO to mean an object that only preforms data storage, usually using getter and setter fields. I just reworked my Domain Model to be super-duper POCO and am left with a couple of concerns regarding how to ensure that the property values make sense witin the domain. ...

Deciding on a Revenue Model for a Web Application

When building a commercial web application, what are the factors that go into the decision of a revenue model? How many users are necessary for an advertising-supported application? What demographic factors of the user base makes them more attractive to advertisers? Conversely, when deciding on a subscription price, what factors go in...

What is involved in open sourcing proprietary software?

My primary motivation for asking this question is this uservoice suggestion. Jeff declined the ticket to make the SO software open source saying that it will take more time. I've seen this before in various other pieces of software that have gone from proprietary to open source. So, my question is: why does it seem to take so long to...

Finding clusters of mass in a matrix/bitmap

This is in continuation with the question posted here: http://stackoverflow.com/questions/408358/finding-the-center-of-mass-on-a-2d-bitmap which talked about finding the center of mass in a boolean matrix, as the example was given. Suppose now we expand the matrix to this form: 0 1 2 3 4 5 6 7 8 9 1 . X X . . . . . . 2 . X X X . . X . ...

Fatal errors in live servers

I'm writing some client/server software and I'm facing the following design issue. Normally, I use a VERIFY macro very liberally - if something is wrong in an user's machine, I want the software to fail and log the error so it can be fixed. I was never a fan of ignoring any kind of errors. However, I'm now writing a server. If the serve...

What logging implementation do you prefer?

I'm about to implement a logging class in C++ and am trying to decide how to do it. I'm curious to know what kind of different logging implementations there are out there. For example, I've used logging with "levels" in Python. Where you filter out log events that are lower than a certain threshold. It also includes logging "names" wher...

Any software for pattern-matching and -rewriting source code?

I have some old software (in a language that's not dead but is dead to me ;-)) that implements a basic pattern-matching and -rewriting system for source code. I am considering resurrecting this code, translating it into a modern language, and open-sourcing the project as a refactoring power-tool. Before I go much further, I want to know ...

Filtering away nearby points from a list

I half-answered a question about finding clusters of mass in a bitmap. I say half-answered because I left it in a condition where I had all the points in the bitmap sorted by mass and left it to the reader to filter the list removing points from the same cluster. Then when thinking about that step I found that the solution didn't jump ...

Interesting uses of fluent interfaces?

I am wondering where and when fluent interfaces are a good idea, so I am looking for examples. So far I have found only 3 useful cases, e.g. Ruby's collections, like unique_words = File.read("words.txt").downcase.split.sort.uniq.length and Fest (Java) for unit testing: assertThat(yoda).isInstanceOf(Jedi.class) .isEqualTo(foundJed...

Minimizing the sum of a special function over a list

Say I have a list and I want it arranged so that the sum of a certain function operating over its consecutive elements is minimum. For example consider the list { 1, 2, 3, 4 } and sum a^b for consecutive pairs (a,b) over the entire list. ie. 1^2 + 2^3 + 3^4 = 90. By inspection, the minimum sum is achieved when the list is arranged as {...

What was your most uncomfortable programming experience

I made this a wiki because I think that some people may think it's too "thready" but I had to share and it wasn't appropriate on my blog. I've had a few, but I think the strangest was once I was on an interview (when I was consulting) and it was my first interview. I wasn't 100% familiar with the position, I knew they wanted to utilize...

Python Threads - Critical Section

What is the "critical section" of a thread (in Python)? A thread enters the critical section by calling the acquire() method, which can either be blocking or non-blocking. A thread exits the critical section, by calling the release() method. - Understanding Threading in Python, Linux Gazette Also, what is the purpose of ...

C# Data structure Algorithm

Hi Techies, I recently gave a interview to one of the TOP software company. I was completely stuck with only one question asked by interviewer to me, which was Q. I have a machine with 512 mb / 1 GB RAM and I have to sort a file (XML, or any) of 4 GB size. How will I proceed? What will be the data structure, and which sorting algorith...

Function-level constants - declare at top of function?

I have a constant value that I only plan to use once in my codebase. I am going to declare it using a const declaration. If this was a function-level variable I would declare it at the point of usage, but doing so with a constant just seems to clutter my function. ...

To NDA or not to NDA?

Assuming a small off-hours development project that may or may not have market value but which the project owner does not want to open source (or at least not at the moment). What is the proper way to formally state this intention to potential collaborators? Is a non-disclosure agreement over board? I know many people are weary of sig...

How to calculate the sum of two normal distributions

I have a value type that represents a gaussian distribution: struct Gauss { double mean; double variance; } I would like to perform an integral over a series of these values: Gauss eulerIntegrate(double dt, Gauss iv, Gauss[] values) { Gauss r = iv; foreach (Gauss v in values) { r += v*dt; } return r; }...

What's your favorite "programmer ignorance" pet peeve?

What are, in your opinion, the worst subjects of widespread ignorance amongst programmers, i.e. things that everyone who aspires to be a professional should know and take seriously, but doesn't? ...

When coding, what do you worry about?

When you're coding are there certain things that you fret and worry about, specific topics that preoccupy your mind as you type (both new code and when maintaining/bugfixing existing code)? These need not be bad things, more like voices in our heads that help us with the quality of our code, and prevent us from just hacking things out. ...