Wednesday, April 22, 2009

Tail recursion elimination in python

Neopythonic: Tail Recursion Elimination


After doing a lot of reading and playing w/ lisp, scheme and clojure, I find it interesting that Guido has no interest in tail recursion optimization.  However, I must say that python, which is my day job, has certainly stood the test of time.  It is a surprisingly powerful language and has been in almost all cases "fast enough" for what we do.  It doesn't have a few of the lisp niceties such as macros, etc, but you can do a surprising number of lisp tricks with it.


Wednesday, April 15, 2009

Debugging a lisp machine

Abstract Heresies

Ran across this earlier today and thought I'd make a quick blog posting about it.  In some ways it must have been a lot of fun to be able to work on a machine that had code in the same language all the way down to the metal.  Especially when debugging hard to find problems.   Homogeneous systems will probably be something we will never see again as more and more code moves to virtual machine like environments.  The beauty of homogeneity is outweighed by the practicality of being able to use multiple languages to solve problems.  Even lisp does not do all things equally well even though some I'm sure would disagree.  And so, we live in the practical world of differing languages all running together on heterogeneous systems.

I have had a stray and odd thought.  Programmers are very biased to their language(s) of choice.  Most never really get beyond their one core language though they may dabble in others.  With the advent of Microsofts CLR and the fact that a lot of other languages seem to be moving to the JVM, it does make me wonder if someday we will be able to cross compile code from one language to another.  I'm sure those that work on compilers for a living will be quick to tell me it's not possible.  But I do wonder if being able to translate to a different language might not make certain types of bugs obvious and/or allow quicker code generation because you can switch to a language that excels at a particular task.

Regardless, something to think about.


Monday, April 6, 2009

Mini projector

AAXA P1 Pico Projector - LCoS Based Hand-held Micro Projector - LED Pocket Projector

At the risk of putting up an advert, I gotta say this mini projector looks really cool.  I wonder if we aren't a generation or two away from getting these in our laptops and phones.  Currently it only does 640x480 which is mostly useful for presentations and showing ad hoc pictures, etc.  But, I'm sure that will continue to improve each iteration.  Now, if only someone would be kind enough to send me one to play with...


Nginx and Lighttpd

Replacing Apache with nginx for static file serving - Be the signal

Note that lighttpd is another alternative to nginx.

Nginx vs. Lighttpd for a small VPS gives some comparisons between the two.

Sunday, April 5, 2009

Throwing away the code and starting over

Twitter on Scala

Ruby on Rails wasn't up to the task on the back end processing, so the twitter dev team is switching to scala.  Scala is a language, like closure, that compiles to java bytecodes.  Concurrency and performance seem to have been a big part of their decision.

I find it fascinating that there are two truisms at work in software development projects that require performance. 

Premature Optimization

As developers, this one has been pounded into our heads over and over again.  Spending the time to optimize something prematurely is wasted effort.  The better approach by far is to get working code and see what needs to be optimized and spend the time and effort on that optimization.  Often times even someone who knows the intimate innards of the code base will guess wrongly about the bottlenecks before profiling.

Glass Ceiling

The second and less talked about problem is what happened to the twitter folks.  They had a perfectly workable system, but one which could not scale.  At some point they came to the conclusion that there was no way to further optimize the existing code base.  They needed to scrap parts of the existing code base and rewrite them in another language.

Concurrency, the monkey wrench

Concurrency is a feature that can be very, very difficult to add once you've gotten to the "working" stage if you didn't think about it at the beginning.  Depending on the problem domain, it can still be possibly to swap out the hot spots and rewrite them in a fashion that is more amenable to concurrency.  Yet, I am amazed at how often I read articles like this where the developers felt like it was more work to do that then to simply rewrite the entire thing with concurrency in mind.

I'm afraid because we are so bad at guessing where the bottlenecks in our code is going to be, that guessing where we will need concurrency may also be difficult.  Some problem domains are not so difficult or the code bases are structured in such a way that it's much easier to swap out parts.

The lesson here to me is that when writing code, it makes a lot of sense to use high level languages to prototype functionality.  But, it is critically important to structure that code in such a way that portions can be rewritten later in an environment that can take advantage of concurrency without having to scrap the entire ball of wax.

This begs the question, are blended or multi-language environments the wave of the future?


Thursday, April 2, 2009

ImageMagick is the coolest thing...

I had a very simple need this morning.  I needed to stitch together 3 image scans from a scanner into a pdf to email to my accountant.  I know there are tools to do this and some scanners do this by default.  But, I didn't have an easy way to do it.

I looked around on the web briefly and found a bunch of OSX and Windows tools that people wanted to sell me to turn multiple images into a pdf.  After not finding anything quickly, I had a brief thought.  I wonder if you can do it in imagemagick.  Sure enough:

convert *.png allinone.pdf (or jpg if your stitching jpegs).

And viola, I have a pdf in the right order.

I'm sure there are probably nice tools out there, but I was just really impressed that this worked so easily.  Here is a nice succinct page detailing some of the things you can do w/ ImageMagick.

Linux.com :: ImageMagick: A graphics wizard for the command line


Colorize those logs...

Clojure + Terracotta

Paul Stadig: Clojure + Terracotta = Yeah, Baby!

Lisp on a multi-machine distributed vm.  It would be fun to have some time to play.