Monday, July 28, 2008
Wednesday, July 23, 2008
Also, on a very different tack, I've become utterly convinced that at least one criticism leveled at my favourite overall programming language, Python, is utterly true and fair. After quite a while away from writing Python code, I started last night on a whim to knock up some code for a prototype of an idea I once had. It's going swimmingly; the Python Image Library, which I'd never used before, seems quick, intuitive, and with the all the features I need for this project. As for Python itself, well, my heart still belongs to whitespace delimitation. All the basics of Python coding are there in my mind like I never stopped using them, or like I've been programming in this language for 10 years.
Except when it comes to Classes. I added some classes to code that had previously just been functions, and you know what I did - or rather, forgot to do? Put in the 'self'. In front of some of the variable accesses, but more noticably, at the start of every single method argument list. This cannot be any longer blamed as a hangover from Java - I've written a ton more code, more recently in Python than in Java or any other OO language. What's more, every time I go back to Python after a break of more than about a week or so, I start making this 'mistake' again. The reason - that old Python favourite, "Explicit is better than implicit."
I'm sorry, but EXPLICIT IS NOT NECESSARILY BETTER THAN IMPLICIT. Assembler is explicit FFS. Intuitive, clever, dependable, expected, well-designed implicit behaviour is one of the chief reasons why I use a high level language. Implicitly garbage collect old objects for me? Yes, please!
I was once bitten by a Python wart I felt was bad enough to raise and spend considerable time advocating change for on comp.lang.python (never got around to doing a PEP; partly laziness, partly young and inexperienced enough to be intimidated at the thought. Still am, perhaps.)
The following doesn't work as any sane, reasonable person would expect:
# Blog code, not tested
a = A()
b = 
assert a == b
assert not (a != b)
The second assertion fails. Why? Because coding __eq__, the most obvious way to make a class have equality based comparisons, buys you nothing from the != operator. != isn't (by default) a synonym for the negation of == (unlike in, say, every other language ever); not only will Python let you make them mean different things, it actively encourages you to do so.
There were a disturbingly high number of people defending this (including one quite renowned Pythonista, think it might have been Effbot). Some had the temerity to fall back on "Explicit is better than implict: if you want != to work, you should damn well code __ne__!"
Why, for heaven's sake, should I have to, when in 99.99% of use cases (and of those 0.01% instances quoted in the argument at the time only one struck me as remotely compelling) every programmer is going to want __ne__ to be the logical negation of __eq__? Why, dear Python, are you making me write evil Java-style language power reducing boilerplate to do the thing you should be doing yourself anyway? What's more every programmer is going to unconciously expect it to work this way, and be as utterly as mystified as me when it fails to do so? Don't tell me to RTFM and don't tell me to be explicit. I'll repeat myself - if I wanted to be explicit, I'd be using C and managing my own memory thank you very much. Better yet, I'd explicitly and graphically swear - swear in frustration at this entrenched design philosophy madness that afflicts my favourite language.
I think the real problem with the explicit is better than implicit, though, is that while you can see the underlying truth its trying to get at (which is perhaps better expressed by Ruby's more equivocal less dependable but more useful Principle of Least Surprise), in its stated form its actually kind of meanginless except as a wart - no, we'll call it for what it is, a language design bug - defence.
You see, the problem is, there's no such thing of explict in programming. Its not a question of not doing things implicitly; its a question of doing the most sensible thing implicitly. For example this python code:
is implicitly equivalent to
SomeClass.some_meth(some_obj, some_arg1, some_arg2)
which in turn gives us self as a reference to some_obj, and Python's OO model merrily pretends its the same as Java's when in fact is a smarter version that just superficially looks the same.
The problem is that the explicit requirement to have self at the start of every method is something that should be shipped off to the implicit category. You should have to be explicit, yes - explicit when you want the other behaviour, of self not being an argument, because thats the more unusual, less likely case.
a != b
is implicitly equivalent to something like calling this function (may not be correct, its a while since I was heavily involved in this issue):
def equal(a, b):
if hasattr(a, "__ne__"): return a.__ne__(b)
if hasattr(b, "__ne__"): return b.__ne__(a)
if hasattr(a, "__cmp__"): return not (a.__cmp__(b) == 0)
if hasattr(b, "__cmp__"): return not (b.__cmp__(a) == 0)
return not (a is b)
There's absolutely nothing explicit about this. I wasn't arguing for making behaviour implicit; I was arguing for changing the stupid implict behaviour to something more sensible and less surprising.
The sad thing is there are plenty of smart Python programmers who will justify all kinds of idiocy in the name of their holy crusade against the implict.
If there was one change I could make to Python, it would be to get that damn line out of the Zen.
Monday, July 21, 2008
Saturday, July 19, 2008
That's certainly not to say that marijuana shouldn't perhaps be a controlled but legal substance, as it is in some countries, and as are alcohol, tobacco, and codeine (which belongs to the opiates, the same class of drugs as Heroin.)
On the subject of the law, and drug policy in general, I would love to see a more rational, less politically and emotionally charged approach to the way we seek to control substances. I would like to see public opinion and government policy shaped by the doctors, social workers, magistrates, and academics, who scientifically and disspassionately study and/or deal with the effects of drugs on a day to day basis. I don't want our society's views on this critical issue dominated by the feelings of overwrought, grief stricken people who have tragically lost family members to drug abuse. Opponents of harm minimisation talk about compromising or diluting "the message" - presmuably, that "all drugs are bad." Well, I'm sorry, that's a bad message. It has little to no credibility, because many people routinely use drugs, both legal and illegal, without suffering noticeable (short-term) consequences; these people will naturally perceieve such a pronounced, absolute anti-drug message as an extreme exaggeration if not outright fabrication (not to mention incoherent given there are plenty of legal yet harmful drugs.) There is no moral high ground to be taken against the substances themselves here. The real moral high ground is to stop people's lives being ruined or lost, and we must adapt whatever approach the evidence (not our intuitions or emotions) suggests will do this best.
Moving on to more specific details, I am in favour of the decriminalisation of the possesssion of any drug (which is the defacto state of affairs as it stands - police and prosecutors go after dealers, not users). Don't get me wrong, I'm not on a libertarian bent here, objecting in principle to the government outlawing behaviour that 'harms no one but yourself.' First, the state has a legitimate interest in preventing people from harming themselves, especially if those people have a diminshed capacity to make a rational judgement due to the psychological effects of a chemical. After all, the state has to foot your medical bills. Second, drugs don't just harm the person taking them. People under the influence of drugs often harm those around them. I just don't think it helps to put someone in gaol for using drugs - perhaps scheduling them in a psychiatric ward is a appropriate in some circumstances.
I also think we as a society need to be more open minded about the use of the more dangerous drugs under specific, appropriate circumstances. Heroin, or to use the more legitimate medical sounding term, Diamorphine, is supposedly a fantastic painkiller and a decent alternative to the closely related Morphine for some patients with severe pain management issues. I think terminal patients in particular should have access to this drug on prescription as they do in the U.K. Ecstacy, in spite of its possible side effects (which are poorly studied and understood due to its legal status), may potentially be a valuable tool to aid in psychotherapy - a purpose it was used for before it was outlawed. LSD, which I understand has fewer physical side effects than many illegal drugs and is mainly dangerous in that it can induce psychosis, has funnily enough been studied as a very succesful way to treat alcoholism.
As for how to manage the substances that are legal to purchase, I would propose a new national scheme in which everyone carries a drug license. To purchase any drug whatsoever, from cigarrettes to alcohol to cold tablets to prescription pain killers, you must present this license (it would naturally act as a replacement or alternative for existing proof of age cards.) People caught driving significantly over the limit would have their right to purchase alcohol as well as their right to drive suspended. It would be a much more effective way to monitor people's purchase of cold tablets (which can potentially be used to manufacture illegal drugs) than the current "Show your driver's license" scheme. People could even voluntarily renounce their right to buy certain substances if they were trying to overcome an addiction.
Its by no means perfect system, of course, but I'd argue its an improvement over current arrangements. Yes, there are privacy issues, but if it were well designed they could be kept manageable, and I think its a fair trade off.
Finally, to finish on a more personal note. I over-indulge in alcohol from time to time; I enjoy the increased sense of happiness, sociability, and reduced inhibitions that come with being drunk. Illegal drugs have never appealed to me, though; perhaps its because I've witnessed first hand some of the negative effects they can have, or perhaps I've just always known that if I really want to I can make much better stuff myself (the noticed side effects include overwhelming feelings of joy, confidence, and serenity, a strong sense of connection to [some form of] God, vastly increased fitness and energy levels, rapid weight loss, and greatly increased ability to sing, do yoga, and shoot accurately in basketball. Yes, there's also strongly delusional thinking, rapidly fluctuating thoughts, patches of severe difficulties with focusing, and bouts of extreme paranoia, but hey, no drug is perfect.)
See, I got the link to religion in there. You can't really have expected me to squeezed it all into this one post as well, though?
Wednesday, July 16, 2008
Regarding my last post, I am in favour of democracy, specifically modern Western representative style democracy, despite my occasional gripes and frustrations with the realities of living in a society where its hard to make sensible policy decisions that happen to be unpopular.
I spend a bit of time thinking about democracy, its merits, its flaws, ways we do it well and ways we do it better. Some practical changes I think ours could merit:
1. Private political donations should be outlawed. People or corporations wishing to donate to a party or candidate should instead give their money to an independent body (possibly a sub-branch of the AEC), along with instructions on how they wish that money to be directed. That body would pool all money for the candidate / party and then doll the funds out in increments that conceal to the greatest extent possible the timing and size of the incoming donations, so as to create a reasonable mask of anonymity in the donation process. This would in my mind strike a fair balance between our democratic right to put resources into political causes we believe in, and our collective need to stop anyone using money to corrupt our political system in their favour.
Possible issues: It would require trust in the independent body to act in good faith, but this is already nessecary with respect to the AEC (not to mention the ombudsman, ACCC, the courts, etc.) Its going to be a difficult idea to sell to the likes of the NSW Labor Party, who are highly skilled at the money-making game and are unlikely to want to give up the doubtlessly large proportion of the revenue flow that will cease once donators no longer think they can buy influence. One final issue is, if you really believe in the scheme, can you also outlaw private entities spending money on political causes in other ways, e.g. by directly taking out ads in a newspaper promoting a candidate? What about the billionaire who buys newspapers or TV stations outright to promote a political agenda? Lacking the kind of protection Americans enjoy via the First Amendment, we must be mindful to balance the need for integrity in the political process against any limitation on our right to free speech.
An extension to this idea I have read online, that could perhaps make up for the reduced levels of donations this system would incur, is that all voters should receive a fixed government-funded voucher (for say $10) to be used as a donation to the political party of their choice.
2. We should switch to a voting system like Punchscan. For a start, the use of computer technology make election results (even in Upper houses) near instantaneous, and enable the use of better preference distribution algorithms like Meek's Method that are too complex to implement under hand counting. Much more importantlt, Punchscan, unlike the hopelessly flawed kinds of electronic voting systems often used in places like America, actually greatly increases the security and integrity of the electoral process.
Possible issues: Usability - although its not that much harder than numbering boxes, you should always endeavour for voting to be as easy as possible. Also, in its current form, Punchscan is only suitable for single-choice (first past the post) elections. I can envisage ways to extend it to preferential systems like ours, but only at the expense of further complicating the voting process. Nonetheless, I think its got to be a worthwhile tradeoff. Hundreds of hours of vote counting and scutineerling labour saved, much higher accuracy, instantaneous results, the freedom to use different proportional systems, and practically unriggable elections. My only regret would be the loss of Antony Green's election night analysis.
I had more suggestions to add, but they elude me for now. Perhaps another blog post later.
Any State or Federal MPs reading, by any chance?
Tuesday, July 15, 2008
I heard Penny Wong (Australia's Climate Change Minister) on the radio today talking about the government's just released Green Paper. There were questions from the media afterward, generally predictable stuff, and then a journalist from a Science publication (Science Week magazine?) posed what I thought was a most pertinent question that seems to not be receiving as much attention as it deserves in the debate about Australia's role in the worldwide Carbon equation. To paraphrase him,
"How can you expect Australians to pay more for the Carbon we use as a nation while on the other hand we are exporting huge and rapidly growing amounts of Coal and Natural Gas to other countries that have little to no climate change controls or policies in place?"
This left her grasping for words for a few seconds, and then sadly I had to dash before hearing her response.
Its a very, very good point. We're putting far more Carbon in the atmosphere by exporting it to China than we via our own consumption, which is relatively small in the grand scheme of things.
Really, to tax carbon effectively, you need to either put a price on all that comes into our economy (imports and whats dug out of the ground), or all that leaves the economy (exports and whats pumped into the atmosphere.)
Of course, the resources boom, including energy, is the engineof our current economy and is all thats likely keeping us out of recession. So slapping a tax on coal exports isn't nessecarily a crash hot idea.
Ideally, the developing world needs to make the same kind of tough decisions about climate change that the developed world is. That's at the heart of a lot of the political excuses for hesitance on this issue.
I'm also saddened by the government's (inevitable, given the political climate) decision to offset the impact of carbon trading on petrol prices. Petrol prices going up is a very good thing - consumers, especially motorists, need to accept the fact that they've had extremely cheap energy for a long time at the expense of the environment, and that besides fossil fuels are a limited resource which given the hyper-expontially growing demand of the global economy means prices are just going to keep going up regardless of any short term measures the government takes. Anyone who's buying a car with a non-hybrid/diesel engine these days deserves to be paying through the nose for their stupidity. Its harsh, but econonomic pressures like this are what's going to result in actual change, not some pretentious gesture like turning off your light bulbs for one hour a year. If only the Federal Opposition were honest and decent enough to give the government strong political support on this issue rather than trying to score cheap populist points, it might be possible to actually sell this message to the Australian public.
Sometimes, democracy sucks.
Lets kick off by quoting (myself) from the exchange which prompted this, because I kind of liked where it was going.
Another interesting sociolingusitic point. Its probably to do with the nature
of applying such a label not just to a political belief or cause but to an
actual person - its a kind of polarising act. When I hear the words
feminism, capitalism, environmentalism, socialism, etc, I tend to think of the
great contributions these ideas have made to what I consider the worth of
our society. When I hear feminist, capitalist, etc, I think of people,
usually self-identified, who are always seem committed to their particular
cause's supposed agenda, regardless of the merits of any
e.g. Capitalism has raised the entire world's
standard of living. Capitalists think human beings can be reduced to
consumptive agents, and that totally unregulated markets are always a good
idea. Environmentalism has made us all aware of the need to conserve
precious resources like energy, water and clean air; environmentalists are
opposed to anything with the term 'nuclear' in it, up to and including
'nuclear medicine.' Socialism gave us free universal healthcare and education;
socialists are often batshit crazy.
I'd like to clarify words written in haste. Captialism has raised the developed world's standard of living. Obviously its yet to help the people of sub-Saharan africa very much.
I stand by the rest of the comments.