JavaScript Is Fun

In this blog post I ramble on about how writing stuff in JavaScript is fun.  Bonus conclusion: Node.js doesn’t suck, either!

But first: Context.

After some discussion, I decided that it might be nice to allow comments on Gwene.  However, if people make public comments, there should be a way to display these comments to the public at large.  “Here.  I’ve made these comments about your crappy blog.  See how wrong you were.”  So Gwene would have to have a web interface.

I though extremely briefly about using the Gmane interface.  However, it uses rather a lot of resources, and I didn’t want to use it for something as frivolous as this.

Besides, it would mean rewriting bits of it, since it would be Wrong for Gwene to show the entire contents of the RSS feeds. Doing so might mean that Gwene would (possibly) take away some traffic from the original sites.  Besides: Legal stuff.

So I decided to write a new interface.  Besides, I needed something to do while not being away on holiday for a few days.

I wrote a C program called warp that takes an inn overview file, parses the thread information, and outputs a (binary) index file suitable for parsing and squirting out onto the web.  The main point of this program is to enable the web interface to do a O(1) lookup onto the index file on (SSD) disk, read a chunk of data, and output all the thread roots for the group.

I then wrote another C program called woof that takes a list of articles (stored in the binary index file created by warp) and outputs HTML of the article contents.  The original RSS entries are shortened drastically (to 100 characters), while the comments originated on Gwene are presented in full.

Then we get to the JavaScript bits.

The fun bits.

Since there are no usability constraints here (blind people just use the NNTP interface), I wrote the web interface in a very JS-ey way.  The HTML output by the server is extremely trivial, but is transformed by client-side JavaScript into a pleasant (I hope) DOM.

All fun and games, so far, but the thought of writing the server bits in PHP just made me gnash my teeth.  There’s nothing much wrong with PHP, but it’s simply the most boring programming language ever.  There’s absolutely nothing fun about it.  Just a boring soup of mis-named functions.

So I looked into the most hyped of all hyped yesterday’s technologies: Node.js. 

I looked at an example static server, copied the code to the local disk, pointed Node at it, and specified http://localhost:8080/../../../../../../../etc/passwd as the URL, and was promptly served my password file in the browser.

It just works!

After writing some functions to parse the binary index file by warp, I then had a complete working interface to the spool.  It took me just a few hours to implement the Node bits.  The async callback style for something as simple as this just had four levels or so.

So here’s my point: JavaScript is fun.  JavaScript is fun because it’s a simple, logical, straightforward language, that has one single killer feature: How natural and easy it is to create closures.  After a while you start introducing closures all over the place, and use mappers and other functional goodies instead of iteration.

People complain about the awfulness of programming with callbacks in Node.js. I think these people are, to use a technical term, retards.  I can’t back that up with hard evidence, but I think it’s pretty self-evident.

JavaScript is fun to me in a similar way that C is fun to me.  For my day job I program in Common Lisp.  For my Emacs hobby I program in Emacs Lisp.  Both languages are so expressive that I have to think about what I’m doing.  With C, and to a lesser extent JavaScript, I can just type away without having to think about a single thing for minutes on end, because you have to type so much to get anything done.

In addition, I get a feeling of accomplishment when doing something — anything — in these languages.  Implement a bank in Common Lisp?  Eh.  Whatevs.  Parse a NOV line in C?  Whoho!  It doesn’t crash!  Yes!

Not that JavaScript is like C in that regard.  It’s very un-crashey, and more expressive than most languages people futz around in.

Writing a simple service in Node feels like programming, while doing the same in PHP feels like script drudgery.  I’m not quite sure why that is, but there’s just something intrinsically boring about PHP that sucks all joy out of using it.

So why all the hate for JavaScript?

I think that most people who natter on endlessly about how awful JavaScript is have one thing in common:  It’s the one other language than the one they’re trained to write in that they come in touch with.  (And I use the word “trained” deliberately.)

They’ve been trained to use one single crappy language, like Java or C#, and then they come into contact with The Other, and every way The Other differs from The One True Language I’ve Trained In is Evil.

So, to them, declaring local variables to avoid making them global is just moronic.  No matter that that’s how it works in plenty of other languages they aren’t familiar with.  Having several equality operators is just iNsAnE, despite all sensible languages having the same concerns (== is kinda like equal while === is very much like eq).  And closures are just so incomprehensible. Boo hoo. And on and on and on.

The biggest wart JavaScript has is that fucking + operator.  Other than that, it’s a downright cute language.  Once you understand the semantics, JavaScript is nice and regular, and nothing surprising happens when you write stuff in it.

So stop trying to use insane languages that compile to JavaScript.  It’s fine the way it is.

Aww.  JavaScript.  Cute and fun.

Futher further further legal proceedings

A year or so I got a heroic amount of paperwork from India apparently making me co-defendant in a libel case.

I think the court wanted be to remove something posted on Gmane or something, but it was kinda hard to tell.

 Anyway, this week I got some new paperwork from India.  Just 50 pages this time.

The contents are even more puzzling than the previous episode.

If I understand them correctly, I’m now party in a counter-suit.

Here’s my understanding of this brain teaser.

Originally, Sanjay sued Milap for libel because Milap said that Sanjay has stolen his land, corrupted the government and tried to have him and his family killed.

Sanjay apparently won this case, which has been going in the Indian courts since the early nineties. I was a party here because Milap had sent an email to a list about this stuff, stored on Gmane.

Now Milap is counter-suing Sanjay.

I’m not quite sure what the suit is actually about, because the papers here deal mostly with trying to shift the case from the Calcutta high court to another high court.  Because Milap is afraid that he’ll be killed if he shows his face in Calcutta.

And somehow I’m now being sued along with Sanjay.

That just seems odd.  Why am I on the suee side in both cases?

So I’m being allowed to “file your affidavit in opposition to the petition” to have the case moved to a court where Milap won’t be killed as much.  (Milap is 70 years old now, allegedly.)

My take on all this is that I won’t be travelling to India any time soon.

Oops. I’m doing London. Again.

Just beachy electronic music

Laurie Anderson is doing a tour! I had no way of getting away from work until one of the last dates on the tour: Performing at Antony’s Meltdown thing in London. Which was fine by me. Lots of other shows at that thing that I’d like to see, like Matmos. And Antony.

So I ordered the tickets. And then it dawned on me that this was taking place during like that sports event you know.

Eek time.

But you know. It’s been just luvverley. Sure, there are more people here than usual, but it not a catastrophe. It’ more of an apostrophe.

There’s a bazillion nice people kindly directing the excess touristry (“Oi! Get off the road! It’s a red light innit?”), and while the tube may be crowded sometimes, it seems like there’s a train everywhere every minute.

Boris makes the trains run on time. You know what that implies.

London is the same as always, only more so. You can’t pass through any park, no matter how minuscule, without happening upon a pavilion with some ladies singing. Pass through the South Bank Centre and watch the 20 ballet dancers that seem to happen to spend all day practising synchronised break-dancing in the basement. And walk along the beach and listen to a busker performing abstract electronic music on his two Korgs.

It’s just kinda awright, innit?

Oh! And the Tate Modern. In the Tanks they had a new exciting artist called Unilever, who was doing a piece involving like 50 people running around in a whopping big room. Or standing around and singing. Or sitting down. Or doing nothing.

They were dressed normally, so during the more dormant periods the audience would sort of wander amongst them, until they realised what was going on.

The unsettling thing about the piece was that occasionally one of the performers would leave the herd and come sit next to you. Then they would tell you a story. About something awkward. Or something they were ashamed about, I guess.

It’s very odd sitting there listening to somebody tell you something personal and not saying anything in return.

I give Unilever lots of thumbs up.

It’s apparently gonna run until October. Those people must get tired of running and confessing after a while.

Oh well.  That’s art.


So, a couple months back I got a call from somebody who presented himself as a “location manager” for a Norwegian movie producer.

I know, but they exist.

He said they were looking for an apt. with a view, so they’d been scouting and thought that my apt. looked like a possible candidate.

I said “er, uhm”, like I do, so they came over and had a look.

A few looks more and then I’ve suddenly signed a contract.

They seem like nice people and probably won’t destroy my apt.  Probably.

So they’re using my apt. for 11 days (plus) in September to film this movie.  The bits about the blind woman, at least.

I was hoping that I’d find the time to do the Gmane SSD switcharoo and more Gnus stuff this autumn after work stuff calmed down.  But I’m probably going to go off on a holiday while they’re filming, so everything is postponed once more.

I have high hopes for October, though! 

Bitch whine bitch whine.

So much drama!