Monday, June 27, 2011

life is good

Writing a fair amount of python these days.
Today was the two noobs pair programming. I think we were half as productive as expected. Maybe less. I didn't get to anything I was supposed to look at, but I read through it for percolating this evening.
Lots of programming does well when it steeps in my head. Sort of. I don't know.
I do know if you take away Gmail and chat programs I do a fuckload more work, that's certain.

Holy cow. I'm not even unhappy about it; pair programming keeps you close to on task. There's never a "hey let's google lolcats" moment when you're working with somebody.

I don't know if I'd run up against that in this environment; there's a metric ton for me to learn about python and the financial services industry before I stand a chance at being bored.

Today this blew my mind in Python:
class CaseOfSpam():
    Case = []
    def spamYourKids(self, spam):

So that looked pretty innocuous to me, coming from Java.
but when you do something like this:
>>> a = CaseOfSpam()
>>> b = CaseOfSpam()
>>> a.Case
>>> b.Case
>>> a.spamYourKids('spamYourWife')
>>> b.Case
Quick, what do you think b.Case should be? Nothing, right? We didn't add anything to it. Ahh, but we did:
Oh no, they're everywhere!!
In fact, instantiating additional CaseOfSpam()s will give you prepacked Cases, with whatever you've appended.

This is actually totally OK, but I flipped out for about ten minutes, muttering "everything I know is wrong" over and over.
What I expected was an object field, not a class field.
Class Fields are global.
Object Fields behave as I'd want, where each object has its own stuff in it.
I'll add 2 functions and an object member to show this. (why two functions? I'm going to add an __init__ call to construct the object field we need)
class CaseOfSpam():
    Case = []
    def spamYourKids(self, spam ):

    def cuzEtc(self, spam ):
    def __init__(self):
        self.Box = []   

Now I can add stuff with the instance object -
>>> a = spam.CaseOfSpam()
>>> b = spam.CaseOfSpam()
>>> a.cuzEtc('Brian')
>>> b.cuzEtc('Filthy Lumberjacks')
>>> a.Box
>>> b.Box
['Filthy Lumberjacks']
>>> a.spamYourKids('I SAID EVERYBODY')
>>> b.Case

And that's how I play Crack The Whip with my readers.
Scott, are you still here? I expect you're the only one.

No comments:

Post a Comment