language-agnostic

Prefer composition over inheritance?

Why prefer composition over inheritance? What trade-offs are there for each approach? When should you choose inheritance over composition? ...

Simultaneous calls from CDR

I need to come up with an analysis of simultaneus events, when having only starttime and duration of each event. Details I've a standard CDR call detail record, that contains among others: calldate (timedate of each call start duration (int, seconds of call duration) channel (a string) What I need to come up with is some sort of an...

Are there any languages that implement generics _well_?

I liked the discussion at Differences in Generics, and was wondering whether there were any languages that used this feature particularly well. I really dislike Java's List<? extends Foo> for a List of things that are Liskov-substitutable for Foo. Why can't List<Foo> cover that? And honestly, Comparable<? super Bar>? I also can't rem...

Spartan Programming

I really enjoyed Jeff's post on Spartan Programming. I agree that code like that is a joy to read. Unfortunately, I'm not so sure it would necessarily be a joy to work with. For years I have read about and adhered to the "one-expression-per-line" practice. I have fought the good fight and held my ground when many programming books count...

The best way to validate XML in a unit test?

I have a class with a ToString method that produces XML. I want to unit test it to ensure it is producing valid xml. I have a DTD to validate the XML against. Should I include the DTD as a string within the unit test to avoid a dependency on it, or is there a smarter way to do this? ...

How to check if the given string is palindrome?

Definition: A palindrome is a word, phrase, number or other sequence of units that has the property of reading the same in either direction How to check if the given string is a palindrome? This was one of the FAIQ [Frequently Asked Interview Question] a while ago but that mostly using C. Looking for solutions in any and all language...

What are the core mathematical concepts a good developer should know?

Since Graduating from a very small school in 2006 with a badly shaped & outdated program (I'm a foreigner & didn't know any better school at the time) I've come to realize that I missed a lot of basic concepts from a mathematical & software perspective that are mostly the foundations of other higher concepts. I.e. I tried to listen/watc...

What are the best RSS feeds for software project/program managers?

ENG or RUS Language only. ...

Retaining HTTP POST data when a request is interrupted by a login page

Say a user is browsing a website, and then performs some action which changes the database (let's say they add a comment). When the request to actually add the comment comes in, however, we find we need to force them to login before they can continue. Assume the login page asks for a username and password, and redirects the user back to...

What does 'foo' really mean?

I hope this qualifies as a programming question, as in any programming tutorial, you eventually come across 'foo' in the code examples. (yeah, right?) what does 'foo' really mean? If it is meant to mean nothing, when did it begin to be used so? Cheers ...

What is your preferred site for code snippets

Do you use any public websites for code-snippets? If so, can you let me know which ones you would recommend? Clarification I'm not looking for anything specific to a particular language, as suggested below - I work with a few different languages so I need something fairly general. I've just found www.snippler.com that seems like a good...

Where do you go to tickle your brain (to get programming challenges)?

Possible Duplicate: Where can you find fun/educational programming challenges? I am sure we all have some place to go to get our brain teased! Sometimes i visit Project Euler is a series of challenging mathematical/computer programming problems that will require more than just mathematical insights to solve. Alth...

Efficiently selecting a set of random elements from a linked list

Say I have a linked list of numbers of length N. N is very large and I don’t know in advance the exact value of N. How can I most efficiently write a function that will return k completely random numbers from the list? ...

How to program simple chat bot AI?

I want to build a bot that asks someone a few simple questions and branches based on the answer. I realize parsing meaning from the human responses will be challenging, but how do you setup the program to deal with the "state" of the conversation? EDIT: It will be a one-to-one conversation between a human and the bot. ...

Algorithm to generate anagrams..

What would be the best strategy to generate anagrams. An anagram is a type of word play, the result of rearranging the letters of a word or phrase to produce a new word or phrase, using all the original letters exactly once; ex. Eleven plus two is anagram of Twelve plus one A decimal point is anagram of I'm a dot in place...

How to parse relative time?

This question is the other side of the question asking, "How do I calculate relative time?". Given some human input for a relative time, how can you parse it? By default you would offset from DateTime.Now(), but could optionally offset from another DateTime. (Prefer answers in C#) Example input: "in 20 minutes" "5 hours ago" "3h 2m...

Travelling salesman problem..

Heres another famous problem we used to solve in college :) Travelling salesman problem - Problem Statement: Given a number of cities and the costs of travelling from any city to any other city, what is the least-cost round-trip route that visits each city exactly once and then returns to the starting city? How would you solve thi...

Interface vs Base class

When should I use an interface and when should I use a base class? Should it always be an interface if I don't want to actually define a base implementation of the methods? If I have a Dog and Cat class. Why would I want to implement IPet instead of PetBase? I can understand having interfaces for ISheds or IBarks (IMakesNoise?), becau...

Sample code for using mac camera in a program?

I'd like to use the camera in my Macbook in a program. I'm fairly language agnostic - C, Java, Python etc are all fine. Could anyone suggest the best place to look for documents or "Hello world" type code? ...

Continue Considered Harmful?

Should developers avoid using continue in C# or its equivalent in other languages to force the next iteration of a loop? Would arguments for or against overlap with arguments about Goto? ...