« Solving Cryptograms, Part 1Tip for using ghci for interactive data analysis »

Grab Bag

18/09/08

Permalink 09:03:52 am, 489 words
Categories: Code

Grab Bag

QuickCheck has documentation! Outside the GHC library documentation! This is different from Python, where it seems like standard modules are written expressly for the library and never get documented elsewhere. Also Python documentation is much more prose and less auto-generated types straight from Haddock. (And the Haddock docs for QuickCheck are truly grim–just a list of functions and their types).

There is a conservation of momentum at work with readability of programming languages. Powerful languages are like guns that shoot small bullets very fast to get the same force as a gun that shoots a big bullet. The resulting program is very small, but it still takes about as long to understand it. Of course the advantage is in the writing, because the less code you have to write, the fewer bugs you have. I ought to remind you that C++ still has enough power to blow your head clean off.

Stackoverflow is a new programming-answers board. They even have Haskell questions. It’s where I found out that QuickCheck has documentation. And that you have to choose a type for it randomly generate, even if you don’t care. I used Int.

Static typing is mostly useful to make changing code easier. For me, it’s only marginally useful to aid reading comprehension, insofar as my tools can more easily understand the source statically. Incidentally, that means you want as smart type system as possible, because the compiler can catch more details when you change something incorrectly. Java generics are slightly better for this than inheritance, but the painful uptick in verbosity means it’s probably not worth the effort. (I made this mistake on some code I rewrote in Java from Python (Python’s GC misbehaved again)).

I’m doing my next project, an analysis of four algorithms to generate factorial typologies in OT, in Haskell. I’ve implemented the first two (the simple ones). Going by those two, my Haskell code is about twenty percent shorter than the equivalent Python. That’s without type annotations. It’s about the same as Python with types annotated. This will probably improve as I get better at Haskell.

Speaking of verbosity, static typing and conservation of momentum, here is an example of a complete context-free parser in Haskell, Scala and two flavours of Java. It’s completely unreadable, but it gets more completely unreadable as you add type annotations on down the page. Maybe it’s just Java’s syntax at fault.

On of the interesting things is that in this comparison of C# and F# is that in C# (especially with the new var keyword), type annotations occur mostly at function boundaries. Just like F#, Scala and Haskell. The problem is that if the annotations at function boundaries are required as they are in C# and Scala, then functional programming becomes unwieldy when you are doing nothing but passing around very short functions. Although I think C# and Scala both scale back on the annotation for anonymous functions.

No feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)
powered by b2evolution