Beautiful Code, Compelling Evidence

Categories:

Recommended

INTRODUCTION

Visualization programmers need a close-to-the-hardware, powerful 2D and 3D graphics toolkit to create applications that handle large amounts of data well. OpenGL is the most portable system for 3D graphics card programming, and thus is a common language for many visualization applications. Scott Dillard has said of the OpenGL graphics library bindings in Haskell:

The library is fantastic. I don’t think it gets enough fanfare. The only other GL API that rivals it is the C API itself. Most other languages provide a shoddy and incomplete interface to that, instead of an idiomatic interpretation of the OpenGL specification. I can’t think of a single language, not even Python, whose OpenGL bindings come close.

OpenGL is powerful, but it can also be more complicated than actually necessary. For applications involving 2D graphics, a low amount of interactivity, and a smaller amount of data, it would be simpler not to bother with the video card and the rendering pipeline. Additionally, some visualizations are meant for print form. The Gnome Foundation’s Cairo 2D graphics toolkit is perfect for these applications. As luck would have it, Haskell also has an excellent binding to Cairo.

Three other things make Haskell ideally suited to information visualization and visual analytics: a well-thought out and extensible library of generic data structures, lazy evaluation, and the separation of data transformation code from input/output inherent in a pure functional programming language. Visualizations written in Haskell tend naturally to break up into portions of reusable and visualization specific code. Thus, programs for visualization written in Haskell maintain readability and reusability as well or better than Python, but do not suffer the performance problems of an interpreted language.

For much the same reason as Simon Peyton-Jones put together Tackling the Awkward Squad, I have put together these lecture notes. I hope these will bring a programmer interested in visualization and open to the aesthetic advantages of functional programming up to speed on both topics.

FUNCTIONAL PROGRAMMING

A lazy functional programming language such as Haskell has practical effects that reduce the programmer’s concern over minutia that are irrelevant to the larger task at hand. Namely, it expresses concurrency and takes advantage of parallelism without the programmer having to bother with barriers, threads, shared data, and IPC. It is capable of loading, unloading, processing, and storing complex data structures on demand without complicated support structures, caching, and loading schemes. It enforces separation of data transformation from data presentation. It makes debugging easier for a variety of reasons, one being type-safety and compiler-time strict type checking. Finally, recursive data structures, such as graphs and trees, can be naturally expressed and traversed in functional programming languages without loss of efficiency.

 

Category:

Attribution

J.R. Heard. Beautiful Code, Compelling Evidence. https://web.archive.org/web/20160411023943/http://www.renci.org/wp-content/pub/tutorials/BeautifulCode.pdf

VP Flipbook Maker

Convert your work to digital flipbook with VP Online Flipbook Maker! You can also create a new one with the tool. Try it now!