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.

Saturday, April 03, 2010

Fictioneering - tool review

Before writing a new tool, it's only sensible to review what's already available.

The project I have in mind is intended to facilitate the creation of fiction for reading online.  IOW it's a web-shaped project.  The output is a series of connected html pages. 

At this stage of the projet I'm not going to experiment with radical hypertexty stuff: sequential content with at most some pop-up links is what I have in mind.

A plain text editor will obviously do the job.  The entry of the text itself is not a problem I have to solve.  Markdown or txt2tags or whatever are more than adequate to that task and well proven.  It's how that writing is organised which a plain editor doesn't address at all.  Gedit and Kate have integrated file managers, which help, but don't offer any assistence in naming and linking the component files.

Specialist web editors such as Bluefish edge closer to my needs.  I find them complex, though, with many of their features irrelevant to the task in hand.  They promise much but leave me wanting more; e.g. page annotation facilities, visual link graphs, page split and join features, and so on.

OpenOffice has an html output option.  It's such a shame the html it produces is poor from both a standards and SEO POV.  That said, text annotations are easy and useful, master documents offer a crude but useful means of organising related content, bookmarking makes links abstract, and BASIC macros allow some automation of missing functions.

Lyx has most of the advantages of OpenOffice, plus decent outlining.  Of all the extant tools, this is my favorite.




Writer's Cafe is IMO the best of the specialist fiction writing tools out there; but again i find it too complex.  I spent more time learning how to use the tools than creating text of my own.  That said, its use will probably feel natural for those used to physical scapbooks and card indexes.

All fall short of my needs.

The way I work is all too modern.  I write in snatches: an idea here, a bit of dialog there, some random musings, a scrap of verse.  Organising such disparate content, filling the gaps and polishing it all is the hard part.  None of the existing tools help much with this.  Those which are good at organising, such as FreeMind, aren't so good for the writing part; e.g. it would be absurd to have each petty page as a node on a mind map.  Full text indexing would be useful.  The ability to define placeholders; e.g. to refer to characters in a story by their role, at least until I have a decent name for them; would make a real difference.

Perhaps most important of all, the tool mustn't get in the way of the writing experience.  And nor must it take months to write.

One tall order is starting to take shape...

Saturday, March 27, 2010

Fictioneering - first sparks

[ It's been a while. For anyone interested, my wife is very much alive, thanks to the UK NHS and http://www.xigris.com/.]

I've decided to start a new programming project. Blogging about the course of its development might keep me on-track. We'll see.

So, what is this project? The title of this post is 'fictioneering', which should give you a clue. Blogs are all very well, so far as they go. Following a thread backwards can be awkward. For fiction projects, it's fatal. The story cannot flow. Nor can advantage be taken of reader comments during development. Collaboration is nigh-on impossible, too.

There are several good web sites for discovering online fiction; e.g. http://webfictionguide.com/. I haven't yet come across one that specialises in writing the stuff. True, I could use any decent editor in conjunction with git or svn or whatever; but that is still a lonely path to take. I specifically want to take advantage of the controlled interactivity the web offers during the writing process. For some of the writing projects I have in mind, the development discussion; e.g. over which of the available plot developments is most believable; could effect, or even become part of, the finished tale.

Eventually I want to offer the site facilities to other authors too, maybe for a fee.

Before I worry about the technology (which tends to distract me, geek that I am) I'm going to broad-brush the main benefits and features of the site. Watch this space.

[There: see how annoying reading backwards is? :-)]