without an e

damn you, haskell! [01/02/2007 10:51:20]

Dammit all! I've been blubbed.

So, one of the forward chainy things I tend to do is this: I'll be sitting there thinking about a programming problem and then suddenly I'll be typing queries into google such as: "wx haskell" or "generators in lisp", or I just find myself looking at tutorials for languages like erlang or scala.

Why?

Because something irks me about python. You have no idea how common this is for me. I always wind up going back to python because I don't want to deal with the learning curve or the lack of library support.

Putting my goals on a schedule brought things into focus. There's a deadline, so I just have to tell myself no, I don't have time for that. Stick with python. And suddenly I can see exactly what that something is that's bugging me.

Most of the programs I think about involve trees or graphs of different types of data. And I was content to use objects for these things, until I picked up The Haskell School of Expression.

See to me, when I sit down to add a feature to a system... It's generally about adding behavior. With objects, you group the concepts according to the noun - the class. And sometimes that's great. But sometimes I just want to declare a tree of various objects, and then dispatch based on the type.

There are several ways to do this in python, but they're all clunky. For example, pirate (the python to parrot compiler) has one giant dispatch object that looks at a node in an abstract syntax tree, figures out what class it is, and then looks for a method on itself whose name matches the name of the class. This is okay, but it's much more flexible to have a separate object for each node type, which is what the failed pirate refactoring was all about. Then you just have a dictionary and map types to callable objects.

Well, I'm starting to ramble here. The point is that for the past year or two I've been thinking functional ideas and trying to express them in python. I've stuck with python because all my code is in python and I feel like it would be a waste of time to rewrite things in another language. But I've wasted a lot of time anyway just in terms of cramming square pegs into round holes.

So the decision I have to make is whether it's better to go through a learning curve and take on a new language, or just put my head down and do things the python way.

You mentioned Scala. My recommendation for going about learning it is this. First read the tutorial at http://scala.epfl.ch/docu/files/ScalaTutorial.pdf . Then, skim the first few chapters of http://scala.epfl.ch/docu/files/ScalaByExample.pdf - but don't let that worry you! Start really reading at chapter 4, once it gets to that point it's like a normal book/tutorial. I found the first three chapters confusing and useless. Of course, the more prior background you have with functional programming, the better. I've used Lisp and Haskell so the only new ideas for me in Scala are the particular way it presents already-familiar ideas along with advanced OO stuff. YMMV.
by Warren Henning [01/12/2007 00:35:23]
Best advice I can give: Sit down and read SICP. Yes, it's a lot of work. But by the end of chapter 3 you'll have a whole new model of computation and you'll understand functional thinking. You'll be able to move on to any functional language from there. And you'll realise what exactly OO is a specific instance of to boot. If you finish chapters 4 and 5, you're a god. :-) I'm like you in that I have so much of a Python history and codebase that moving on is difficult. Even though I now realise that Python is Blub, and even though (say) Scheme makes Python look (*gasp*) inelegant and (*gasp*) horribly inconsistent.
by wjv [01/11/2007 08:01:35]
You haven't entirely described your problem (and may not be able to) but there may yet be a better way to do whatever you're trying to do in Python. I can't know either way. One thing that may work is a custom iterator on the tree; it's easy to write a generator method that can take a function to decide whether to return the node and whether to recurse on it. That may help. Or not. Don't know. :) I'm not saying this to prevent you from using Haskell; switch by all means. It just sounds like you may be under some time pressure.
by Jeremy Bowers [01/11/2007 10:57:24]
+1 for the SICP I am actually going through it as part of my studying right now. I am writing the answers to each question in both Scheme and Python, just to see what the differences are. It's actually quite and interesting exercise.
by Joshua Volz [01/11/2007 09:48:40]
Post a comment:
name: (shows up on site)
link: (shows up on site)
mail: (for michal only)
no html allowed yet. sorry: