Author Archive

The Plank

August 1st, 2008

Christer Ericson in Design patterns are from hell says:

The “Design Patterns” book is one of the worst programming books ever. Yes, really. I’m 100% dead serious when I say that I think it has set (and will continue to set) the progress of software development back by decades. Why?! Let me offer up a parable; I will call it “The Plank.”

Measuring Visual Clutter

August 22nd, 2007

Visual clutter is a huge problem in GUI design, in which the architect needs to balance the desire to have all information immediately available to the the user, with the need to enable the user to make sense of that information. The aesthetic of minimalism often falls victim as the designer acquiesces to the many competing demands of a project, resulting what I call the “Las Vegas School of Design” – a myriad of colours, shapes and sounds, rendering the user completely insensate.

Ruth Rosenholtz proposes several measures of Visual Clutter, the most practical of which is to compress the image in question using JPEG2000 – the smaller the resulting file, the less clutter.

Indexing LINQ

May 24th, 2007

Microsofts LINQ presents a wonderful sql-like syntax for querying arbitrary collections of objects. Under the hood, however, that sql-like syntax is transformed into what is called a monoid comprehension, which, scary though it may sound, is basically one or more nested loops.

This nested loopiness means that if you do anything more complex than filtering or mapping on a collection, for example a join, you will rapidly end up in a world of performance pain and your query starts performing O(n^m), where m is the number of nested loops.

Consider the following LINQ query:

The Fallacy of Premature Optimization

August 1st, 2006

In ACM Ubiquity Magazine, Randal Hyde writes:

Every programmer with a few years’ experience or education has heard the phrase “premature optimization is the root of all evil.” This famous quote by Sir Tony Hoare (popularized by Donald Knuth) has become a best practice among software engineers. Unfortunately, as with many ideas that grow to legendary status, the original meaning of this statement has been all but lost and today’s software engineers apply this saying differently from its original intent. As computer systems increased in performance from MHz, to hundreds of MHz, to GHz, the performance of computer software has taken a back seat to other concerns. Today, it is not at all uncommon for software engineers to extend this maxim to “you should never optimize your code!” Funny, you don’t hear too many computer application users making such statements. It is unfortunate that Hoare’s comments have been twisted to imply that optimization is unnecessary. The bloat and unresponsiveness found in many modern applications compels software engineers to reconsider how they apply Hoare’s comments to their projects.

life: a functional programming approach

July 21st, 2006

Tomas Rokicki describes a very novel approach to implementing the game of life in “An algorithm for Compressing Time and Space“.

The Game of Life is an example of a cellular automata, in which the state of cells in a grid are updated based on the state of the surrounding cells. In the case of the game of life, a cell can be considered alive or dead, and from one generation to the next, a live cell dies if it has less than 2 or more than 3 neighbours, and a dead cell comes to life if it has exactly 3 neighbours. From these simple rules comes an incredible variety of behaviors mimicking the complexity of life itself, and inspiring both professional and amateur scientists to study the game.

Accelerator – GPU Programming with .NET

June 21st, 2006

Accelerator provides a high-level data-parallel programming model as a library that is available for all .Net programming languages. The library translates the data-parallel operations on-the-fly to optimized GPU pixel shader code and API calls. There’s a technical report titled “Accelerator: simplified programming of graphics processing units for general-purpose uses via data parallelism”.

Essentially, Accelerator defines several array-like classes such as FloatParralelArray, IntParralelArray, and BoolParralelArray, with overloads on the various arithmetic operators on these classes. You can then build expressions using instances of these classes, which get converted into expression trees by the operator overloads. The resulting expression trees are optimized, compiled and executed on the GPU at the point that you try to extract the result of your computation.

(Pseudo) Random Number Generators

June 21st, 2006

If you are dealing with lots of computing power, at some point you will decide to try and leverage randomness in solving problems. The most well-known analytical technique leveraging randomness is called the Monte-Carlo method, and is called that for obvious reasons. Another technique that leverages randomness is Hashing (which will be covered in another post).

One of the pre-requisites for any techniques that leverage randomness is a good random number generator. A bad random number generator can give misleading results, and diagnosing the resulting problems is like wandering around in a blizzard looking for snowflakes that look too alike. You therefore want to start with a good RNG, and ideally you want as much proof of its randomness as possible before you start using it.

On computers, its is more correct to call RNGs Pseudo-Random Number Generators (PRNG), because they aren’t, in fact, random at all. They are instead deterministic, in that starting from the same state, they always give the same resulting sequence of numbers. This can be very useful, for example, when testing algorithms. The basic form of an RNG is a function: (rand,state) = f(state).

General Purpose Computation on Graphics Processing Units

June 21st, 2006

A top-of-the range graphics card, such as the NVidia 7900GTX, is a highly parallel computer, with 24 execution units capable of performing 32-bit floating point calculations on 4-element vectors at 650MHz, including being able to issue a pair of multiply-add instructions per cycle, giving a theoretical maximum of 250GFlops. The GPU has 512MB of memory attached, with a 50GB/sec theoretical maximum bandwidth. There is also a GPU that recently became available, (the 7950GX2) which is basically a pair of 7900GTX on a single card, and its possible to install a 2 or maybe even four cards in a single machine. All of the top-model GPU cards cost around $600 shortly after launch.

So… for the cost of a modest PC and 2 7950GX2 cards (a total of about $3000), you get around 1000 GFlops of computing power and 2GB of memory operating at an aggregate 200GB/sec.

Compare this to a tricked out dual-core PC (a total of about $3000), where you get around 20GFlops of computing power and 2GB of memory operating at an aggregate 10GB/sec.

Some thoughts on Windows Presentation Foundation

June 11th, 2006

WPF is Microsoft’s new API for graphics and user interface work. Its object-oriented all the way down, is architected to efficiently work across remote desktop, and is to a certain extent hardware accelerated.

To the developer, the API appears as a “scene graph” or strongly typed DOM tree called the “Visual Tree”, and changing what is displayed on screen is effected by making changes to the “Visual Tree”.

Literate Programming and Interactive Fiction

June 11th, 2006

Inform 7 is a natural language programming environment for writing interactive fiction. Whats fascinating about this approach is the conciseness and power of the language, which seems to span aspects of both logic programming and object oriented programming. A paper on the approach, appropriately subtitled “A humanising interface”, can be found here.

A relevant excerpt:

Inform does not aspire to recognise anything like the whole sweep of natural language, and in a few cases usefulness has been allowed to trump linguistic fidelity: in particular, it does not attempt to reject all un-natural language. But on the whole Inform tries to avoid eccentricity. The four self-imposed guidelines for the language were as follows:

May 2006 Linq Preview Released

May 11th, 2006

The Linq team have released a new CTP, available for download here

In 2009…

April 10th, 2006

Developers will face CPUs with

  • 20+ cores
  • 80+ hardware threads
  • 1+ TerraFlops of computing power (today < 5 GigaFlops)

So sayeth Tim Sweeney in “The Next Mainstream Programming Language: A Game Developers Perspective”

First-class relationships in an object-oriented language

April 9th, 2006

This paper outlines a kind of programming that bridges the object-oriented and relational worlds in quite a nice way.

When programming Model-View-Controller patterns, I tend to think that there is an equivalence between model and database. The model is the repository of all of the information relating to the state of the application, while the relational database is the repository of all the information relating to the state of the enterprise. Obviously, the scope is different, but many of the data design problems are similar. Just as with an enterprise relational database, you want to design for the data, in the hopes that a well structured schema will persist over time, as the demands on it change from iteration to iteration. Object-oriented databases are one way of approaching this problem, and with the advent of Linq in the C# world, the day of being able to arbitrarily query the model may soon be upon us.

Grappling with Monads

March 31st, 2006

In learning Haskell, I have got to the point where I am trying to understand Monads.

Haskell is a lazy functional language, which means that almost everything in Haskell is expressed as a function, and that those functions are evaluated on an as-needed basis only. This approach means that you never quite know when or in what order your functions are going to be evaluated. It only becomes a problem when your functions have side-effects, such as interacting with the world outside Haskell. Input and output are the cannonical examples of such side effects.

Functional Queues

March 22nd, 2006

Came across a very interesting queue implementation today in my Functional Programming class.

In an imperative language, such as C#, you would normally leverage arrays to create a resizeable circular buffer or somesuch. In functional programming languages, all datatypes are immutable, which tends to encourage one to avoid arrays and instead prefer linked lists.

How can you create a queue from linked lists of immutable nodes? You cant use a single linked list, because whilst you have easy access to the head, accessing the tail requires traversing the whole list (well, you can use a singly linked list, but its terribly inefficient).

The Command Pattern In Windows Presentation Foundation

February 22nd, 2006

Jelle Druyts of Microsoft Belgium introduces the Command Pattern, as implemented in Windows Presentation Foundation:

Text Rendering in Avalon/WinFX

January 11th, 2006

Avalon/WinFX promises a new level of quality in text rendering, but what about performance?

This powerpoint document describes the text rendering architecture of avalon.

Until the advent of DirectX 10 hardware, we should’nt expect any performance increases over and above that found in GDI+, which achives approximately 100K glyphs per second using a CPU-intensive process. With DirectX 10 hardware (not currently available), this should improve by a factor of 10, making it comparable to the GDI text rendering with the kind of hardware acceleration found on a VGA card circa 1996.

Plus ca change, plus c’est la meme chose.

Faster .NET exceptions

January 11th, 2006

If you are heavily using exceptions for flow-control in your apps, and are hitting a performance wall, consider using exceptions not derived from System.Exception as these wont generate a stack trace and are therefore faster. Not recommended for beginners.download ringtone nokia 3585i freecent i if cant ringtones 502285 nokia ringtone24 ringtone free ctufree ringtone nokia that 3585iringtones nz alcatelringtone nokia free 5100 seriesmaker alltel ringtone Map

Proebstings Law

December 15th, 2005

Todd Proebsting argues that compiler optimisation produces results far inferior to hardware optimisation

I claim the following simple experiment supports this depressing claim. Run your favorite set of benchmarks with your favorite state-of-the-art optimizing compiler. Run the benchmarks both with and without optimizations enabled. The ratio of of those numbers represents the entirety of the contribution of compiler optimizations to speeding up those benchmarks. Let’s assume that this ratio is about 4X for typical real-world applications, and let’s further assume that compiler optimization work has been going on for about 36 years. These assumptions lead to the conclusion that compiler optimization advances double computing power every 18 years. QED.

virtual methods can be subverted

November 29th, 2005

In C# we override virtual methods with the expectation that the base method can no longer be accessed. For C#, this expectation is correct, but the CLR supports accessing any method in the derivation chain, not just the most derived one.

Consider the following C++ code, which allows access to Object.GetHashCode(), regardless of whether or not that method has been overriden.


namespace ObjectHash
{
int Obj::GetHashCode(Object^ obj)
{
return obj->Object::GetHashCode();
}
}

Now, for my application (pointer joins), this is very usefull. If, on the other hand, you are using virtual methods to provide security or semantic guarantees, then you should look to delegation instead.