Saturday, January 23, 2010

Closures and Objects in JavaScript

"If you want to make an apple pie from scratch, you must first create the universe." - Carl Sagan

I've always hated the word "JavaScript". What's up with that capital S? However I've always loved the language. I learned the basics of it when Netscape 3 came out in 1996, and was immediately hooked. Your web browser became a scripting language interpreter, how cool! Before then most web pages were static, and business websites, if they existed at all, were mainly shells listing contact information and displaying the company logo.

Some pages I stumbled on back then used CGI scripts to take user input and do something with it - private content that required a login, rudimentary chat, surveys like the ever-popular "purity test", Pi calculators (show me __ digits of Pi [Submit]), things like that. The scripts were all server-side, though. The code was being executed from private space in the web server's cgi-bin directory. For people relatively new to the web like myself, doing something like this was an impossibility. We hadn't found Linux or Apache yet, hadn't learned perl or shell scripting, and our web hosts were angelfire, geocities, tripod, and CompuServe and AOL's user page areas. We could do chili recipes, pictures of our cats, and link to other people's recipes and cat pictures, but not write anything interactive.

From the professional programmers of 1996, Javascript was immediately scorned as a toy for little kids playing progammer. For those of us with a little insight who didn't have cgi-bin access on the web host we were using, Javascript was nothing less than a godsend. We struggled to do client-side what could previously only be done by a script on the webserver. We begged for more features from Netscape. Microsoft struggled to copy the functionality with JScript. Standards bodies struggled to make a standard language definition out of it. Good times.

Monday, January 18, 2010

Good recursion, bad recursion

"Go to the store, buy some more, 99 bottles of beer on the wall!" - 99 Bottles of Beer

Factorials are a common math problem used in computer programming tutorials. For those who don't remember them from 5th grade math class, factorials are integers followed by an exclamation mark. You multiply the number by all the numbers that come before it, down to 1. They go thusly:

1! = 1
2! = 2 * 1 = 2
3! = 3 * 2 * 1 = 6
4! = 4 * 3 * 2 * 1 = 24

Another way of expressing this same idea is with recursion. Recursion is basically self-reference in an expression. Let's use the euphemism "Same shit, different day" to illustrate:

shit(day) = shit(day - 1)

Thursday, January 14, 2010

Gaming and Coding

So I've been killing lots of time lately playing Flash video games on the games portal. The one I'm currently whittling my way through is called "Cargo Bridge", where you have to build wood or steel bridges across gaps, and then laborers test the bridge by transporting boxes of unknown contents across it, as well as the occasional elephant.

The game that got me hooked on Flash games is called "Use Boxmen". I discovered that a couple months ago, and after beating the game I quickly sought out others. Naturally I've played puzzle games on the web before, but Boxmen was the one that really piqued my interest in the genre. I found it on Kongregate, but it is hosted also at the author's homepage.

The game is very cartoonized with stick figure avatars, and reminds me vaguely of "Simon in the Land of Chalk Drawings". I found it when looking for the "Quake Done Quick" walkthroughs on youtube, and then just browsed around looking at walkthroughs of other games. I found the boxmen one here:

Wednesday, January 06, 2010

Google Analytics, and sometimes I can't do math

First, my apologies to rich people: You're getting at most a $65 tax break over last year, not the 5% I promised you. I didn't account for the extra tax brackets that came with the new withholding tables. There are nine tax brackets now rather than seven, and things line up less disturbingly than I thought. Still, poor people have a higher tax obligation than last year, rich people a smaller one. The amounts are now insignificant, but the symbolism is still bad.

Here are the corrected charts, first, how much normal people will be paying extra, then how much less rich people will be paying. I'm including the new amounts for people filing as married, as well.

Monday, January 04, 2010

Oh, it really is the rich getting richer, after all

(Update, Jan 6, 2010 - Bad math corrected.)

I've heard the phrase "it's the rich gettin' richer and the poor gettin' poorer" often throughout my life, usually by old-timers discussing politics, social mobility, the decline of the middle class, things like that. Like most things people say when they're complaining about the government or "rich people", I didn't put much stock in it.

Each year since 2006 I have created a spreadsheet at work to calculate what my paycheck should be. You fill in how much you pay for insurance, whether you're filing as single or married, how many exemptions you're claiming, and your salary, and it outputs what your paycheck should be - give or take a couple pennies. To make it work correctly, I stumbled through figuring out how gross, taxable, and net income are calculated, what federal, state, and local withholdings should be, how exemptions work, how 401k and company paid benefits are calculated, what marital status really changes. Here are a couple examples to show how nuts payroll math can be:
  • 401k isn't tax-free. Medicare, Social Security, and the city of Columbus all tax your 401k contributions.
  • Saying you're married on your W-4 decreases federal withholding only, and only if you make more than $15,000. The state of Ohio doesn't care if you're married or not.
  • Employee-paid benefits (life insurance, for example) aren't really free. They count as a raise in taxable income that is deducted back off after withholding is calculated.
So today I started on this year's spreadsheet using the withholding tables listed on 2010's Publication 15 on The tables looked odd, making me suspicious, so I investigated and got all mathy. Usually as your pay rate goes up, your tax rate goes up. In 2009, for example, single people making over $10,400 annually were taxed at 15%. Those making over $36,200 were taxed at 25%. $66,530 = 28%, $173,600 = 33%, and $375,000 = 35%. This year was similar, unless you make between $84,450 and $87,700. In that range, your tax rate jumps up from 27% to 30%. After $87,700, the rate drops back down to 28%. Confused, I decided to run the 2009 tables and 2010 tables through for different pay rates to see what the real tax amount would be for each income level. As you can predict, that produced a pile of meaningless numbers, and my eyes quickly crossed. "OK, then," I said to myself "let's just subtract the 2010 tax from the 2009 tax for different income levels and see what happens". It took a few seconds of glancing at the results for me to loudly declare that yes, indeed, the rich are getting richer, and the poor are getting poorer. Not by much, but by enough to notice. If you make $10,000, this year you'll pay $113 more in federal deductions than you did in 2009. If you make $200,000 annually, this year you'll pay $1,000 $25.85 LESS in federal withholdings than you did last year. Here's a chart showing some sample incomes and change in withholdings, including the sweet-spot of $76,865 where the withholding is the same both years: