Igor Ostrovsky on April 14th, 2009

In database terminology, a view is a named query that typically aggregates data from multiple tables. When using views, it is important to remember that querying a view will evaluate the query that defines the view. Repeated evaluation of the view – say from within a nested query – may seriously impact or even kill the performance of your application.

One solution to this performance problem is to use a “precomputed view”. Unlike an ordinary view, a precomputed view is stored in a table rather than computed on demand. When data in one of the aggregated tables changes, the update operation also updates the precomputed view table.

Read the rest of this entry »

Tags:

Igor Ostrovsky on April 1st, 2009

Notice that this post was published on April 1, 2009.

For decades, computer science students have been taught that so-called NP-hard problems do not have known efficient solutions. These problems include the infamous Travelling salesman problem, subset sum, 3SAT, and many more.

But – as is often the case – where theoretical Computer Science failed, sound software engineering practices will succeed. By using loosely-coupled OOP, agile methodologies and the model-view-controller architectural pattern, I developed a solution that someone trapped in the world of formulas and big Ohs would never dream of.

Enough with the background, and let’s take a deep dive into the intriguing design.
Read the rest of this entry »

Tags: ,

Igor Ostrovsky on March 23rd, 2009

It’s now been a month since I launched RoboZZle, so it is a good time to reflect on how things went so far. It has been a great experience, and the project took up all of my free time and then some.

For fun, I’ll discuss different aspects of RoboZZle and assign each a letter grade.

Game Addictiveness: A
Read the rest of this entry »

Tags:

Igor Ostrovsky on February 22nd, 2009

After about 3 months of evening coding, the game that I’ve been working on is now live.

RoboZZle is an online puzzle game that challenges you to program a robot to pick up all stars on a game board. The game mechanics are simple, yet allow for a wide variety of challenges that call for very different solution approaches.

Here is an example of a solved RoboZZle puzzle, with the arrow edited-in to show the path of the robot:

Read the rest of this entry »

Tags:

Igor Ostrovsky on February 2nd, 2009

Here is a little puzzle for C# developers reading my blog. What is the error in the program below?

   using System.Collections.Generic;
   class Program
   {
       public static void Main()
       {
           int[] arr = new int[10];
           IEnumerator<int> e = arr.GetEnumerator();
       }
   }

If you don’t see it, don’t worry.  I was surprised by this C# behavior as well. Just come back in a couple days to see the solution. Or try to compile the program in Visual Studio. :-)

PS.: The cause for the low cadency of posts on my blog is a side project (an online game written in Silverlight) that has been draining away my extra time over the last few months. Expect an announcement in two to three weeks, once it’s ready for launch.

Tags:

Igor Ostrovsky on November 19th, 2008

Windows Live Writer is an awesome tool that I use to write all of my blog posts. I am so used to it that I can’t imagine blogging without it, but I have also found ways to shoot myself in the foot with it. Here are two ways in which I managed to lose a nearly finished blog post:

  1. Live Writer clears its undo history when you switch between views. So, if you mess up your article in the HTML view, you won’t be able to revert the change when you notice the disaster after switching back into the Normal view.
  2. In the Preview view, Live Writer looks a lot like Internet Explorer. If you are not careful, it is not too hard to close Live Writer by accident. And, the confirmation dialog looks somewhat like IE’s closing dialog.

Thankfully, I found a way to recover Live Writer posts, and saved myself some wasted work.

Read the rest of this entry »

Tags:

Igor Ostrovsky on October 31st, 2008

As promised at the end of my recent post, I am going to explain how to implement a program that prints itself, in addition to doing other things (like playing Game of Life).

A self-printing program – also called a quine – is a program that prints out its own source code. I will describe one simple way to implement a quine that can be adapted to just about any programming language. The technique does not depend on any unusual language features, but also does not necessarily yield the shortest possible quine in a particular language.

The main idea behind this quine implementation is simple. The quine will consist of two parts: a definition of a string and the program core. The string will contain the source code of the program core. And, what will the program core do? It will print the string twice: once to print the string definition, and again to print the program core.

Read the rest of this entry »

Tags:

Igor Ostrovsky on October 30th, 2008

Conway’s Game of Life has fascinated computer scientists for decades. Even though its rules are ridiculously simple, Conway’s universe gives rise to a variety of gliders, spaceships, oscillators, glider guns, and other forms of “life”. Self-printing programs are similarly curious, and – rather surprisingly – have an important place in the theory of computation.

What happens when you combine the two? You are about to find out, but one thing is for sure: the geekiness factor should be pretty high.

I wrote a little C# program that contains a Game-of-Life grid. The program advances the game grid to the next generation and prints out a copy of itself, with the grid updated. You can take the output, compile it with a C# compiler, run it, and you’ll get the next generation of the game. You can iterate the process, or change the initial grid state manually.

Read the rest of this entry »

Tags:

Igor Ostrovsky on October 18th, 2008

Did you know that there are numbers that cannot be computed by any computer program? It is weird, but true.

And by number, I mean just an ordinary real number. As a perhaps unnecessarily simple example, the result of the division 1/7 looks like this:

        0.1428571428571428571428571428571414285714285714285714285714285714…

We can easily implement a program that prints this number. The decimal expansion of 1/7 is infinite, so the program will have to run in an infinite loop to print the “whole” number. Here is a C# implementation:

    static void Main()
    {
        Console.Write("0.");
        while (true) Console.Write("142857");
    }

Read the rest of this entry »

Tags:

Igor Ostrovsky on September 23rd, 2008

SelectMany is a fascinating operator in LINQ to Objects. For one thing, it is not as intuitive as most other LINQ operators. MSDN says that SelectMany “projects each element of a sequence to an IEnumerable(T) and flattens the resulting sequences into one sequence.” I still remember reading this description of SelectMany for the first time, and wondering why that would that be useful.

Of course, SelectMany is not only incredibly useful, but also surprisingly powerful. In fact, a variety of LINQ operators are really just constrained versions SelectMany. Select, Concat, Where, Take, Skip, TakeWhile, SkipWhile and Distinct can all be easily rewritten using a single SelectMany.

Read the rest of this entry »

Tags: