New Strategy

February 3rd, 2010

I can’t write. Seriously. I’m not happy with where my writing skills are at the moment. I came to this conclusion some time in December and so I committed to blogging at least once per week to improve the situation. Tonight I started writing a post about my motivations as an entrepreneur, and then I stopped writing it because it was crap. I don’t mind writing crap, I have to start somewhere, the problem is I don’t know why it’s crap. Yarg.

I need a new strategy. First, I think some books on writing are in order. I’m also going to pick a writing format, you know, like I’m only going to write sonnets. I probably won’t write sonnets, but I think giving myself some constraints is bound to help. I’m also canceling cable. Watching TV is not conducive to writing, or anything else other than watching TV for that matter.

Also, once per week is too ambitious. I’m going to knock it down a notch to twice per month and I’ll ratchet it up when my writing gets better.

Seth Godin: How to Produce Like a Linchpin

January 27th, 2010

This is a complete blogging Wednesday cop out, but whatever it takes to keep the streak alive. I found Seth’s interview here inspiring and interesting. It’s long, but worth listening to in the background or at lunch or something.

Summary: The economy is changing. Assembly line jobs are going to completely disappear. What do we need to do to be successful in this new economy? What will our new jobs look like? Turns out your job, whether you realized it or not, is to figure out how to beat the lizard brain.

Clark Kent by Day…

January 20th, 2010

By day I’m your average enterprise developer. I develop in Windows. I write VB code on .NET. I write standards-compliant Javascript. When I head home for the day I’m just glad I haven’t literally died of boredom. By night I’m a dual-wielding Python/Django hacker battling my foe  with a stream of commits to GitHub. I’m an entrepreneur bent on market domination.

I struggle with this dual identity. In the startup community quiting your day job is tantamount to seeing God on the road to Damascus. Having a day job and starting a company are like water and oil. Paul Graham says my day job is why I’m going to fail. This dude says I’m not an entrepreneur because I have a day job. For me and others like me there is little choice. I’m married. My appetite for risk and my lifestyle are not self-determined, they are negotiated. So I need a job or a great big pile of cash.

Assuming a reasonable padding of cash, working full time on my startup would be optimal. Perhaps my time would be better spent tracking down investors. Certainly I’m constantly evaluating this option. But for one reason or another, here I am and I’ll likely be here for a while yet. So to make myself feel better here are list of the advantages that come with having a day job.

No Investors

I’m a fan of startup war stories. Over the years I’ve likely read hundreds. Perhaps I’m coming to an erroneous conclusion, but based on this pile of stories I’ve been left with the impression that much of the pain in starting up stems from bad relationships with investors. There seems to be a correlation between the success of startups and their skill at managing their investors. My working theory is the possible number of extremely painful endings increases exponentially with the amount of equity owned by investors. Programs like YCombinator seem to be exceptions to this rule. I don’t have investors because I don’t need investors and I’d say on the whole this is an advantage.

Plenty of Room for Errors

I’m new at this whole startup thing. It’s nice to know if I screw up the only cash I burned through was my own. How is this an advantage? Wouldn’t it make more sense to risk another person’s money? I’ve always felt that the value of the relationships I have with friends and family, (my most likely source of angel money, maybe you are different), vastly exceeds the few thousands of dollars I might raise from them. If I don’t ask them for money I don’t have to worry about irreparable damage to a relationship. I used to play a lot of poker, and the saying is “scared money is easy money.” Never sit down to play cards if the stakes are outside your bankroll. I’m never worried about money, because as long as I keep my job, there’s always another paycheck.

There’s Never Enough Time

The number of things to do in a startup is approximately infinity. Having a job constrains me to roughly 35 hours per week spent on my startup. If I want to make measurable progress in a reasonable amount of time I have to be really good at prioritizing what I’m working on. I’ve put great effort into learning skills and methods for focusing my energy on the right tasks. I’m pretty good at it. In the past I would have just thrown more hours at the problem, and now I simply don’t have that luxury. This is why having an externally imposed constraint on my time is a good thing.

Starting up is hard enough without giving up a big chunk of your week to a job. Maybe it’s impossible, I’m not sure. But this is where I find myself. How could I call myself an entrepreneur if I didn’t make the best of it?

Next post: Tips for starting up while working full time.

Programming is Magic

January 13th, 2010
I first started programming when I was 10. Dad had CompuServe, a 28.8Kbps modem and a laptop the size of a microwave. It was summer break and during the evenings he would let me log in to a MOO. (Think World of Warcraft but entirely text based and it had a programming language).

Every night I would open up the laptop, dial in, launch some ancient, long-since defunct shell and log in to the MOO. It was exciting every time. Using the MOO was pretty straightforward. Once you logged in you were in a room. A room was just a screen of descriptive text followed by a list of commands you could type in like ‘North’ or’South’. You were also usually given a list of people in the room you could chat with.

My memory of the MOO is almost 20 years-old and fading, but I’ll never forget the first time I programmed. One night I was chatting in a room with someone when he spoke a command I’d never heard. In an instant my character was whipped up into a tornado of wind and thrown across the world into a secret room. HOLY SHIT COOL! Of course I asked him:

“How did you do that?”

“It was a spell.”

“How do I use spells?”

“You need a quota. I can get you 10k”

Of course a quota was disk space and the spell was a bit of code in the MOO’s programming language. But to me it was spell book and a magic spell. He set me up with a quota and told me how to copy paste what he had done. The whole process was arcane — and I loved every step. I think I had to use Gopher and maybe even Emacs. It was all so new and mysterious. Eventually I adjusted my new spell. Now a giant  earth elemental appeared out of nowhere, grappled them in massive hands of stone and ran straight to my secret room. Everyone else had lame tornados.

I was on the path to becoming a wizard. Actually, at this point the number of possible paths my life could take that intersected with ‘cool kid’ or ‘not a nerd’ began to asymptotically approach zero.

Things I Wish I had Time to (Re)Learn/Do

January 6th, 2010

This is the list I intend to get to…eventually.
* Lisp
* Prologue
* Haskell
* The Lambda Calculus
* Discrete Math (especially the counting stuff)
* Chinese
* Invent a new programming language
* Write a chat bot
* Write the next version of a MOO
* The entire field of AI
* Chopin’s etude in C# minor
* Spend months travelling the countries bordering the Mediterranean
* Divinity School
* Robotics
* Astronomy
* Eat meat pie and drink beer in some 200 hundred year old pub in Ireland

I own an accordion. It rots on a shelf. It’s only purpose is to
constantly remind me that I want to learn how to play it but I just
don’t have time.

Life is so interesting, I just wish I had time to do everything.

Prototypes in Javascript

December 30th, 2009

Inheritance allows programmers to reuse code. Code reuse is the holy grail of software development best practices. The most common form of inheritance relies on an idiom known as the Class. The Class is a blueprint of what an object should look like once instantiated. It is declaritive and exists at compile time. Any Class can inherit another Class and override methods declared by it’s parent or add new methods.

Example (I hate using metaphors to describe software, but it will have to do):
A house blueprint defines a building with four walls and two windows. A villa blueprint adds plans for a jacuzzi and refers the builder to the house blueprint for everything else.

Another implementation of inheritance uses Prototypes instead of Classes. Prototypes are instantiated objects. Programmers take a Prototype and add or remove methods and properties to create a new object. Prototypal inheritance is procedural and happens at runtime.

Example (You’re about to see why I hate metaphors — they produce odd outcomes):
You build a prototype airplane. For this metaphor to work you need to imagine that this prototype can make infinite copies of itself, and the copies stay in perfect sync with eachother. Remember the Mirror Image spell? Like that. If the original prototype gets a scratch, all the copies instantly have the same scratch. If one of the copies is scratched, it doesn’t affect the original. Now, take one of those copies and replace the wings. That’s prototypal inheritance.

Using Classes, you are reusing the directions for building the object. Using Prototypes, you are reusing objects.

This is what prototypal inheritance looks like in a fake programming language I call OolongScript:

var biplane = { 'sound' : 'buzzZZZzzz',
'color' : 'blue',
'numWings' : 4,
'chanceOfFailure' : 60%;}

var jet = create(biplane); //jet is a magic copy of biplane

//Let's improve our biplane copy
jet.numWings = 2;
jet.chanceOfFailure = 5%;
jet.weaponry = "Smart Bomb";

//okay, how many wings does the jet have?
print jet.numWings
>> 2
//What color is the jet?
print jet.color
>> blue

//Did we mess up the biplane?
print biplane.numWings
>> 4
print biplane.weaponry
>> Undefined

//All airplanes should be red, not blue.
biplane.color = 'red'

//What color is the jet?
print jet.color
>> red

//I want an F22 Raptor, not some lousy generic jet
var raptor = create(jet)//Create a magic copy of the jet.
raptor.stealth = True
raptor.sound = "looooooooud"

print raptor.weaponry //should be "Smart Bomb" as defined on the jet.
>> Smart Bomb

print raptor.color //should be red, just like the biplane
>> red

The raptor is built on a magic copy of the jet which uses a magical copy of the biplane prototype as a base. The jet and raptor replace the bits they don’t want and add new stuff. This doesn’t affect the biplane. But when the biplane changes color, the jet is automatically updated, as is the raptor.

Prototypal Inheritance in JavaScript (not OolongScript)

Javascript facilitates inheritance using prototypes, but where OolongScript has “create” for making magic copies, JavaScript has constructor functions and the prototype property. This is not better, it’s just harder to understand. But working from the example above, we should be able to understand what is happening.

The code for creating the biplane is the same:

var biplane = { 'sound' : 'buzzZZZzzz',
'color' : 'blue',
'numWings' : 4,
'chanceOfFailure' : 60%;}

In JavaScript we want to ‘construct’ a jet by calling a function. It might look like this in OolongScript:

var this = create(biplane); //Set this to a magic copy of the biplane
var Jet = function(){
//Let's improve our biplane prototype
this.numWings = 2;
this.chanceOfFailure = 5%;
this.weaponry = "Smart Bomb";
return this;
}
var jet = Jet();

Except in JavaScript there is no ‘create’ function. So how does JavaScript set the variable ‘this’ to a magic copy of the biplane? Like so:

// The Jet function remains the same. 'this' is a JavaScript keyword that we don't need
// to define anywhere. We tell JavaScript what 'this' should be later using the 'new'
// keyword, as you'll see below.
var Jet = function(){
//Let's improve our biplane prototype
this.numWings = 2;
this.chanceOfFailure = 5%;
this.weaponry = "Smart Bomb";
return this;
}

//Set the prototype property of the function Jet
Jet.prototype = biplane;

// Calling a function with 'new' in front of it tells JavaScript to bind
// the keyword 'this' to a magic copy of the prototype property of
// the function Jet, which we set the line above.
var jet = new Jet();

This whole setup is really hard to wrap your head around. Understanding prototypal inheritance is much easier when you can ‘create’ magic copies of objects at will. Wouldn’t it be nice if JavaScript had the ‘create’ function like we did in OolongScript? I give you my slightly simplified version of Douglas Crockford’s ‘create’ function:

var create = function(o) {
var F = function () {};
F.prototype = o;
return new F();
};

I leave it as an exercise to the reader to figure out how this works.

Hint: replace ‘F’ with ‘Jet’ from the example above and ‘o’ with ‘biplane’.

ActiveRecord Style Validation using SQLAlchemy and Elixir

April 20th, 2008

Update: Turns out I missed the boat on this one. This has already been implemented in Elixir.

I just spent the better part of today putting together the pieces in order to create ActiveRecord like validation in my Elixir models. Here is what I wanted to be able to do:


class Tag(Entity):
label = Field(String(200))
before_insert('validate_label')
before_update('validate_label')

def validate_label(self):
Some validation code here

I wanted to be able to write custom validation methods in my model and then hook them into sqlalchemy events like ‘before_update’ so that before any data goes to my app’s database it is first validated. Then at that point I can catch it and redirect the user to change the invalid data.

Earlier I had stumbled upon this code by Beachcoder. While I was excited to see that it could work, I was having a difficult time understanding the approach, largely because a lot of this stuff was essentially a black box to me. So I got under the hood and came up with my own approach. I’m not sure if it’s better or even complete, (even though it seems to work and I pass all my unit tests), but that’s why I am posting it here. Feedback is welcome!

from sqlalchemy.orm import MapperExtension
from elixir.statements import Statement
class HookExtension(MapperExtension):
"""
Given a hookname and a list of callbacks, (which are just methods associated with the instance)
this mapper extension overrides the given hook with a function that executes each of the callbacks.
"""
def __init__(self, hookname, callbacks):
MapperExtension.__init__(self)
def execute_callbacks(mapper, connection, instance):
for f in callbacks: getattr(instance,f)()
setattr(self, hookname, execute_callbacks)

def create_hook_statement(hookname):
"""
A simple class generator. Given a sqlalchemy hook name like 'before_insert' or 'before_update' creates
an Elixir statement. The statement excepts a list of 'callbacks' which are names of methods associated
with the Elixir class that will be executed based on the hook.
"""
class HookStatement(object):
def __init__(self, entity, *callbacks):
ext = HookExtension(hookname, callbacks)
entity._descriptor.add_mapper_extension(ext)
return HookStatement

before_insert = Statement(create_hook_statement('before_insert'))
before_update = Statement(create_hook_statement('before_update'))

401k Loan: The Double Taxation Myth

November 1st, 2007

Whenever personal finance gurus are presented with a question about 401k loans they usually bark back with a list of truisms that should lead you to conclude that a 401k loan is a very bad idea:

  • If you lose your job you will have to pay back the loan immediately or face severe tax penalties
  • You give up the interest you would have earned had you left that money in the 401k plan for the duration of the loan
  • The money you have in your 401k has not been taxed
  • When you pay back your loan you are paying with after-tax dollars
  • When you withdraw your money on retirement, you pay taxes again

All four statements are true and I won’t argue with any of them, and the last two statements would lead one to conclude that you are in fact faced with double-taxation. Prepare yourself for massive cognitive dissonance: 401k loans are not taxed twice!

To prepare you for the mental gymnastics ahead I have a little warm-up routine for you to follow. It’s a riddle.

Three men go to a hotel and share a room. The total cost for the room is $30, so they each give the hotel manager $10. The hotel manager later discovers that the room was actually only $25 and gives the bellhop the difference of $5 to give back to the men. The bellhop can’t think of an easy way to evenly distribute this money to the three men so he keeps two dollars for himself and gives one dollar back to each man. The men have now each paid $9 for a total of $27 and the bellhop has $2 — what happened to the other dollar?

I hope you are completely befuddled. There is in fact nothing to this riddle except a little misdirection. There is no missing dollar, I just worded the problem in a way that seemed completely logical but in fact has no bearing on the situation whatsoever. You should realize that the three men have $3, the bellhop has $2 and the hotel manager has $25 which sums up to a tidy $30.

The 401k loan problem is similar in that the last three points above are completely true but they do not help you answer the question — are 401k loans taxed twice? I will put forth two scenarios to hopefully bring some clarity to this problem. In both scenarios the man is buying a car for $20,000, he has $20,000 in his 401k and can borrow the entire amount (not true in real life, but simplifies our scenarios), he is retiring in 10 years and he earns 8% on all money he invests.

In the first scenario the man takes out a car loan for $20,000 at 9% for 48 months. He leaves the $20,000 in his 401k to earn 8%. After the loan is paid off he diverts the payments he was making on the car into the 401k for 6 years and then retires.

In the second scenario the man takes out a loan against his 401k at 6% for 48 months. At 6% his payments are less than in the first scenario, so to keep things equal he gets to invest the difference into his 401k. At the end of the 48 months he keeps putting those payments into the 401k for 6 years until he retires.

In both cases he takes out a loan. In both cases he pays back the loan with after-tax money which is the only way you can pay back loan, (I think home equity loans are an exception). The money from the loan is not taxed in both cases. As you can see, the fact that the 401k loan was taken from an account that had pre-tax money in it doesn’t even enter the equation. Again, the last three of the five truisms above that personal finance gurus often hound on aren’t even connected to this problem.

Now, which is better you ask? If you assume that your monthly payments to the 401k loan are then reinvested at 8%, the math that I did showed that the final balance of the 401k loan in the second scenario at retirement had over $10,000 more than in the first scenario. If the payments are not automatically reinvested then I don’t know what the answer is, but it’s probably not as clear cut as you might think. Remember, theoretically you can invest the difference in loan payments so if your 401k loan has a lower rate, you get to invest the difference in pre-tax dollars over the duration of the loan. You have to compare that to what your money would make if it just stayed in your 401k. I’m reluctant to make any guesses without doing the math, (I haven’t had to face this problem yet), but I suspect you’re usually better off just taking a regular loan. My energy for solving theoretical problems has officially run out, so if someone else wants to figure out whether a regular loan is better than a 401k loan assuming your payments are not reinvested immediately I think that would be a great service to everyone. In the mean time, I have the spreadsheet I used and am happy to email it to anyone on request.

GTD for your personal finances

April 12th, 2007

I really appreciate the comments on my last post. They were all thought provoking and fun to read. I’m looking forward to responding to them, but in the mean time this post is in a completely different vein.

I really thought that I had my finances in order. Beth and I have a cushy savings account that could cover about four months worth of expenses; we have no credit card debt and only $20,000 in student loans all of which is mostly at 3% or some other ridiculously low rate. Even still, I found myself worrying about our money, I felt like I didn’t have any control over where money was going and that the only reason we were doing well at all was because when we transitioned from college life to the working world our income more than doubled – once we adjusted to this, it seemed to me as if we would be in trouble.

I am a very organized person. This is not a natural ability of mine. In my teenage years I recognized that I needed some way to keep track of my outstanding to-dos, but about the closest I ever came to a ‘system’ was a pile of papers very neatly crammed in my backpack. I knew that the most recent stuff was at the top and so I mainly dealt with that layer. At the end of each semester I went through the pile and put anything I thought I might like to keep in my filing cabinet. Needless to say, this wasn’t the greatest system and as a result I was never very reliable.

In college I lived in a 10×10 foot room with a roommate for 2 years. That room got messy fast. I quickly learned that the only way to keep things under control was to make sure that everything had a place. It wasn’t so important to me that everything was always in its place, (remember I’m not a naturally organized person), but as long as I knew where everything should go then it never took more than 30 minutes to clean up even the worst messes. This gave me great peace of mind. When I looked at the room, Instead of thinking, “I really should clean that mess up, but it’s so much work it will have to wait”, I always knew how much work it would take to clean up, so I could decide whether I wanted to do it at that moment or later.

As it turns out, making sure that everything has a place is the key to any organizational system. When you’re organizing what’s in your head, the key is to take everything out and put it somewhere where you know you will find it at the appropriate time. If you know that everything is in your system and everything will present itself at the appropriate time so that you won’t forget – anxiety almost completely disappears. I use the GTD system created by David Allen, and I highly recommend this system to anyone.

When looking at my money situation I realized that the reason I had anxiety was because I didn’t have a place for everything – my system sucked. I decided to sit down one day and bang out something useful, and I thought I would share what I created with everyone since I think it’s incredibly useful. (Would I come up with anything that isn’t incredible? No).

The System

You will need a notepad and a copy of all your bills. The bills don’t have to be the most recent as long as it includes the date it is due and the amount. Go through each of the bills and write the due date and the amount down, also write down your paycheck amount and the corresponding dates, then order this list by date.

Now you need to decide on a fiscal period. This is fairly arbitrary, so do what makes the most sense to you but don’t think about it for too long. I picked the billing cycle of my American Express card from the 22nd to the 22nd of each month.
Now we lump our expenses into three categories:

  • Automatic withdrawals, (savings, retirement, etc.)
  • Fixed, recurring expenses
  • Everything else

Automatic withdrawals:

I have 15% of my paycheck dumped into a savings account. Beth and I are saving for a down payment on a house, so nothing is going towards retirement at the moment. Once we’re done with the house, this will change. It’s up to you how much you save here. Here is the order that I would go in: 3-6 month emergency fund, retirement accounts, other investments. If your company offers matching on their 401k, always make that top priority.

Open up an account with Emigrant direct and set up direct deposit through your payroll department. I have two direct deposits with 85% going into my checking account and 15% going into savings.
Fixed, recurring expenses:

This is where that list of bills comes in. These bills come up every month, and they are almost always the same amount, (for utilities I just picked a number that seemed like it would almost always be more than the bill).

The goal with the list of these bills and creating a fiscal period is to make it possible to come up with one or two days that you can put on your calendar when you will pay all the bills and make sure everything is headed in the right direction. I looked at mine and it wasn’t immediately evident to me how I would accomplish this. Then I realized that I could set up automatic billing for almost all of my fixed expenses which meant that I only needed to worry about paying off my MasterCard bill on time.

Now the days I think about money are on my calendar, (remember my billing cycle is 22nd to 22nd, so these dates appear to go backwards):

The 24th, close fiscal month, (this is my process, yours may be slightly different)

  • Pay American express balances
  • Review assumptions in financial plan, (paychecks, monthly recurring bills, etc.), make any necessary adjustments
  • Transfer money to or from to make checking account balance equal $2300. This is enough to cover recurring fixed expenses: MasterCard bill (this are all my automatic bills, we don’t carry a balance), student loans, electric bill, rent + $300 pad. I will need to pay much of this before the first paycheck of my billing cycle. This may require some adjusting up front to get to this initial balance, but after one month there should not be too much adjusting.
  • Set up any automatic transfers to occur for planned future expenses. For example, you want to buy a $200 bookshelf in two months, you set up an automatic transfer to secondary savings account for $100 to occur twice. Adjust your available spending cash for the month. You are treating saving like a bill that must be paid. (More on this later).

The 13th

  • Pay MasterCard balance

Everything Else

Add up your recurring fixed expenses and subtract that from your monthly income, (You’re income is your original paycheck minus all of the behind the scenes automatic withdrawals). Don’t spend more than that amount. That’s it. What, no budget? I don’t think people really need a budget. I think the only useful thing a budget does is force you to allocate all of your money – this way you know how much you can spend. This of course naturally reduces anxiety but it is a huge amount of overhead. Why do I need to know how much money I can spend on books? I only allocated $15 per month but I really want to buy that $22 dollar book but it will put me over budget! Screw that. I can spend $1200 a month. I know between gas and food, I typically have about $500 left. I have a pretty good feel for how much I have to spend, I can also check my American express balance and see if I’m headed up too quickly – if that’s the case then I just slow down my spending. Easy.

If you want to purchase a relatively big ticket item, (I would say over $100 falls into this category), treat it like a fixed, recurring expense. That’s what the fourth bullet above is describing. Pay $50/month into your savings account for two months, then you can buy your $100 thing. “But I really want that $300 oak vanity now!” or “But I owe $900 for car insurance next week because I forgot to plan for it!” Okay, give yourself a loan. I’m assuming you have 3-6 months of savings, pull it from there, charge yourself 5%, and create a loan payment in the fixed, recurring bills category. Keep in mind that with any of this, it is subtracted from what you can spend each month, so you will have to spend less money to by that vanity.

What have I left out?

Let me know! It seems to me as if this covers everything. I don’t really need to think about my money except once a month I do a high level check and every couple of days or so I check my American Express balance to monitor my day-to-day spending. My anxiety levels around money have disappeared.

life after death

April 9th, 2007

Imagine two universes: Heaven and Everyone-Else. Heaven and Everyone-Else never touch or interact. A human in Heaven can’t see, touch, smell, taste or use any other measurement tool that could ever be created to observe Everyone-Else, and vice versa.

If such a scenario exists, and we are in Everyone-Else, is it useful for us to spend any time thinking about Heaven? Of course not, because we can’t affect Heaven and Heaven can’t affect us. In this case we can’t prove that Heaven doesn’t exist – but who cares, because it can’t even change one atom of this universe. This is a useless definition of Heaven, because we can’t even get there.

If we change the scenario and say you can go to Heaven, but you can’t come back, then this starts to look like a fairly common description of life after death as defined by Christians. When a Christian dies his or her sole soul leaves Everyone-Else and goes to Heaven and never comes back, (none of that reincarnation bologna). On the way to Heaven, the sole is stripped of sin which can’t ever enter Heaven.

By going to Heaven, we have taken something away from Everyone-Else — our soul. If this is the case, we should be able to measure this transfer of energy and prove that there is life after death. If there is nothing to measure, then there is no life after death.

It is impossible to create any version of life after death, any version of Heaven that does not at least in some way create a measurable effect. If it’s not measurable or observable, then it doesn’t exist and it is like the first scenario. If Heaven can’t interact with us in any way then it is pointless to think about or speculate on the existence of Heaven. If Heaven can interact with us then we can measure it and observe it – and therefore it is part of this universe. If life after death exists we can prove it.

We can take this logic and apply it to everything that we as Christians speculate exists – if it has the ability to affect the universe then we can prove it exists. If it doesn’t affect the universe, and can’t ever affect the universe, then we can’t prove that it doesn’t exist – but it also has absolutely no effect on the universe, so who cares?