Sunday, July 30, 2006

aaaaa! amusing ourselves to death was right!

I just got a chill. I realized that the science and general idea of global warming/climate change, a complex and huge topic even to the scientific experts, came on to the cultural rader in a big way through a movie. Think about that. I'm sure there are many deep scientific debates, but the standard mode of the public is indifference. Until...it's a movie. The movie has not contributed anything strictly factual to the discussion; all the movie did was present it in a different medium.

The reason for my chill was that I've read Amusing Ourselves to Death, which was written in the 80s, before the rise of the WWW for example, but its material is eerily prophetic of the current time. The point of the book is that our dominant mode of discourse switched from mass-produced documents like books and newspapers to mass-produced (transmitted) motion pictures like TV and movies. Along with that shift came a shift in thinking style, literacy, and even our entire lifestyle. In the age of "show business", people form opinions differently. "A picture is worth a thousand words" is not just a quaint saying, but the motto of this age. If you wish to make your point, you don't write a pamphlet like Paine's Common Sense and distribute it around. You make a documentary in which you carefully present all footage so that it supports your cause *cough* Michael Moore *cough*. The name of the game is not reasoned debate, but the manipulation of immediate emotional reactions, by both sides.

I could go on and on about this, but I bet you got the point, since you haven't switched to a different website/channel already. It can't be good when the predictions of this book, which seems to claim that we are losing the skill of coherent thought, are coming true.

Saturday, July 29, 2006

patrick warburton in twilight zone episode

Through the magic of syndication I saw a Twilight Zone (the new series, not the B/W classic) episode not too long ago that starred Patrick Warburton as fantasy comic book hero Azoth the Avenger. An ordinary boy reads some nonsense words out loud and suddenly the real Azoth appears in his room. I was really hoping the episode would play the idea for laughs, but unfortunately that was not the case. Azoth helps him out against some bullies, teaches him to show courage, and does some other dull things. Funny how a man who dresses like a barbarian would turn out to have such good manners.

Warburton sure doesn't have any trouble finding roles. I don't mind because I'm all for skewering the American caricature of masculinity, that is, a big guy who's either dense or square. If you don't mind me blatantly showing my nerd bias, I think that putting a higher value on qualities like intelligence, creativity, or compassion would go a long way toward making my culture more broadminded and effective. Plus, Warburton's funny, ever since I saw him as Puddy on Seinfeld, and he has a great voice talent. Spoon!

In other non-news, Kung Fu Hustle is the most fun movie I've seen in a while. After seeing that, Dead Men's Chest attempts at slapstick comedy look halfhearted. And how telling is it that some of the epic martial arts duels in Hustle are just as awe-inspiring as, if not more than, the climatic fight scene between Neo and Smith at the end of Matrix Revolutions? Kung Fu Hustle is a peculiar kind of genius, but I like it.

Friday, July 28, 2006

perl's intermediate form

Quick: what does perl convert Perl into before running it? A syntax tree, or a series of bytecodes?

The answer is mu, which according to my interpretation of Pirsig's explaination in ZMM means "your question assumes an answer space which is too narrow". Actually, the intermediate form is a tree of bytecodes! Read `perldoc perlhack` and `perldoc perlguts` and see for yourself. The tree comes in handy for modeling hierarchies of lexical scope: just propagate context downward. It also comes in handy for constant folding, i.e., replacing an operation with its result at compile time: replace the operation node with a constant node, and eliminate all of its children. After the optimization steps, perl actually runs the tree by executing a given node and then dereferencing the node's pointer to the next node for execution, regardless of the location of each bytecode in the tree. The bytecodes are just indexes to a table of all the C implementations for each Perl operation.

Say what you like about Perl's syntax and semantics, but some very smart people have worked on the implementation; its regular expression engine alone is known for being without equal. A good related link is Squawks of the Parrot, the blog of Dan Sugalski, who worked on Parrot, the interpreter/VM intended for Perl 6 but also any other similar language. His archives are well categorized, and he wrote about such high-level concepts as continuations, co-routines, garbage collection, etc. from the perspective of a VM designer. Explanations at that level are pretty fascinating, especially when Dan writes so clearly. If you've ever programmed in assembly at all, you should be able to understand. (Actually, since he's often writing about the Parrot VM and not something like x86, it may be easier to comprehend!).

Thursday, July 27, 2006

the strain of a monad kick

I've been on a monak kick recently, i.e., reading some of the monad material lying around the Web in an attempt to wrap my gray matter around the concept. All about monads is good for its sheer thoroughness, and Monads as Containers makes a commendable effort to apply some analogies to it. This page about Haskell I/O takes a close, step-by-step look at why and how the IO monad works the way it does.

My own light bulb switched on (if it has!) when I realized that monads were like the formal symbol systems I learned in my abstract algebra courses (I was com sci major, math minor). Just as we can take a set of numbers, define some operations on that set which have specific properties, and then use those properties to combine operations, so we can do the same with a monad. Unlike the set of integers, which has numerical values and the (+) and (*) operations, a minimal monad has values of any specific type you choose and the "return" and "bind" operations or functions.

The return operation defines how to take a value that is not a monad and make a monad value out of it. The bind operation is trickier to understand, but basically it serves the purpose of constructing a new monad value from existing monad values. It takes for parameters a monad value and a function that creates a monad from an outside value, and returns a monad value by somehow applying the function argument to the monad argument. If the monad value was a simple list, for instance, the bind operation might just be applying the function to each element in the list and combining all the results into a list.

If I pass a monad value and a function to the bind operation, I will get back another monad value. (In abstract algebra we would say that the bind operation has closure.) This means that I can substitute a call to the bind operation anywhere that a monad value would work, such as, say, the monad value argument to a bind operation! I could say "monad bind function bind function bind function bind function". Each bind applies the function on the right to the monad on the left, so the monad on the left of each bind must be evaluated for the bind itself to be evaluated, so the sequence of the monad operations is assured.

The really interesting bit here is that the set of operators or functions for a monad can be put to use without knowing how the monad's bind or return are implemented. The Haskell folks have come up with many varieties of monads that can connect statements in ways that might make typical Haskell code sneer: IO, Continuations, exceptions, state. I haven't covered real examples of monads or transformers, and I don't plan to. I have satisfied my monad curiosity for right now.

Tuesday, July 25, 2006

a lisp evangelist who actually makes sense

In my continuing quest to learn and experiment with F#/OCaml, I decided that I should get to know tried-and-true functional programming techniques in a functional programming mindset. Otherwise, I would end up writing the same code but in different syntax, mmm'kay? I remember reading Perl gurus mocking people who programmed "C in Perl", and more recently I remember a case of a Python guru complaining about some "Java in Python". I've certainly run across OCaml examples that were clearly imperative-style, not that there's anything wrong with that.

Anyway, in my attempt to figure out how to do "functional design" I came up with this link. I highly recommend it. The writer tries to get across exactly what makes Lisp special and, as he describes, enlightening. But he does it by starting with concepts that are understood by his audience, much like ocaml-tutorial. He starts with XML, an extendable tree data format. From there he goes to Ant, in which XML is both data and code. As he says, the jungle of parantheses in Lisp is just a more concise way than XML of expressing a collection of nested elements, so it's not that bad to convert an XML document to a Lisp s-expression. Then he points out that Lisp can assign identifiers, known as symbols, to lists. Lisp functions are created just by passing a couple lists representing parameters and code to a built-in function that creates a function from the lists. Finally, lists are evaluated as functions, in which the first element is the function name and the remaining elements are arguments, unless the list is marked as being data with a simple ' mark in front. With these pieces, he can explain that a Lisp macro is just a special function that takes a data list and returns a (nested) list that will be evaluated as code. Unlike C with its preprocessor or Java using Ant, Lisp needs no templating language because it is its own!
Moreover, defining new macros is painless enough that Lisp can be extended at will...in fact, one way of attacking a problem is to define some macros in what amounts to a "domain-specific language" that is in turn defined in terms of Lisp. Much different from what I've read about caml4p. Then again, I know that I have only a superficial understanding.

There's another article at the same site that explains the benefits of lazy evaluation and continuations. But learning Haskell is not something I wish to do right now...

Monday, July 17, 2006

.Net: pathway to many abilities some would consider unnatural

You just know I've been waiting for an opportunity to use that particular dark side quote.

On Saturday afternoon, I decided to learn more about OCaml since it has long been on my list of "interesting languages I should look into sometime". The wikipedia page had a link to the F# project. It is to OCaml as Boo is to Python: a .Net implementation that mutated the language by enhancing some features, smoothing out some rough edges, and, last and least, taking on new restrictions/limitations due to the platform. Here's a nice table. I've read recreationally about some other functional languages like Lisp, Scheme, Haskell, but I must say that OCaml/F# appeals to me the most at this point. Part of the reason may be because of the down-to-earth, clearly written tutorial I skimmed through. Honestly, my comprehension level reminded me of when I learned Perl. When you start out at ground zero, the code looks like so much gibberish (Python would be an example of code that at least looks more welcoming to beginners), but with each little bit you learn the code makes more and more sense. Haskell gave me the same impression, but on the other hand I still can't read Haskell code as fluently as I can read OCaml now.

Some of the specifics I like:
  • OCaml is fundamentally functional, but it has perfectly adequate support for imperative and object-oriented styles if the need arises. F# has different ways of doing objects than OCaml, but for the sake of CLR interoperability this could be a hybrid bug/feature. OCaml is multi-paradigm to a pleasing degree. Lazy evaluation can be turned on at will.
  • An impressive list of language primitives, and unlike some other languages the primitives are REAL unboxed primitives, not object wrappers. Tuples, lists of course, records, discriminated unions, even references for those cases in which you feel you must have a true variable to store an intermediate result. The syntax doesn't make you want to choke yourself, either.
  • It has good roots and history. OCaml is not just a project that outgrew its original boundaries; it was carefully architected upon solid theoretical work.
  • Static typing without explicit variable type declarations. I like to think of it as adding program efficiency and safety without even trying. Of course, this can only go so far before the programmer needs to intervene to prevent the compiler from guessing wrong, but it's still a marvel. Something about me just gets queasy at the idea of a variable containing a variety of possible things at runtime, or morphing into something else accidentally. OCaml does offer a 'generic' type, by the way, and since its operators can handle all data types, functions with generic type parameters just work without having to write separate code paths per type. Its templating ability is par excellence.
  • It's not Ruby. I have an irrational animosity toward anything that even hints of being the latest pasture for sheeple, even if the category is "languages with functional features and dynamic (meaning the type is not set at compile time) typing". I hate the concept of a herd controlling my thoughts, with or without my consent.
Unfortunately, I'm not sure that there's a strong case for using OCaml or F# as general-purpose languages. The syntax is definitely tilted toward heavy symbolic/math applications. Some of the examples I have seen look more like algebra than any other programming language, except Haskell perhaps. A hundred lines of Caml will blow your mind. In particular, the example of the 3rd derivative of a sine is still blowing my mind. The great thing about F# is the potential to mate this great power (when wielded responsibility) with the extensive .Net libraries. But I could see myself having trouble explaining an F# program to people who haven't been initiated. OO would feel more natural to them. Thanks to some people at Microsoft Research working on F#, the .Net CLR is a pathway to many abilities some would consider to be unnatural.

Saturday, July 15, 2006

.Net: The dark side clouds everything

The past week at work I spent some time reimplementing one of our more complicated, multi-page, multi-function, high-profile portlets using sharpdevelop/web matrix. I'm getting better at the mere mechanics of the conversion, replacing former items in the page template with asp controls and moving code from former actions to page_load and onclick handlers.

The interesting wrinkle this time was a page that has a dynamic form. Not only are the choices different for each category of user, but even the categories of those choices are different. Meaning that the form has a variable number of inputs; in fact, the form is data driven. Of course, adding new inputs would require a change in code, but the order of the form's existing inputs could be rearranged just by modifying an 'ord' field in a database table.

The difficulty is not dynamically creating the inputs, but getting the values from the inputs back out again the next time the form is submitted. Before .Net, I did this by assigning the correct HTML 'name' attribute to each input as it was dynamically created inside the 'repeat' tag's template. Getting the values out on submit was just a matter of keying into the request's form inputs with the relevant name. In .Net, setting the 'name' attribute on an asp control to whatever the hell you want won't work, and it might even mess up its VIEWSTATE processing (the part that automatically keeps track of the current state of all inputs on the page). The control innocently named inside the repeater template receives a new, menacing name once it falls under the Dark influence. So how does one know that the value for data item 'farg3' is in the dynamically generated dropdownlist control with id '&4745_ct100_5'?

I wrote a handler for the ItemDataBound event for the repeater in which the uniqueID property for that generated input goes in the view state bag keyed by the data item name that input was genereated for. Then, when I need the value for a particular data item, I get the uniqueID from the view state bag, start at the repeater control, and recursively search for the input control with that uniqueID. Uuuuuugly, the elegance of recusion notwithstanding, but it seems to work in my tests so far. I bet that there was easier way to accomplish this, but I just didn't know it or find it. Sometimes I like that the .Net controls just sit on the page and handle the details of how they look, but only as long as they take direction like an agreeable actor and not like, well, Brando. I don't have a page any more to work with, but a hierarchy of controls. In this case, that worked against me, because I had trouble seeing the individual value I wanted to inside the shroud. In other words, sometimes the dark side clouds everything.

Thursday, July 13, 2006

check mysql logging config for knoppmyth

Yesterday I encountered some unusual problems in MythTV. None of my recorded programs were showing at all. I ssh'd over, found out that the / partition (not the /myth) was full, *grumble grumble*, and started picking off low-hanging fruit with apt-get remove until things started working again. I run KnoppMyth, which by default has a lot installed, for ease of use.

Today I ran a series of 'du --max-depth=1 -h ' commands, starting in /var and working my way down. In retrospect a 'find' of some variety probably would be a better choice. In any case, /var/log/mysql/mysql.log was the obvious culprit: it was dutifully recording every operation. After some quality time with Google I found out that a line in /etc/mysql/my.cnf had to be commented out: 'log = /var/log/mysql/mysql.log'. Self-evident, once you know about it. I can't even guess why that option was enabled, but thank sweet zombie jesus mythtv is the only client of this mysql instance and I am the only user. I thought I used KnoppMyth to avoid dealing with these kinds of issues? I guess I shouldn't complain, it's not as if I'm trying to run Myth on gentoo...

Tuesday, July 11, 2006

wikipedia is not an epistemology silver bullet

Disclaimer: I am not a serious student of philosophy. Moving along...

Arguments and counter-arguments about the validity of content on wikipedia get tiresome. Ultimately, the nature of truth and knowledge haven't changed through the introduction of a new medium, the Internet, a network of (networks of) computers. The real question is: how can anyone evaluate the accuracy of any propositional statement (as opposed to a self-confirming logical tautology or syllogism), regardless of the communicating medium? Let me count the ways, and shoot down each one.
  • How widely corroborated the statement is. This measure only makes sense if you also posit that, statistically speaking, more people are correct than incorrect about the statement. Yet how can you be sure about the statement "more people are correct than incorrect about this"?
  • If a competent authority accepts the statement. OK, but who defines "competent"? Other "competent authorities"? And what about the risk that the authority may simply be wrong in this individual case?
  • Objective verification of the statement through a test. At least this method would get around the need to trust what another guy is saying. However, don't assume that the result you obtain will be absolutely conclusive. Also, make sure you didn't somehow compromise the test, or bias it in some other way. Even if the result is clear, I hope you interpret it right. Forget about the cases like the existence of Greenland, which you don't have the time or interest to personally verify.
  • Apply a metaphysical, categorical rule to the statement. For instance, reject a statement because it is more complicated than it must be to explain the facts, or simply declared "out of bounds" for some other reason. Of course, now the statement isn't confirmed to be true or false.
  • Check whether the statement contradicts other statements that are known to be valid. But if there is a contradiction, how do you know whether this statement is false or the others?
In practice, we use more than one of the above tests at once, in effect validating them against each other. "Peer review" is finding the consensus of a group of authorities. An objective, experimental result should be compared to other well-known results to see if it contradicts. Sometimes, the validity of a statement is not a simple true/false but a "yes under these conditions" or "yes within this range of confidence".

The essential point is that all statements, not just the statements on wikipedia, have a truth value that must be evaluated on a case-by-case basis. Moreover, this truth value is not absolute because the measures of its truth are fallible. Traditional enclopedias use a small circle of authorities; wikipedia uses consensus. No method has a monopoly on truth.

Since people usually cannot partially act based on a statement, they must act based on the statement being true or act on it being false. That is, they must act as if the statement's truth value was absolute. To do this requires a leap of faith or trust. People can choose what statements they trust enough to act upon. Each time a person does this, he or she is choosing what reality is. (If you say you believe in a statement but act as if its opposite were true, you prove your own level of trust in the statement to be hypocritical hogwash).

Friday, July 07, 2006

.Net: The Sith and the Jedi are similar in almost every way

Most of this week I was too busy with other things at work to attack the .Net migration again. When I had a chance, I opted to go for the portlet that collects user feedback and stuffs it in a database. Still one page like the previous one, but at least it was interactive. I had my first real encounter, or should I say collision, with the page lifecycle. I added a RequiredField Validator for the textarea in web matrix, then a simple branch in Page_Load that checks IsPostBack and IsValid. Task done, right? Ohhh no. If it was a Perl CGI script, then that strategy would have worked. Not so here, because the Page_Load event comes before validation happens. That means, Page_Load cannot check IsValid! I know that the "button click" event never really "fires", because on the Web all that happens is documents zipping back and forth over HTTP, browser to server. The game is pretending that the user just clicked a button, and the server is handling that event, rather than receiving a POST. It's an interesting conceptual shift, and I imagine it will feel more natural in visual studio than in sharpdevelop/web matrix. Anyway, I just moved the code from Page_Load to the onClick handler, and that was that.

The real letdown in this round was saving the data out to the database, over the Light/Dark boundary, as our main database is not Sql Server or (heaven forbid) Access. The feedback goes in a CLOB in our database. This turned out to be a point at which my meager .Net experience matched my experience in Java: CLOBs are a pain in the cojones to work with. (The real blame in both cases is, of course, on the database driver implementations and not the platforms). Should have used a varchar, I imagine, but can't change it now. Tried it one way, got a mysterious and unhelpful error message from the driver, then tried it a different way. Joy, another unhelpful error message. Repeat ad nauseum. Finally, after admitting defeat through switching from the database-specific provider classes to the more generic OleDb family, it worked. Have I mentioned that a CLOB should be a last resort data type? We don't need to give our users the ability to spew a novella of bile at us, a short story will do.

The sun still rises in the east and sets in the west, no matter where you live, unless you're in a polar region that has time periods of darkness. Database vendors tend to focus their best driver efforts on whatever platform they see as advantagous. In any case, CLOBs alternately blow and suck. The Sith and the Jedi are similar in almost every way, including their quest for greater power.

Monday, July 03, 2006

.Net: You don't know the power of the dark side

Visual Studio isn't yet on our computers at work, so I opted to try out the sharpdevelop/web matrix combination by reimplementing one of our simpler, existing Java portlets. The portlet was display-only: get user data and show it. No pagination in this case, or viewing options of any kind. No postback whatsoever.

Wading through reference material and examples, I got a rough but working version done much faster than I had expected. The compiler type checks and editor code completion (the corresponding Sith term is intellisense) came in handy here, in the worst case at least allowing for faster typo-free typing. There were only a handful of controls on the web form, so I can't claim to have truly tested web matrix. I can see how it could get tedious trying to keep the control declarations synchronized between the aspx in web matrix and the code behind in sharpdevelop...from what I read, visual studio does that task for you.

The biggest hurdle was getting the database access working, of course. The .Net provider installed without any trouble, but when I tried a 'using', my combine failed to build. A quick web search showed the newbie that one must go to the project tab, right click on references, and add the assembly reference before 'using'. It's even in SD's FAQ. After that, I moved on to getting the connection string exactly right. And finally, figuring out which methods on which objects in which combinations in order to execute a few queries. For my first attempt to display the data, I used a custom grid control that happened to be in the example I was following. It worked in a way that felt a bit kludgy, but then I noticed that the custom control was a subclass of DataGrid. I switched to using a vanilla DataGrid for the sake of standardization. Suddenly I was able to precisely define the columns of my DataGrid within the web matrix GUI. After looking up what else my asp.net training book had to say about DataGrid, I'm feeling excited. I hope Java doesn't have a custom data table-generating tag with DataGrid's combination of flexiblity and ease, because if it does then I had been working much harder than I had to.

My initial foray into .Net development has remained positive. I am getting the impression that even as I learn, I still do not know on a palpable level the power of the dark side.

Saturday, July 01, 2006

History of Violence & Corpse Bride

Corpse Bride - Honestly, not exactly what I was expecting. Looking back, I should have assumed it would have a lot of musical numbers. And I expected it to be more twisted. On the other hand, it was much more funny and charming and genuinely touching than I assumed. All the dead beings in the movie, and even the live ones, look off-putting but exhibit a degree of personality that makes them go full circle from macabre to droll. The corpse bride is voiced so well that she may be the most likable undead character ever. I also like how the movie purposely mocks any cliches it had a danger of falling into. Although some of the songs annoyed me, I thought it was a movie that somehow managed to end up cute but not at all gag-inducing.

History of Violence - This movie has two sides, but both are manipulative. It juxtaposes the imagery and vibe of small-town paradise with brutal and rapid violence. The same dichotomy that runs through the movie runs through the main character. This wasn't hard to fit into my own frame of reference: he's a superhero with a secret identity. He's Violence Man. When there's trouble, he switches from mild-mannered diner owner to the Punisher. Then I had another realization: he's a Mel Gibson character being played by Viggo. As we know from Mel Gibson movies (e.g. Ransom, Patriot, Braveheart), don't mess with a guy's family or he'll go off like a lethal weapon. Ooops, mixed metaphors there. Anyway, I don't think people should need a movie to point out that while violence is one of those "necessary evils", the thrills it affords are part of being human. We have blood that is fun to get pumpin', and we like to see dirt rubbed into evil's face at every opportunity. People without exposure to true life-and-death violence get their quota through their entertainment. Even back when TV and movies were tamer, people got into fistfights and gun duels in westerns. On the other hand, after seeing this movie, I don't feel like playing my 24 video game for the rest of today...