Monday, 11 November 2013

KineticJS + CoffeeScript

After a fairly long break I'm back to tinkering with things. Today, I spent a couple of hours reacquainting myself with CoffeeScript. I really enjoy coding in this language, it's clean and straightforward and compiles right down to Javascript automatically.

As usual, I like to see things happening graphically so I combined it with KineticJS. I'd not used this before today and the fact I managed to get something going so quickly speaks volumes as to its simplicity.

Anyway, I put together something with some animation and a bunch of classes.

It's not much to look at, but like all things I do it's just to scratch the surface and get a feel for it (-:

BTW. The quality of the video is awful, not entirely sure why - must investigate next time I'm bored.



Wednesday, 17 July 2013

PyPy Performance - Wow!

For those who follow my (very) occasional posts you know I've been working on measure performance of functional languages. I've been expanding this recently to include a more imperative comparison.

What I've done is use a simple algorithm to assign activities to resources. I have a data file with 500 activities and 10 resources. I assign 50 jobs to each resource in turn, selecting the closest each time. The result should be the same for all languages, however, the order in which I process the resources matter. Some languages (notably Go) have a random sequence for maps so I need to take this into account.

This is VERY numerically intensive and makes heavy use of collections (lists and maps).

The following table is a rundown of the results:

C++   -> 1.473s
Go           -> 2.966s
PyPy (Maps)       -> 3.180s
Scala (Imper.)    -> 3.283s
Haskell           -> 3.955s
C# (Adjusted)     -> 3.997s
O'Caml            -> 4.892s
F# (Adjusted)     -> 5.442s
Scala (Func/Imm)  -> 6.836s
PyPy              -> 6.987s
C# (Mono 3.0)     -> 10.137s
C# (Mono 2.10)    -> 10.554s
F# (Mono 3.0)     -> 13.802s
F# (Mono 2.10)    -> 16.031s
Ruby 2.0          -> 16.563s
Python 3.3        -> 25.274s
Python 3.3 (Maps) -> 27.642s
Python 2.7 (Maps) -> 31.736s
Cython            -> 32.745s
Ruby 1.9          -> 37.843s
Python 2.7        -> 43.798s
Clojure           -> 2m25.605s

I'm not going to go into the specifics of each, but where possible each is using the same basic algorithm but in an idiomatic style for each language.

From the title of this post you can see where I'm going with this. Python was by far the quickest to get to a working solution, was the simplest code to understand and extremely easy to profile and optimise. Running the standard interpreter (either 2.7 or 3.3) gives reasonable results but running PyPy gives a performance in the league of Go/C++/Scala/Haskell and O'Caml.

This was very interesting!


Thursday, 23 May 2013

RISC OS - An interesting retro diversion.


My experience so far on using & coding on RISC OS is that it is a little bit like "the old days."

What I mean is that there isn't a great deal out there on the internet, Amazon has I think 2 books - apart from a bunch of old 90's second hand ones.

I've been coding in BBC Basic, which feels really retro; however, I did forget how easy it was to get things going and it's relatively powerful, for its age at least. I need to use an external editor to make it work efficiently, hardly a problem for me these days. In fact back on the BBC Master I used to use *VIEW to write my code anyway.

I've also been dabbling in some ARM assembly language. Now, I always had an idea about the utopian beauty of its RISC instruction set. I'm now discovering a few annoying limitations of it, partially due the fixed 32-bit wide op-code width.

So...it's been a fun journey, but RISC OS is most definitely stuck in the 80's/90's. It has given me some great inspiration though, which ultimately is the point of it all!

The pic below is my first BBC Basic program in ~25 years! You can see the Raspberry Pi just underneath the monitor:


An OS in 6MB!:

My RISC OS desktop running:


My venerable INPUT magazines (52 issues on programming for 8-bit machines from the early 80's), this is a page on Lisp coding:


Monday, 13 May 2013

C++?

I think the title says it all.

I spent some time last weekend looking through the C++11 spec. The seminal C++ book by Stroustrup is due to be released in about 10 days time. Incidentally the cover photo is of Mount Fisht in Russia.


After working through all the available languages on my 8-bit machines (forth/lisp/pascal and the ubiquitous basic and assembly language), C was the first language I learned on my shiny new PC-AT in around 1985. Around 1990 C++ was starting to become mainstream, I remember picking up Turbo C++ first and then Borland C++. The IDEs on these things were so quick, especially considering the performance of the machines they ran on.

Going off on a tangent here but COBOL was the next I learnt. Here is a link to a COBOL project I created: Campbell's Cuisine. It still builds on a modern machine! I wrote this when I was 14/15. I have very fond memories of this as I got an optical mouse as a gift for doing it, at a time when NOBODY had one. It came with it's own shiny metal mouse mat with a pattern on it. A bit like this:


Where was I? Oh yes, C++. So, having look up C++11, it is so far beyond that original C++ that I learned that I struggle to really make sense of it all. I'm not afraid of learning something new, but that thing has some seriously funky syntax.

Is the performance worth it? I'm a big fan of functional languages and the fact it forces you to think in a certain way. C++ gives incredible power to shoot oneself in the foot.

Maybe I should order the book and see for myself...

Monday, 21 January 2013

The Joy of Programming

I was just having one of those nostalgic moments earlier today. I'd been reading an article on C performance and managed to land on the Wikipedia article for Turbo C and then through this to Turbo Pascal.

Now, I'm a language geek and rather than becoming expert in one, I've pretty much coded in most out there except for the more esoteric ones.

I'm currently on a long functional language journey, oscillating between Clojure and Haskell, and it's reignited my idea of the actual act of coding being fun rather than the end purpose of the code itself.

Anybody who remembers Turbo Pascal will immediately remember just how much fun it was, a little like Basic on steroids. It's a bit like the sheer joy of creating music with a Tracker program (which is even more fun when large amounts of alcohol is consumed).

I wonder which language & environment would compare today? Common Lisp is certainly close, although I expect Python to win out.

It sort of ties in with my current desire to use plain old C again for some substantial project, the feeling of control and immediacy appeals. It was also the first language I learned that felt powerful but light, unlike the behemoths that are C++ and C#.

Maybe I should give myself a task to code and code it up in each and see which one I prefer?