2006-01-28

Mathematica

Recently I've solved quite a number of programming challenges on the project euler site. Most of them I have solved using Wolfram's Mathematica. I am simply amazed how well-designed and easy to use it is as a programming tool. Rich mixture of functional programming tools, pattern matching and "classical" procedural programming. Excellent GUI, marvelous documentation, and it's even pretty fast in execution.

Apart from being an excellent programming language, it's also the best numeric/symbolic/visualization tool available. I have also worked with Matlab and MathCad, and they are below mathematica in almost every respect.

Ok, now for the flaws from the programming perspective. I can see only one - no (explicit) support for lazy lists. I.e. if you want to generate a list of odd numbers less than 100, you can write

Select[Table[i,{i,100}], OddQ]

(ok, this is suboptimal since odd numbers can be generated by 2*i-1 for suitable range of i). I can't know how does it work internally but my guess (based on the time and memory consumption in much larger example) is that it first generates a complete list of the first 100 numbers (the inner Table) command and then filters out even numbers. A better way would be to "streamline" the application of Select and OddQ while the list is generated. Haskell works this way, as far as I understood from little reading about it.

Tags:

2006-01-17

Programming challenges

These days I'm not doing much coding, but I miss it. I can't engage myself in some long-term project (too busy with my PhD), but I like solving puzzles in my free time, esp. programming ones. The ACM competition problems require too much time, effort and training. Today I have stumbled upon the Project Euler. Nice collection of math-related programming challenges of various difficulty. I have immediately registered!

Tags:

2006-01-16

The sad state of free software

I need to draw a diagram. Few boxes with text inside connected with arrows also having some text on top of them.

Try 1: OpenOffice draw, version 2.0. It comes pretty close to what I need except for one very annoying feature: I can't control the placement of labels over the connectors. Which wouldn't be so bad if the text were placed intelligently. But it's not. If I have an L-shaped line with some label, the text is not over the horizontal or the vertical part. Instead, it is in the middle of the virtual rectangle obtained by filling out the opposite parallel lines of L. Or, if the connector is completely horizontal, it strikes through the text (the text should be obviously placed above the line).

Try 2: Someone suggested dia. I drag a predefined shape (square) on the drawing area, double-click it in order to put the label inside, and what happens? NOTHING! Thank you, I'm not going to manually select the text tool, enter text, center it over the shape and group it. For each box. What's worse, dia crashes when run as an X11 application over the network.

Try 3: I connect to the Windows 2003 terminal server installed at my institution, launch Microsoft Visio and continue my work from there.

My needs are simple, yet two popular free tools for drawing diagrams aren't able to satisfy them "out of the box", if at all.

2006-01-12

Perl, python, security and vision

A friend has pointed me today towards a very cool project named logix. In short, it is a programming language with extensible syntax and macros. Ideal for defining domain-specific languages. I was awed when I saw what it is. It strongly reminds me of the power of LISP macros. And I didn't even look into much detail. Currently, they have python as their back-end but they are considering to switch in the long-term. A quote from their "Future Work" section: "Efficiency and security are two areas that are somewhat lacking with a Python foundation." I think that, in the end, they will make a better Python than Python :)

These people seem to have a *vision* of what they want to achieve. The perl folks also have their vision: the Perl6 language and the Parrot VM. I feel that the Python world is lacking its vision. Ok, there is "Python 3000", but unlike Perl, or Logix, it is vapourware, and AFAIK, not a line of code has been written. To build on the Python community's "batteries included" metaphore: putting a more powerful engine and more batteries in the car will make it go faster, but it won't make it *fly*.

They are also pretty conservative with the language, and this shows, for example, in their *disinterest* for the maintenace of the restricted execution module. Which brings me back to Perl: Ben Laurie wanted to implement capabilities in the Python language to provide fine-grained control over execution of the untrusted code. He says that the python community was not interested, so he implemented it for perl, thus resulting in CaPerl. Python doesn't even implement something akin to Perl's *tainting*.

Today, engineers and programmers are slowly becoming aware of ever-increasing security issues. Slowly, they are realizing that security has to be *built-in* the system, and not an add-on. It has to be *pervasive* and the best place to make it pervasive is *the runtime system itself*. I believe that today with, without such security features, it is hard to take an interpreted/VM language in serious consideration for coding Internet applications. I believe that this disinterest in security will harm Python (and other such languages!) in the long run, at least for Internet applications. One of the major advantage of executing the code in VM is easy restriction on what the code is or is not allowed to do. And python folks willfuly do not exploit this advantage. And they have much to learn, for example from Java. I don't like Java for many things, but I have to admit that it has well-engineered restricted execution model.

Another good idea that for some reason never caught on in the python world is the Stackless Python. Despite its obvious advantages, they went for the much weaker alternative in the form of generators.

Conclusion? Python reminds me of Latin. Nice, well-structured language with fast syntax and rules (also with few ugly exceptions!), unambiguous and expressive.. and too slowly changing to meet modern demands. Today, Latin is effectively a dead language, save for few niche areas (the catholic church). Will Python live to the same fate? Maybe IronPython, now backed by Microsoft, will introduce some innovation in the Python world.

Tags:

2006-01-10

NetBSD again..

It is a wonderful system, but it does not support all the latest features. For example, one can't use HW performance counters on SMP kernels even in the new NetBSD 3. The FBSD6 now also supports fine-grained locking in the kernel, another feature that NetBSD is lacking (so it works less than optimal on SMP machines). Therefore, I'll probably switch to FreeBSD for my research purposes.

Tags:

2006-01-09

Java sucks

For many reasons. Too many to list them all here. Instead, I'm pointing you to the following article: The Perils of JavaSchools. The author has so nicely put all the main points I dislike Java for.

Tags:

2006-01-08

Hacker's Delight

This is an excellent book of computer arithmetic tricks. Recently I have found that it has a dedicated web site. The site has a revision text for the possible 2nd edition, and links to other sites with tematics related to the book. There you can also find a very interesting (and non-trivial!) "computist quiz". It is quite some food for thought!

Tags:

2006-01-04

Sudoku solver

Finally, I have added the "original" sudoku solver to my collection. Again, it is a brute-force method, but very efficient.

Tags: