Monday, December 20, 2010

Haskell, the language

I started getting serious about Haskell tonight. I have Graham Hutton's book "Programming In Haskell", and I installed hugs and started going through the exercises in the book. (I finished the Matlab book last week.) The installation on my Xubuntu system worked without problems (as usual) and I had fun with the first chapter.

Sunday, December 12, 2010

More fun with matrices

I'm more impressed with Matlab and Octave.

Octave (Matlab also) has a small language that lets one build scripts. This language has two features that give Octave (and Matlab) its advantages.

The first feature is parallel assignment. Programming languages have had serial assignment since the early days of COBOL and FORTRAN. Serial assignment moves one item in a statement, like BASIC's

LET A = B + C

It is a simple operation, easy to program and easy to understand.

Parallel assignment moves multiple items in one statement. Perl has it, and the typical example is

($a, $b) = ($b, $a);

to swap to values. The corresponding code with serial assignment is:

temp = a;
a = b;
b = temp;

Notice that one line of parallel assignment requires three lines (and an extra variable) in serial assignment.

(Actually, COBOL had a sophisticated "MOVE CORRESPONDING" operation that is rarely discussed. It moved one record to another record of a different structure, moving fields based on their names, which meant that COBOL "did the right thing", all in one line.)

The second feature is the colon operator, which generates a sequence of numbers. The expression "1:10" generates a list of numbers from 1 to 10. A variant on the syntax allows you to specify the interval size, so the expression "1:0.5:10" generates the numbers from 1 to 10 in steps of 0.5 in size.

An expression that generates a list is more powerful than one might think. After all, you can generate a sequence of numbers in a loop and every programming language has basic looping. But the expression that generates a list is a compact thing, roughly the equivalent to C's pointer arithmetic. Just as C can use pointer arithmetic for

while (*d++ = *s++);

Octave can use the colon operator for

list = 1:7:365;

for a list of numbers that might represent days in the year.

Combining parallel assignment with the colon operator provides for some powerful programming constructs. Where in other languages we would need to set up loops and control variables, in Octave we can perform a single operation:

output(10:20) = data(1:11);

This moves eleven items from 'data' into 'output'. Without parallel assignment and the list generator, we would need:

for (int i = 10; i <= 20; i++)
output(i) = data(i - 9);

Now, one might argue that the difference between these two code snippets is small, with the difference being one line of code and the latter using familiar constructs. Yet I find the Octave version much easier to read -- once I learned the 'lingo' of Octave.

And programs that are easier to read are easier to write, easier to understand, and easier to debug.

So I'm impressed with Octave.

Thursday, December 9, 2010

Fun with matrices

I did some work with Octave (the GNU variant of Matlab) last night. I performed one of the exercises in book "Engineering Problem Solving with Matlab". It was fun, working on a new tool and on a problem different from the normal work-day problems.

I found one difference in the book's description of Matlab and the performance of Octave, and that was in the zeros() function. This might be due to a difference between Octave and Matlab, or a difference in a later version of Octave (and a later version of Matlab), or possibly an error in the book. Solving this challenge and seeing the plot come out was the most fun of the exercise.

Wednesday, December 8, 2010

Calendars and dragons

I attended the CALUG (Columbia Area Linux User Group) meeting tonight. We had an open conversation about calendar tools and then watched the movie "Sintel". Both were educational. The first was less about technology and more about business models and group psychology; the latter was impressive in the tech and the artistry.

Tuesday, December 7, 2010

Microsoft WebMatrix

I attended the CMAP (Central Maryland Association of .NET Professionals) tonight. The presentation was on Microsoft's new "WebMatrix" development tool, a low-end web page/app editor/builder.

WebMatrix is pretty nice, for what it does. The description "low-end app builder" is perhaps not quite accurate, nor is "high-powered HTML editor". WebMatrix is an IDE and a set of libraries that sit on top of .NET, run under IIS, and serve dynamic web pages. You can program web pages with this funny little language (like PHP or ASP or JSP) and get results pretty quickly. I got a lot out of the presentation.

I also chatted with a bunch of folks, including my friend Ben who wants to attend ShmooCon. Apparently the tickets have already sold out, and he missed the small window.

And bonuses: I picked up a copy of a book on IronRuby (the .NET implementation from Microsoft) and a USB memory stick with Microsoft Windows Phone stuff on it.

All in all, a good evening.

Sunday, December 5, 2010

Adventures with MatLab

On a recent trip to the Book Thing, I found a copy of "Engineering Problem Solving with MatLab", a dual introduction to engineering problems and the MatLab software. For me, the engineering is a stroll down memory lane; MatLab is the new experience.

I installed Octave, the GNU equivalent of MatLab. Octave performed some basic functions identically to MatLab, which got me excited. I have yet to try the advanced features.

The book contains a floppy disk with programs and data (I assume) for its exercises. The Linux systems (//desdemona and //delilah) refuse to mount the disk. Perhaps it is no longer readable -- the book was published in 1993. I may have to get the data from another source.

My plan is to perform the exercises in the book. The idea excites me -- it's a fun, geeky way to learn a new language!

Edit: Apparently the exercises use very little in the way of data from the floppy disk. I had some fun this evening, entering data and displaying graphs. Whee!


Saturday, December 4, 2010

Sharing is nice

I did a little bit of technical work at home today: I configured a Linux system to automatically mount a share from another Linux system. It took less than 30 minutes, even with my fumbling searches for information on the web.

This change makes my home systems a little more web-like, in that the data is not stored on the local PC but on the server -- even though the server is less than four feet away.