Monday, April 30, 2007

Python in Your Browser: Not From Who You Thought

There is a long history of people wanting to use Python in a browser. I have been one of those people. Of course, we always thought that this would come from Mozilla, who already has support for Python in their XPCOM framework (through cooperation with ActiveState), which their JavaScript components are also based on. It seemed that sandboxing python was the only piece missing to replace JavaScript with Python.

Well, here's a hit from left field we never saw coming (or did we?): Microsoft is giving us support for sandboxed Python in the browser. Silverlight is supposed to be cross-platform, so this shouldn't be an IE-only beast. When announcements were made recently about Silverlight, and included a note about a secret to be revealsed at Mix'07, I called the Python support. Now, sadly I can't prove this. All the comment that suspected Ruby and my comment suspect Python support seem to have gone missing. My theory is the guesses were too close, so they were deleted to keep the secret secret. I swear, the comments were there.


Peer Pressure Turned Me Into A Programming Language

Everyone else is doing it. I took it once and lost the results, and got a different result. But, I'm glad. I am not PERL.

You are C. You do what you're told, even if you know the result will be bad.
Which Programming Language are You?

Sunday, April 29, 2007

Internet Radio On The Rocks


I was a strong supporter of Pandora when they came out, so I'm a know proponent of internet radio. So, obviously, the recent problems facing them all is very troubling to me. I think I am even more troubled by the revealing of the RIAA's SoundExchange organization and their policy and terrible legal right to collect royalties for non-members, and force them to join the RIAA and pay fees to collect those royalties. No musician is legally allowed to opt out of this, meaning no musician has the right to make direct deals with internet radio organizations or to allow their works to be used for free. According to these laws, even royalties on public domain works would be collected, and SoundExchange would just pocket the cash. If it were just bad policies it would be one thing, but their lobbyist have made this our law.

Organizations like the RIAA are effectively allowing monopolies. They and SoundExchange might be supposedly independent, but its far from reality.
These laws effectively forbid any competing or alternative organization of recording artists and labels to form, because they would be forced to just be members of the RIAA to collect on royalties. Such organizations are just what we need. When we have them, there is a front face to fight against the RIAA's tactics.

Many artists have shown a growing disdain against the RIAA. Days are numbered.

Distributed Battle of the Giants

Google and Yahoo are facing each other on a lot of battle grounds, and some of them are less public than others. Research is key to the long term survival of both companies, and lots of information is the bread and butter of the two. Without effective technology to burrow through unheard of volumes of data in record time, neither will make it. Some of the things coming out of this struggle are interesting.

New languages are under development by the research teams at both Yahoo and Google. Sawzall is a the topic of a research paper from Rob Pike, Sean Dorward, Robert Griesemer, and Sean Quinlan. Pig, with a much less elegant name, is an working language from Yahoo Research. Off the bat, note that Sawzall is a paper, and you can download Pig's source today. If Google has an implementation of Sawzall, they are not making it public at this time.

Both are based around respective implementations of the popular concurrency algorithm, MapReduce, originally a Google creation. Yahoo supports an open source implementation of this algorithm, named Hadoop. Google has yet and likely won't release source code or open up their MapReduce system, although much information is available through their research papers.

I guess I just find it interesting that although Google is considered so often to be the geeks company, and a more open and public loving corporate entity, much of it sometimes seems to just be face without substance. Yahoo is the one supporting the open source project, instead of a closed internal solution, and their concurrency language is available freely with its source code. Sometimes, I wonder if Yahoo is more in line with the communities than Google.

Found from Geeking with Greg.

New Super

Discussions and my first PEP will hopefully lead to "fixing" super in 3.0 and could probably also be backported to 2.x branches. The two threads are linked here, and I'm going to include the reference implementation so anyone can check it out and comment on the design.


#!/usr/bin/env python
#
# newsuper.py

import sys

class SuperMetaclass(type):
def __getattr__(cls, attr):
calling_frame = sys._getframe().f_back
instance_name = calling_frame.f_code.co_varnames[0]
instance = calling_frame.f_locals[instance_name]
return getattr(instance.__super__, attr)

class Super(object):
__metaclass__ = SuperMetaclass
def __init__(self, type, obj=None):
if isinstance(obj, Super):
obj = obj.__obj__
self.__type__ = type
self.__obj__ = obj
def __get__(self, obj, cls=None):
if obj is None:
raise Exception('only supports instances')
else:
return Super(self.__type__, obj)
def __getattr__(self, attr):
mro = iter(self.__obj__.__class__.__mro__)
for cls in mro:
if cls is self.__type__:
break
for cls in mro:
if attr in cls.__dict__:
x = cls.__dict__[attr]
if hasattr(x, '__get__'):
x = x.__get__(self, cls)
return x
raise AttributeError, attr

class autosuper(type):
def __init__(cls, name, bases, clsdict):
cls.__super__ = Super(cls)

if __name__ == '__main__':
class A(object):
__metaclass__ = autosuper
def f(self):
return 'A'

class B(A):
def f(self):
return 'B' + Super.f()

class C(A):
def f(self):
return 'C' + Super.f()

class D(B, C):
def f(self, arg=None):
var = None
return 'D' + Super.f()

assert D().f() == 'DBCA'


What do you think?

SoliDOM Simpler Than I Thought

I have been playing around with the idea of a project I codenamed "SoliDOM", which would parse XML documents into a DOM structure thats actually stored in a database, which means you can have very large or very many documents operating on DOM interfaces at the same time, because the database can manage far more than you could reliably work with in memory at any one time. I did some small interface designs, but never had time to take it far.

Then I found this.

I don't think its a complete solution, and I want to think my SoliDOM would do the job much better, being designed specifically for this use. Still, I think it shows the power of languages like Python when the solution can be found so amazingly simply. All this guy has done is created classes that subclass both the xml parsing ElementTree classes and the database persistant Durus classes, and BOOM: Instant persistant XML document interfaces.

There isn't even any real code.

Do you realize the significance of being able to combine completely unrelated libraries like this, with effectively Zero glue between them?

What is even more impressive is that the benchmarks found this to actually beat the use of cElementTree outside of a database.

I'm all twittery!

I finally gave in and started using twitter. I actually think it might help keep me focused, somehow. Figure this in: I'll be posting what I do publicly, so I'll want to look good. That means I'll try to focus on really doing things more. I don't want to post to twitter that im play minesweeper, but if I am, I will. Posting one thing and doing another is lying to The Entire Freaking Planet, so I don't think I'll fabricate much. Anyone else twitter? I'd like to build a network.

My Twitter Page.

Tuesday, April 24, 2007

Agile Charlotte Meetup

Attending my first meetup tomorrow for the Agile Charlotte group from meetup.com. My old area, surrounded by cows and corn, had no chance of getting any meetups, so I'm excited to be back at the city and able to partake in some community. If anyone by chance is attending, or near enough to make it, check out the information and drop a note.

Monday, April 16, 2007

Notes on generators, yield expressions, and order of execution

I was messing around with the use of yield as an expression, the new feature in Python 2.5, and I got a little tripped in small cases of order with how you need to iterate over the generator and when you call send(), etc. I just thought I would post this example to make anyone passively reading aware of the ordering.


>>> def g():
... print 1
... print 2, (yield)
... print 3
...
>>> gen = g()
>>> gen.next()
1
2
>>> gen.send(0)
0
3
Traceback (most recent call last):
File "", line 1, in
StopIteration
>>>
I write here about programming, how to program better, things I think are neat and are related to programming. I might write other things at my personal website.

I am happily employed by the excellent Caktus Group, located in beautiful and friendly Carrboro, NC, where I work with Python, Django, and Javascript.

Blog Archive