Monday, March 30, 2009

Number Eight: A WSJ Subscription

A recent Wall Street Journal article titled "Seven Things You're Wasting Money On" offers advice for those looking to cut back in these tough economic times:

"Someone buying a 40-inch Samsung flat panel high-def television at Best Buy for $800 has the option to add a four-year protection plan for another $150. Skip it, and pocket the cash instead."

Really?  Skip the protection plan?  That's your big advice?  How about not buying the 40 inch flat panel high-def television in the first place!

Duh.

Thursday, March 26, 2009

Spring cleaning

I was looking for some speaker wire in the basement tonight and I happened across a pile of old computer books.  The highlights:


Red Hat Linux User's Guide (1996)

One day in college somebody in the CS department was handing out copies of Red Hat Linux.  It came on 2 CD's in a nice plastic case and the user's guide was included.  Ironically, I was never able to successfully install that version of Linux on my computer (I couldn't get it to recognize my CD drive).  The CD's are long gone, but for some reason years later I still have the book.



National Semiconductor Databooks (1995-1996)

Leftover from my long dead stereo building project are this very nice set of databooks from National Semiconductor.  I'm guessing that they spent more money on printing and shipping these books to me than they made on the handful of transistors and integrated circuits I bought from them.



Borland C++ Manuals (1994)

The smell of these books alone gave me flashbacks of all of the late nights I spent hunched over my old trusty Windows 3.11 machine learning how to program.  Ahh, the memories.

I had bought a copy of Borland C++ 4.0 off of my freshman roommate for something like 70 bucks.  He had been planning on majoring in CS, but after nearly failing the intro class he wisely decided to switch majors.  If not for that I might never have become a software engineer.



Fundamentals of Data Processing (1981)

Flipping through this book is a lot of fun.  There are lots of pictures of polyester clad individuals feeding giant piles of punch cards into computers that are bigger than my garage.  Among other things it contains a chapter on flow charting, introductions to both BASIC and COBOL, and a lengthy comparison of punch cards vs. magnetic tape.  It also has a chapter on careers in data processing.  The salary data shown below is from that chapter.  The top salary shown is for around $31,000.  Not bad for 1980.



This is all good stuff, but unfortunately, computer books don't age all that well.  The trashman cometh tomorrow.

Saturday, March 14, 2009

The other thing I learned today

I learned that the Python programming language is named after the British comedy troupe Monty Python.

Nice.

Friday, March 13, 2009

Fun with factorials

A long time ago in a job interview I was asked the following question:

How many consecutive zeros are at the end of one thousand factorial?

After a little bit of thinking I managed to figure out the trick (hint: think about the factors of 1000! that would produce zeros at the end of the product when you multiply - then count those factors). I didn't get the job, but I liked the question so much I often use it when I conduct interviews.

I happen to think that asking a question like this out the blue isn't a very good way to evaluate whether someone will be a good developer or not. What I like to do instead is have a conversation about factorials that eventually leads to the above question. For example, I get them to write both an iterative and a recursive function to calculate factorials. That leads to a discussion of topics like error handling, input validation, stack overflow, and tail recursion. The strong candidates breeze through this stuff. I'm constantly amazed by how many "senior" developers don't breeze through this stuff.

If they're doing reasonably well I will eventually pull out the above question out and we will discuss it. It's the last technical question that I ask and it seems to wrap things up nicely.

One time I was interviewing a developer who I will call Ted. Ted was obviously smart, and he had tons of experience, more than me in fact. He breezed through all of my questions, and his coding skills were solid. We progressed quickly through the topics I wanted to talk about. When we got to my last question, the one listed above, I figured that he would breeze through that too. But I figured wrong. For some reason he struggled with it. He kept getting himself confused and going around in circles. I ended up walking him through the steps to a solution, but I don't think he ever really understood what I was saying. It was like he was a different person. Eventually I ended the interview and sent him on his way.

I figured that I would never see him again.

Once again I figured wrong.

The next day Ted showed up at my office and asked to see me. He had a printout in his hand which he handed to me. There were numbers all over it.

"What's this?" I asked.

"It's one thousand factorial," he said. "I wrote a program to calculate it and count the zeros on the end."

I squinted at the paper. Sure enough, there was an enormous number followed by the number 249 at the bottom, which is in fact the right answer for the number of zeros. I had never actually bothered to calculate 1000!, so I had no idea if his enormous number was correct or not.

Intrigued, I asked him how his program worked. It turns out that Ted had write a multiplication function that worked on string representation of numbers, like this:

string strProduct = MultiplyStrings("1000","999");

We were both C++ guys and this seemed like a perfectly fine solution. After Ted left I sat down and wrote my own version of a program to do this. Instead of using strings I used integer vectors. Writing the MultiplyVector function was a little tricky but soon I had calculated 1000! for myself. Ted's number matched mine. I happily filed the program away and went back to whatever it was I was doing before Ted showed up. And then I forgot all about it.

Many months went by and I decided to learn python. Today I read the Wikipedia page for the python programming language. I figured that it was as good a place as any to start. About halfway down it says that an int is "an immutable fixed precision number of unlimited magnitude". Immediately I thought of the factorial problem. It would be trivial to calculate 1000! if you had integers of unlimited magnitude. Five minutes later I had written my first python program:

import sys

sys.setrecursionlimit(1001)

def factorial(n):
if (n < 2):
return 1
return n * factorial(n - 1)

def count_zeros(n):
if (n % 10 != 0):
return 0
return 1 + count_zeros(n / 10)

a = factorial(1000)
print a
print
print count_zeros(a)


When I first tried this I didn't have the bit about setting the recursion limit and I got a "maximum recursion depth exceeded" error. Python doesn't support tail recursion, so my options were to rewrite it using a loop or else figure out how to increase the recursion limit. A Google search quickly lead me to the setrecursionlimit function, and I was on my way. Ironically, the default recursion limit is 1000. I only had to increase the limit by 1. Of course, rewriting this using a loop would have been trivial as well, but using recursion to solve factorials is not only natural, it's the canonical example.

My entire experience with Python consists of walking through the Google Application Engine tutorial, reading the aforementioned Wikipedia page, and then writing this program. The syntax is very easy to learn because there is almost no syntax. The one hard thing you have do for this program, storing and multiplying really big integers, is already taken care of. So I was able to write a program in Python, a language I don't know, in about 5 minutes. By comparison it took me about 30 minutes to write the same program in C++, a language I've been programming in for about 15 years. To be fair, I could have used a "big number" library in C++, but I wanted to work out the details out for myself. I was thinking that it might make a good interview question. But still, 5 minutes in a language I don't even know? Awesome.

I wonder what else Python can do.

The science unfair

When I was growing up the junior high had a science fair every year. The gym would be bursting with row after row of tables overflowing with volcanoes, solar systems, and the fanciest equipment that dad could build.

I don't recall anyone having those nice folding cardboard display boards that they all have now. Instead everyone just used regular poster board with a slight curve to make it stand up. If you've ever tried to make a poster stand up this way you know that it doesn't work very well. A solid bump on the table would make it fall down. Because the gym was very crowded this happened often.

Each student had to stand in front of their display and wait for the judges to come around. This took a while, and during that time family members and other students could browse around and look at all of the projects. Eventually they would hand out the awards, and everyone would pack up and go home.

Unfortunately, I never got to take part in the junior high science fair. For some reason they cancelled it for the two years that I went there. But when my older brother and sister were in junior high I got to go. Honestly, I'm a bit disappointed that I never got to do it. It seemed so exciting. There was a certain energy in that gym. It felt like something important was happening. To me it was an event. What else does a science geek have to look forward to in a small town?

My daughter's science fair was last night, and I was really looking forward to it. I was expecting that same level of energy and excitement that I remembered. In fact, since her school is about four times as big as mine was, I was anticipating an absolute three ring circus. As it turns out, it was barely a side show.

For starters, the projects are all judged anonymously. They do the judging the day before based solely on the display board, which must be devoid of all identifying marks. That way the judges don't know who did what project, and in theory they won't be biased. One big downside is that the judges can't ask any questions. Having to answer questions and defend your work is an important skill to learn, and now that's gone from the science fair. Plus it makes it easier to pass off mom and pa's work as your own, since you don't even have to understand it.

When we got there the place was almost deserted. A handful of people were perusing the displays and reading silently. There were maybe only 50 projects in the cavernous cafeteria. And this for a school with around 800 kids! The students didn't have to stand in front of their displays and talk about them. They didn't even have to be there on time. It felt more like an art museum than a science fair.

We soon discovered that my daughter's display board wasn't in the fifth grade experimental section where it was supposed to be. Instead we found it in the sixth grade life sciences section. Somehow it had ended up over there and because of the anonymous judging there was no easy way to correct the mistake. Immediately my heart sank. I knew that any shot of her winning was gone. Her project had nothing do with life sciences, and the sixth grade judging criteria was tougher to begin with.

Every child that entered was either a winner or received an honorable mention. When they announced my daughter's category she was the first to receive her honorable mention, which I later figured out means that she had the lowest score, which figures since it was judged incorrectly.

Basically, the system that was put in place to prevent children from being judged unfairly by biased judges ended up causing my daughter to be judged unfairly. I suppose that I could tell myself that she learned an even more important lesson about how the world works, and maybe she did, but mostly I just feel bad for her.

Losing is one thing. Not getting a fair shake is something worse.

Friday, March 6, 2009

Watch out for those Mt. Lebanon girls

The local headlines in yahoo tonight:


Good times.

Thursday, March 5, 2009

Along came a spider

I heard the sudden inhale from all the way downstairs. Then came the shriek.

In no time at all I was upstairs and in my daughter's bedroom.

"What happened?" I said, trying to catch my breath.

"I felt something touch my leg," she said. "But then I realized that it was only my covers."

She grinned at me and said "Good night, daddy."

And so I went back downstairs.

Tuesday, March 3, 2009

The bird is beginning to move

I just finished the Google App Engine tutorial.

Here is my version of the Guest Book App:
http://onedozenbagels.appspot.com/

Feel free to leave me a message.

I wonder how many of these are up and running?

Monday, March 2, 2009

A touch of gray

I've been thinking about the possible downsides of cloud computing, specifically of using the Google App Engine.

The big obvious downside is that you are at the mercy of Google. If they raise the rates, cancel your app, or decide that cloud computing is a waste of money what choice do you have? At least with some of the other cloud services you can use standard technologies that are available outside of the service, so if you had to rebuild your site somewhere else it would be easier. For example, the Google datastore uses Big Table, which is propriety Google software. You would have to rewrite your code to use something else like hadoop or a standard relational database. Since I don't yet really know anything about the Google datastore (or about hadoop) I can't comment on how hard or easy this would be.

There are some interesting tidbits in the terms of service. Google can raise it's rates or lower the quotas with 90 days prior notice. They can immediately terminate your account at any time if you violate the terms of service, so it's probably a good idea to at least glance over them. They can terminate your account without giving you a reason as long as they give you 90 days of prior notice. Hopefully they put in that wording just in case they decide to terminate the entire program, not because they want to go around terminating accounts willy-nilly. That would probably be considered evil, but who is the arbiter of evil anyway?. If your account does get terminated, you will have 90 days to export your data. If your account is terminated without cause you will have 24 months to export your data.

If you can't live with that, then I suggest you go elsewhere to build your app.

Quotas

So in a recent post I blathered on for a while about the cost structure of EC2, Mosso, & Azure. But I never actually said what the Google App Engine free quotas were or how much additional resources cost.

According to Google the free amount of storage, bandwidth, and CPU usage that you get are designed to "serve a reasonably efficient application around 5 million page views per month, completely free." So far they have tweaked the quotas once, with the new set becoming effective on May 25, 2009. As of that date you will get 1 GB of data storage, 1 GB of bandwidth per day, and 6.5 CPU Hours per day for free. If you require more resources than that you can purchase them at the following rates:

1 GB of storage for 10 cents a month
1 GB of bandwidth for 15 cents
1 Hour of CPU time for 10 cents

Once you enable billing on your account you can set daily budget limits that you don't want to exceed. Since even a company like Google does not have infinite resources, there are upper limits to what you can buy. For example, the maximum number of requests that you can serve is 43 million per day, which translates to around 500 requests per second, which they claim is more than enough to survive being slashdotted or dugg. If by some miracle you need to temporarily handle more requests than that there's a form to request more resources.

What I have laid out is a very high level overview. The quota system is actually a bit more complicated. Feel free to check out all of the gory details for yourself here.

I'll be ready for kindergarten in the fall, promise

After thinking about it for a minute I realized why the water/anti-freeze mixture on the stove only gets to around 230°F instead of the proscribed 265°F on the back of the bottle. The mixture on the stove is at standard pressure. In a radiator it's under high pressure. Duh!

I sure am putting my 4 year college degree in science to good use, aren't I?

What's even worse is that I bought a replacement radiator cap for my car a few years ago when I lost the old one (don't ask). The cap was rated at 16psi. So I really should have known better.

Sigh.

Sunday, March 1, 2009

I'm stepping through the door and I'm floating in a most peculiar way

So after just a few minutes I have a hello world app up and running in the Google App Engine development server on my machine.

Very exciting stuff:


A few points of interest:

1. Every Google Apps Engine application has a configuration file written in the YAML syntax. The config file contains a version number. According to the Getting Started Guide you can use this to save old versions of your app:

This is version number 1 of this application's code. If you adjust this before uploading new versions of your application software, App Engine will retain previous versions, and let you roll back to a previous version using the administrative console.

I haven't even seen the administrative console yet, but it sounds interesting.

2. You also have to specify the runtime environment in the config file. Currently the only valid setting is Python, but they claim that they may add more languages in the future.

3. You use Google Query Language (GQL) to query the Big Table datastore that is available in the Google Application Engine environment. GQL looks very similar to SQL. Here's an example query from the guide:
"SELECT * FROM Greeting ORDER BY date DESC LIMIT 10"
Queries like this do not generate recordsets or tables in the traditional sense. Instead they generate a set of data objects that you can manipulate. In this case it will generate a set of 10 objects of type Greeting, which was previously defined.

You cannot query for a subset of the fields in a data object; you must query for all of the fields. Otherwise you might have a set of objects that are partially defined. Thus the "SELECT *" isn't actually needed at all in the query since it is the only option. Apparently it's just there to make it easier to read for people used to SQL.

Additionally, GQL does not allow constant values directly in a where clause. All values must be bound to parameters, which will help prevent GQL injection attacks.

4. It turns out that I have a hard time writing code without terminating every statement with a semi-colon. That's what years of using C++ will do to you.

Clearly not smarter than a 5th grader

For her 5th grade science fair project my daughter is seeing how adding different things to water affects the boiling and freezing points. She tried adding several different things: table salt, driveway ice melter, bubble bath, sugar, & anti-freeze. Pretty standard stuff.

According to the back of the anti-freeze bottle a solution consisting of 50% water & 50% anti-freeze should boil at 265°F. So after we were done I mixed half a cup of water with half a cup of anti-freeze and boiled it on the stove. The highest temperature reading I got was 228°F.

Hmmmm.

Update: I figured it out.

More options

A new day brings more to consider.

Last night I get pretty excited about the Google App Engine. As it turns out, the other big guys are doing similar things. Amazon has its Elastic Compute Cloud or EC2. Rackspace has Mosso. Microsoft is building Azure. Yahoo has announced that they are working on something, but they haven't really released any details yet. Unlike Google, none of them appear to have a free starting point. Perhaps Yahoo will, but we will have to wait to find out.

EC2 lets you rent various sized virtual machines, which come in three different sizes. A "small" linux virtual machine costs 10 cents per hour. A "large" linux vm costs 40 cents per hour. An "extra large" vm costs 80 cents per hour. Apparently there's no medium. Windows vm's and "High CPU" vm's can also be had for more money. There are also monthly fees for bandwitdh (between 10 and 17 cents per GB), for storage (10 cents per GB), as well as for data usage (10 cents per million I/O requests). Since you're getting a vm it looks like you can pick which database and web technologies you want to use, which is a big plus.

For $100 a month Mosso gives you 50 GB of storage, 500 GB of bandwidth, and 10,000 compute cycles, which it claims is the equivalent of 2.8 GHz processor running for a month. Additional resources can be purchases at the following monthly rates: 50 cents / GB storage, 25 cents / GB bandwitdh, and a penny for each additional compute cycle. For additional fees they also offer SQL Server, SSL, automated customer billing, and 24x7 tech support. Like EC2, it also looks like many different technologies are available for use.

Azure is in the Community Technolgy Preview phase, so I couldn't find any pricing details. As you would expect, the full Microsoft web stack is available for use.

These are interesting times to be a developer.

Post Zero

I am the anti-fanboy. For whatever reason very few things get my juices really going.

When Java came out they said it was the greatest thing ever. I looked at it. Yet another programming language? I shrugged and got back to work.

When XML came out they said it would revolutionize everything. That time I even bought a book on the subject. Could this panacea really just be a data layout format? And a bloated one at that? Surely you jest.

When Google exploded onto the scene they said it was the greatest company ever. Really? Ever? Ever is a long time you know. What's the big deal? They're a search engine company that sells ads that make a lot money. So what? If Google dropped off of the face of the earth tomorrow we would all switch our searches to Yahoo or Live or whatever and life would move on. In a week we wouldn't even remember them.

But tonight I discovered the Google App Engine. Basically you can write a web app in Python that Google will host. You get instant scalability. You get instant reliability. You get instant parallelism. You get instant redundancy. You get powerful Google services like Big Table. And best of all, you get it for free. That's right, I said free. At least up to reasonably high usage quotas. Then you can opt to pay for more bandwidth, storage, etc... But by then hopefully you've figured out a way to monetize your app.

You can check it out for yourself here. It almost seems to good to be true. You can write an app and potentially deploy it to billions of people without ever having to buy a server or use big words like "co-location facility". Certainly, there have been plenty of application hosting frameworks before, but this one has lots of potential.

Needless to say my juices started flowing. I have a strange urge to write something on this platform. I haven't felt this way since I figured out how to write programs on my TI-85.

More on that later.

First I need to find a Python tutorial.

Ye gads!

I've had this blog for what, a week? And I've already started a second one. This one will be for posts relating to software engineering.

Check it out here.