Next post: Exploring Consonance

Code Tidbits

I have been writing code, but that will have to wait. I just needed to post something since it's been a while.

In Java, Math.abs can return a negative number (!). I heard about it from here.

Python 2.6 is in beta. In Python, last fall Guido talked about the GIL. Now I am interested to see a "multiprocessing" module which "supports the spawning of processes using a similar API of the threading module". This is pretty cool - it will allow programs to take advantage of multiple processors, while maintaining the GIL.

My sophomore year is complete. I am currently working for Avid in Tewksbury, MA, as a Software Engineer Intern in the Media Engine Infrastructure team. It's going well so far as I dig deeper and deeper into C++.

A Python 3k hack from here. At least on the Python 3k I'm using , __signature__ isn't available yet, so this doesn't work yet. Annotations can be useful though.
#posted by Nick Coghlan
#on Python-3000 list,
#http://mail.python.org/pipermail/python-3000/2006-May/002033.html

#Apparently __signature__ hasn't been added yet. This won't work yet.

class Annotate(object):
     def __init__(*args, **kwds):
         self, args = args[0], args[1:]
         self.arg_notes = args
         self.kwd_notes = kwds
         self.return_note = None
         self.strict = False

     @classmethod
     def strict(*args, **kwds):
         cls, args = args[0], args[1:]
         self = cls(*args, **kwds)
         self.strict = True
         return self

     def returns(self, note):
         self.return_note = note
         return self

     def __call__(self, func):
         func.__signature__.update_annotations(self)
         return func

@Annotate(str, str, int).returns(int)
def f(a, b, c=0):
     # some operation producing an int. . .

@Annotate.strict(str, str, int).returns(int)
def f(a, b, c=0):
     # some operation producing an int. . .