language-agnostic

Optimizing Conway's 'Game of Life'

To experiment, I've (long ago) implemented Conway's Game of Life (and I'm aware of this related question!). My implementation worked by keeping 2 arrays of booleans, representing the 'last state', and the 'state being updated' (the 2 arrays being swapped at each iteration). While this is reasonably fast, I've often wondered about how to...

Is solving the halting problem easier than people think?

Although the general case is undecidable, many people still do solve problems that are equivilent well enough for day to day use. In cohen's phd thesis on computer viruses, he showed how virus scanning is equivilent to the halting problem, yet we have an entire industry based around this challenge. I also have seen microsoft's terminat...

What are some compact algorithms for generating interesting time series data?

The question sort of says it all. Whether it's for code testing purposes, or you're modeling a real-world process, or you're trying to impress a loved one, what are some algorithms that folks use to generate interesting time series data? Are there any good resources out there with a consolidated list? No constraints on values (except pl...

How can I make my applications scale well?

In general, what kinds of design decisions help an application scale well? (Note: Having just learned about Big O Notation, I'm looking to gather more principles of programming here. I've attempted to explain Big O Notation by answering my own question below, but I want the community to improve both this question and the answers.) Resp...

How to fetch a Book Title from an ISBN number?

I am planning on creating a small website for my personal book collection. To automate the process a little bit, I would like to create the following functionality: The website will ask me for the ISBN number of the book and will then automatically fetch the title and add it to my database. Although I am mainly interested in doing this...

How to evaluate an IP?

How can I determine if a string is an IP? Either IPv4 or IPv6? What is the least and most number of characters? I assume this would be a regex answer. ...

How do I write a While loop

How do you write the syntax for a While loop? C# int i = 0; while (i != 10) { Console.WriteLine(i); i++; } VB.Net Dim i As Integer = 0 While i <> 10 Console.WriteLine(i) i += 1 End While PHP <?php while(CONDITION) { //Do something here. } ?> <?php //MySQL query stuff here $result = mysql_query($sql, $link) or ...

How do you retrofit unit tests into a code base ?

Do you have any strategies for retrofitting unit tests onto a code base that currently has no unit tests ? ...

Hello world: what did your first ever computer program do ?

If you can remember that far back, what did the first computer program you ever wrote do (once you had finished debugging it)? ...

How do I avoid having the database password stored in plaintext in sourcecode?

In the web-application I'm developing I currently use a naive solution when connecting to the database: Connection c = DriverManager.getConnection("url", "username", "password"); This is pretty unsafe. If an attacker gains access to the sourcecode he also gains access to the database itself. How can my web-application connect to the d...

'method' vs. 'message' vs. 'function' vs. '???'

I recently asked a question about what I called "method calls". The answer referred to "messages". As a self-taught hobby programmer trying to phrase questions that don't make me look like an idiot, I'm realizing that the terminology that I use reveals a lot about how I learned to program. Is there a distinction between the various term...

Web Development Methodology

In your opinion, what is your single most favoured methodology for developing a web application? Broad Case: I am contracted to assemble and manage a team to begin the creation of a large web app, what methodology would suit best? Edit: Methodology being the team/work practice NOT architectural ...

ICalendar and event updates not working in Outlook

I'm generating ICalendar (.ics) files. Using the UID and SEQUENCE fields I can update existing events in Google Calendar and in Windows Calendar BUT NOT in MS Outlook 2007 - it just creates a second event How do I get them to work for Outlook ? Thanks Tom ...

To add custom/user-defined fields feature or not?

This is more of a product philosophy/software architecture question. If you are writing a business application, groupware, bug tracker, etc. you'd come across a client demanding "I want field XYZ in this entity." You know the field is too specific for the organization's needs and/or the terminology does not fit your product. Do we give...

Given an array of characters which form a sentence of words, give an efficient algorithm to reverse the order of the words (not characters) in it.

Example input and output: >>> reverse_words("this is a string") 'string a is this' It should be O(N) in time and O(1) in space (split() and pushing on/poping of stack are not allowed). The puzzle is taken from here ...

How do you determine how far to normalize a database?

When creating a database structure, what are good guidelines to follow or good ways to determine how far a database should be normalized? Should you create an un-normalized database and split it apart as the project progresses? Should you create it fully normalized and combine tables as needed for performance? ...

Free text search integrated with code coverage

Is there any tool which will allow me to perform a free text search over a system's code, but only over the code which was actually executed during a particular invocation? To give a bit of background, when learning my way around a new system, I frequently find myself wanting to discover where some particular value came from, but search...

Why do most system architects insist on first coding to an interface?

I'm not asking this question out of spite, but I really want to know, because I might be missing something. Almost every Java book I read talks about using the interface as a way to share state and behavior between objects that when first "constructed" did not seem to share a relationship. However, whenever I see architects design an app...

Finding the phone numbers in 50,000 HTML pages

How do you find the phone numbers in 50,000 HTML pages? Jeff Attwood posted 5 Questions for programmers applying for jobs: In an effort to make life simpler for phone screeners, I've put together this list of Five Essential Questions that you need to ask during an SDE screen. They won't guarantee that your candidate w...

When should a method be static?

In addition, are there any performance advantages to static methods over instance methods? I came across the following recently: http://www.cafeaulait.org/course/week4/22.html : When should a method be static? Neither reads from nor writes to instance fields Independent of the state of the object Mathematical methods tha...