Saturday, June 12, 2010

One reason I'm falling in love with Erlang

One reason I'm falling in love with Erlang is its brevity.

For example, here is an example from Joe Armstrong's book "Programming Erlang" (ISBN 978-1-934356-00-5):


-module(geometry). -export([area/1]). area({rectangle, Width, Height}) -> Width * Height; area({circle, R}) -> 3.14159 * R * R; area({square, Side}) -> Side * Side.

A Python version is not too wordy, though not as clear:


def area(type, *args) if len(args) < 1 or len(args) > 2: raise Exception("Invalid number of arguments") if type == 'rectangle': return args[0] * args[1] if len(args) != 1: raise Exception("Too many arguments") if type == 'circle': return 3.1459 * args[0] * args[0] if type == 'square': return args[0] * args[0] raise Exception("type of shape not recognised")

but the Java version is, by comparison, ridiculous. Four separate files are combined here for (a sort of) clarity:


################### ### Shape.java #### ################### package geometry; public interface Shape { public Number area(); } ##################### #### Circle.java #### ##################### package geometry; public class Circle implements Shape { final private Number radius; public Circle(Number radius) { this.radius = radius; } @Override public Number area() { return Math.PI * radius.doubleValue() * radius.doubleValue(); } } ######################## #### Rectangle.java #### ######################## package geometry; public class Rectangle implements Shape { final Number height; final Number width; final boolean isDouble; public Rectangle(Number width, Number height) { this.height = height; this.width = width; this.isDouble = (width instanceof Double || height instanceof Double || width instanceof Float || height instanceof Float); } @Override public Number area() { if (this.isDouble) { return width.doubleValue() * height.doubleValue(); } else { return width.longValue() * height.longValue(); } } } ##################### #### Square.java #### ##################### package geometry; public class Square implements Shape { final Number side; final boolean isDouble; public Square(Number side) { this.side = side; this.isDouble = (side instanceof Double || side instanceof Float); } @Override public Number area() { if (this.isDouble) { return side.doubleValue() * side.doubleValue(); } else { return side.longValue() * side.longValue(); } } }

Wednesday, June 09, 2010

OpenOffice docs really are secure

Saving a document with a password in MS Office used to be a joke.  For all I know it still is (I can't afford a copy to check).  Would OpenOffice be any better?  I decided to try.

Using a paltry 6 character password, I expected one of the pieces of cracking software to break it in short order.

Not so.  One ran for 48 hours before giving up, but give up they all did. Using a decent password of, say, 12 characters, is calculably sufficient to strain the NSA.

So saving a document with a password on OpenOffice really is worth it - just don't forget that password!

Sunday, May 09, 2010

Mac Mini + Linux x 3

My original Intel (i.e. 32 bit) Mac Mini running OS-X 10.4 is nippy enough.  As Tiger is rapidly losing support (e.g. from Mozilla) and I'm too mean to upgrade to Snow Leopard, I thought I'd give Xubuntu 10.04 a try.

Not nippy.  Agonisingly slow, in fact.  I've no idea why, and hadn't the patience to find out.  Instead I tried the full Ubuntu, which runs beautifully on my Inspiron laptop.

Disaster.  Lucid installed as easily as expected, but failed to boot.  After several minutes of futile disk spinning I pulled the power cable.  Maybe their super-clever boot speedup techniques, which are a feature of this release, are confused by the Efi Mac innards.

As Xubuntu had run, albeit slowly, I decided to have one more try.  Mandriva 2010 One was the final candidate.  Installation was smooth, and - hooray!- it booted.

Nippier than Xubuntu, but not as fast as the older single core self-build AMD box I compared it to.

In conclusion, my Mac Mini will soon be on eBay, the proceeds going toward a new NetBook.

Wednesday, May 05, 2010

Wikipedia vs Libraries

Once upon a time research was easy.  A visit to the local library to browse as many specialist titles as available, plus a quick skim of the Britannica article(s) in their reference section, was as good as any non-academic could achieve.  Missing the latest research?  Blame the library.  Used the wrong equation?  Blame the publisher.  As soon as you walked out, notes under arm, your job was done.

Not any more.

Book publishing is static, reliable, mostly safe.  Errors in print are permanent, so some effort is made to avoid them.  Web publishing, as exemplified by Wikipedia, is a now thing, as reliable as the latest editor's opinion.  Errors are corrected and made with equal rapidity.  Expert opinion (costing money) has been supplanted by a perverse form of intellectual democracy (costing merely time).  Research today is no longer the gathering of scarce facts and the quoting of authority but a frantic filtering of abundant ever-changing data and the blind hope that the quoted links stay both live and valid.

Was the old way better?  Not at all; but it was clear when an adequate effort had been made.

Tuesday, May 04, 2010

Which is worst: blank page or screen?

Once upon a time, when I was a mere lad, the worst thing a writer had to fear was a blank page.  Today that's a choice.  More often we fire up a computer, and then...

Procrastination pen-in-mouth was private.  Hours could pass with nary a doodle.  A type of meditation, p'raps, the mind a-framing (wow: I meant to write 'dreaming' - let it stand!) thoughts within thoughts, feelings within feelings.  Realising one's writing time was over (or waking up with a sore neck), one could go back to normality refreshed.

Procrastination hand-to-mouse is hectic.  Hours still pass, with barely a blog entry to show for the wild tangents of googling, the bookmark tree growing ever deeper and heavier.  Realising one's writing time is over is to be frustrated.  One goes back to normality angry or upset.

Monday, May 03, 2010

Blogging has limits

Blogging is all very well if you've a single point to express (as I have here).  Communicating multiple points of view on a topic is harder.  Distinguishing each perspective with a single voice is tricky.  We naturally (i.e. unconsciously) try to associate a single POV with a specific voice.  [Which perhaps is why Plato wrote dialogues.]

Maybe the answer is 'conversational blogging': i.e. using two or more voices at once.  As far as I know no software yet supports this directly.  Emulation is possible: e.g. use a forum with two or more open browser tabs, each logged in as a different user.

Pity most forum software is unnecessarily hard to read, loading the page with dates and times and thumbnails and signatures and other oft repeated stuff...

Time for some research.

Wednesday, April 28, 2010

PyDev Django runserver prob' solved

One little detail seems to be missing from the pydev django support: pydev runs a process on port 8000, conflicting with the django runserver.

Easily solved though.