Friday, February 10, 2012

The simplest possible computer

The simplest possible computer

So, if we were going to build a model of the simplest possible computer, where would we start? As it turns out, you probably have such a model in your home already.


Many homes have what's known as a "three-way" switch, which is a light switch that you can turn on and off from two different locations. This circuit can be used as a simple digital computer.





By properly labeling the switch positions and the light bulb, we can use them to solve a logic problem.


Let's say that you need a system to tell you whether to have dessert with your lunch, but you have some specific rules to follow:

1. If you have a salad for lunch, you'll have dessert.

2. If you have soup for lunch, you'll have dessert.

3. If you have both soup and salad for lunch, you'll skip dessert (since you'll be over-full).

4. If you haven't had anything for lunch, you won't have dessert (because dessert on an empty stomach will make you sick).


Here's how to solve this problem with the three-way switch:


If necessary, flip one of the switches so that the light is off. Label the positions that the switches are currently in. Label one "had soup", and the other "had salad". Label the other two positions "no soup" and "no salad", respectively. Hang a sign on the light bulb that reads "have dessert".


Congratulations! You now have a computer that will tell you, based on whether you've had soup and/or salad, whether you should have dessert. Try it out, and you'll find that it follows the rules given above, and the light will only come on if you've had either soup or salad (but not both).


This isn't all that exciting by itself, but this same circuit can be used to solve an entire family of related logic problems, just by changing the labels on the switches and the light bulb. This ability to use the same logic to solve many different problems is the source of the flexibility of computers, and is what enables them to be useful for so many different things.


A new project!

I'm working on a "book" in my spare time. I put book in quotes there, because I don't know that it'll actually get to the level of being published on dead trees. Due to the subject matter, it would make more sense to publish it online (or perhaps, via something like iBooks) in any case.

It's intended to be an introduction to Computer Science for non-nerds (and/or younger folk), which I'm sure is well-covered ground, but the unique direction I'm planning on taking is to start "at the bottom" with the most basic principles and work my way up.

This is based on conversations I've had with family and friends over the last few decades, at family gatherings, at parties, and on road trips. I get the impression that a lot of folks think that there's this mysterious "other level" beneath what they understand about their computer that requires a lot of formal training to understand. I want to show that things aren't really that complicated at the lower level, and that all of the complexity is layered on top of a very simple foundation.

And, I find the subject really interesting, so I enjoy writing about it. I'm going to set up a website for he new project soon, but in the meantime, I'll put an excerpt up here to see what people think.

Update: Here it is - The Simplest Possible Computer

Wednesday, June 08, 2011

Time for a reboot...

Okay, it's now been more than a year and a half since I updated this blog. I need to get back on the horse. Stay tuned for an update soon (really)!

Sunday, January 24, 2010

JavaScript by example: functions and function objects

I've been working in JavaScript a lot these last couple of months, and I feel like I've learned a lot. I wanted to show some of the more interesting aspects of JavaScript that I've had the opportunity to bump into. I'll use some simple examples along the way to illustrate my points.

Note: If you want to follow along with the examples in this blog post (and the followup posts), you'll probably want to use an interactive JavaScript environment. I tend to use Firebug with Firefox when I'm trying stuff out, but there shouldn't be anything in these examples that won't work in the WebKit console in Safari or Chrome, or in Rhino, for that matter.

Functions

A simple function is defined and used in JavaScript thusly:

function add(x, y) {
return x + y;
}
console.log(add(3, 5)); // this prints "8" to the console

This does just about what it looks like it does. There's no trickery here (the trickery comes later on). Let's say that we want a version of this function that takes a single argument, and always adds 5 to it. You could do that like this:

function add5(a) {
return add(a, 5);
}

console.log(add5(3)); // prints "8"

But what if you're going to need a bunch of these one-argument variants on the add function? Well, since functions are first-class objects in JavaScript, you can do this:

function make_adder(v) {
var f = function(x) {
return add(x, v);
};
return f;
}

var add7 = make_adder(7); //create a function
console.log(add7(3)); // prints "10"

This is only slightly more complicated than the original example. One possibly subtle point here is that the returned function "captures" the value of v that was passed into make_adder. In a more formal discussion, you'd call this a closure.

Sunday, June 07, 2009

PuzzleTwist is now available!

My latest creation is now up on the iTunes App Store. It's called PuzzleTwist, and it's a puzzle game where you unscramble a picture by rotating the pieces.  As each piece is rotated into place, others will rotate as well - some in the same direction, some in the opposite direction. The key to solving the puzzle is to figure out what order to move the pieces in.

One unique feature is that the rules for each puzzle are different - some are simple, some are more complex. A few are so difficult that I can't solve them without looking at the solution.

Once you've solved a puzzle, you can save the resulting picture in the Photo Library on your iPhone, and then use it as the wallpaper image for the phone, or assign it to one of your contacts.

PuzzleTwist also keeps track of the best reported scores, so you can compare your scores versus the rest of the world.

If you're a puzzle fan, you should check it out. Here's the iTunes store link.

On a side note, this application was approved much faster than the previous applications I submitted. Perhaps the App Store review team is coming out from under their backlog.

Tuesday, May 12, 2009

The eyes have it - a tale of 3 vision problems

I'm recovering from a head cold today, so rather than try to do heavy programming work, I decided to write up a personal story that I've been thinking about lately, for a variety of reasons. 

As anyone who knows me personally can probably attest, I wear glasses and have pretty bad eyesight.  Not many of my friends, and probably not even all of my family, know that I have three distinct vision problems, only one of which is actually addressed by my glasses. I'm going to tell y'all about all three, more or less in the order that I found out about them, and the ways in which they've been treated.

Disclaimer: I'm not an eye doctor, nor an expert in human vision. This is all about what my experience has been. It's entirely likely that I'll make at least one glaring error in my use of some technical term. Feel free to correct me.

Chapter 1: Nearsightedness and Astigmatism
Okay, that probably looks like two different problems, but they're both refractive issues, and they're caused by misshapen eyeballs, and so are corrected easily with eyeglasses. If I remember correctly, I got my first pair of glasses in the 5th grade, when I was 10 years old or so. 

I was pretty astounded at the difference when I put them on - for the first time, I could see the leaves on trees as individual objects. I asked my eye doctor how bad my vision was compared to the 20/20 that's considered "normal" and got the unsatisfying response that the 20/x scale wasn't really a useful measure for people with strong nearsightedness. Since I can barely find the eyechart on the wall at 20 feet without my glasses, I can now understand where he was coming from.

There was some consternation amongst the various parties involved about how it is that I could have gone without glasses as long as I had without anybody noticing that I was blind as a bat. For whatever reason, there wasn't any mandatory screening for vision problems in my elementary school. I got screened for a number of other potential issues, amusingly including colorblindness, but nobody ever stuck an eye chart up on the wall and had me read it.

The biggest issue was probably a simple (dare I say child-like?) assumption on my part that everybody else saw things more or less the same way that I did. So, since I couldn't see the blackboard if I was sitting in the back row, I assumed that nobody else could, either. And if it was critical to the learning process for us to be able to read what the teacher was writing, the school would have arranged the classroom such that it was possible, right?

It probably didn't help that I was also a bit of a daydreamer and a slacker. I think that when I said I didn't know that we had homework due, my teachers and my Mom assumed that I just wasn't paying attention, when in reality, I might have simply not seen the homework assignment written on the board.

As I get older, and more and more of my friends have children, it's occurring to me that there might actually be something useful for other people to learn from my experiences. I think the lesson here is actually a pretty simple one. Parents, talk to your kids about what their sensory experiences are. If someone had at any point between age 2 and age 10 simply asked me whether or not I could see some distant object, or count the number of birds on a telephone wire, or even tacked up an eye chart on the wall and tested me, I might have gotten into glasses sooner.

Alright, so I got glasses at age 10, which helped a lot with being able to see what was written on the blackboard, probably made it a lot safer for me to ride my bicycle around, and generally greatly improved my quality of life. Problem solved, right? Not so much. It turns out that I had another problem, which went unnoticed for several more years, despite going to the eye doctor regularly.

Chapter 2: Strabismus, or the "turned" eye
My right eye has a tendency to turn outwards and upwards, away from whatever it is that I'm looking at. When I was younger, this happened involuntarily, and fairly frequently. These days, I can do it "at will" which is a pretty great way to weird people out if they haven't seen it before. It still tends to happen spontaneously when I'm tired, or when I'm drunk.

Since my left eye is (evidently) my dominant eye, the turning out of my right eye didn't cause me much difficulty, except in one critical visual skill - depth perception. As best as I can remember, I was hit in the face by a baseball or softball while trying to catch it at least a dozen times during my youth. I was also considered pretty "clumsy" in general by most of my friends. 

An interesting aside is that your brain actually uses a lot of other cues besides the convergence of your eyes to judge depth, so it's not exactly true that I didn't have any depth perception. It is true that I had really bad depth perception up close, which is where convergence counts the most - hence my spectacularly-bad performance in the whole "get the glove up in front of the ball before it hits you" task.

This particular quirk in my vision went for quite a while before being discovered. In fact, I think it wasn't noticed until I was examined by a new eye doctor for the first time. The doctor who examined me actually had an intern working with him at the time. When he discovered the eye turn, he called the intern in so he could see how it worked.

Having established that I had this eye problem, the question then became what to do about it. The treatment for this problem varies depending on the ultimate cause, but can include everything from eye exercises, to wearing an eye patch, to surgery. At the time, it was widely believed that any treatment for this condition was essentially useless after about age 10 or so. 

The only recommendation from the eye doctor was that they could put a "prism" correction in my eyeglass lenses, which would help reduce any eyestrain I felt from the misaligned eye. As it turned out, the prism correction didn't do very much, either positive or negative, for me, though it did help my eye appear to other people to be pointing in the right direction.

In the years since, I've met several people who've had the Strabismus surgery, mostly as young children, and overall the success rate doesn't seem to be particularly high. I opted not to have the surgery, and it's worked out pretty well for me. I'd say that if you (or your child) have Strabismus, and someone suggests surgery, you'd do well to get a second opinion, and/or try some of the other treatments, before going forward with the surgery.

Chapter 3: Amblyopia, or "lazy" eye
 It turns out that if you have Strabismus from an early age, and/or if your eyes have significant differences in their refractive power (which mine do), then you've got an excellent chance of developing Amblyopia, which is where your brain adapts to ignore the input from the defective eye.

I had always known that the vision in my right eye was considerably worse than in my left eye, even when I wore my glasses. I had assumed (there's that word again) that the difference had something to do with the difference in astigmatism and nearsightedness between the two eyes. While that was probably part of the cause, it wasn't the whole story.

It turns out that my brain had mostly adapted to not use my right eye, though I still had some amount of vision from it. My right eye provided some peripheral vision on that side, and was essentially ignored for everything else. 

An interesting consequence of this that I discovered sometime in my twenties, was that I actually couldn't read if I covered up my left eye. This was a very strange experience. I could see through my right eye fairly well, and there was an image with shapes on it that I knew I ought to be able to recognize, but I wasn't able to make sense of them, at all.

Chapter 4: What I did about it
It bugged me that my eye was pointing out into space like that, and it really freaked me out that I had one eye that really didn't work at all, so I decided to try to "fix" it. You'll recall that the eye doctor told me that there really wasn't much to be done about this since I was "too old". I figured that if it wasn't going to work, it wasn't likely to hurt to try some things.

And I also figured that you hear about people who suffer traumatic brain injuries of one sort or another, and need to spend years in therapy, while their brain works around the damage. By comparison, working around a mental block on my right eye should be easy, right?

I started working on getting my right eye to point in the right direction. Since I did this on my own, I wasn't following anybody else's accepted eye training program, I just did the things that made sense to me. 

I strengthened my eye muscles and stretched them by repeatedly moving my eyes back and forth to the very limits of their motion. Sometimes I'd go left to right, sometimes top to bottom, sometimes in circles one way or another. I did this for a few minutes at a time, working up to about 1/2 an hour or so. 

I did these self-invented exercises nearly every night for probably a year or so, before I started noticing an improvement. When I first started, it was relatively easy for me to over-strain my right eye by trying to force it to the limit of its motion. Let me tell you, a cramp in your eye muscles is no fun at all. I still have a couple of positions that my right eye really doesn't like to go into, but the range of motion is much improved.

Concurrent with the work on the eye muscles, I tried closing my left eye when I was performing various everyday tasks - watching TV, shopping, driving (not in heavy traffic!), or just walking around. Doing that was always very tiring, and a bit stressful. I tended to get headaches if I tried to do it for very long.

Sometime after I moved to California, I had a breakthrough - occasionally, I'd briefly get my eyes to align properly as I was going about my everyday business, and the whole world would suddenly snap into 3-D perspective. It was really disorienting the first couple of times it happened, but I soon enough got used to it. 

It's a little like those "magic eye" random-dot stereograms. At first, it takes a while to get the knack of getting your eyes to cross by the right amount. Then suddenly, you get it right, and the image jumps out at you. After that, it gets easier to do. Over the course of several more years, I gradually trained myself to keep my eyes pointed in the same place, such that it's now second-nature.

I did go through an irritating period where the convergence of my vision wasn't 100% correct, but I was starting to pick out more detail with my right eye. That caused some double vision and headaches, from time to time. These days, I only have double vision sometimes at night.

Chapter 5: Closing Thoughts
Well, this is already ridiculously long, so I guess I'll save some of the amusing anecdotes I was originally going to include in here for a follow-up post. Mostly I wanted to get the story down so the folks that have heard me wise-cracking about "now" being able to see in 3-D know what I've been talking about. 

I also hope that if someone with relatively mild Strabismus and/or  Amblyopia comes across this article, they'll be somewhat encouraged by my success in overcoming them, even after having a late start. Everybody's case is going to be different, but personally, I'm glad that I made the effort.

Wednesday, April 22, 2009

Release early, release often...

Six Apps In Six Months - or, Why Mark Can't Schedule
That was the plan, anyway - but I haven't been able to keep myself on track. It's really difficult to release something when you're the only engineer working on it. It's hard to resist the temptation to just keep polishing the thing, or try out some new ideas, until you're well and truly past your milestone. Ah, well.

Beta Test Now Open
In the interest of trying to keep the pipeline flowing, I've just released "The Picture Puzzle Game Without an Interesting Name" to a select group of Beta testers. Since I don't want anyone to miss out on the fun of seeing what you get when I'm forced to release something that I don't think is ready, I'll put a link here to Starchy Tuber's Secret Beta page, where you can sign up to Beta test my latest creation.

If you like puzzle games, or if you're just interested in seeing how the sausage is made, the Starchy Tuber Secret Beta program is the place to be!

I reserve the right to limit Beta signups to the first 100 applicants (ha! as if...).

Grr. I just found a typo on the Beta Sign Up instructions. I'll go fix that...

Wednesday, March 25, 2009

Easter Pictems - a marketing experiment


I'm trying an experiment. There's a free version of Pictems up on the App Store now, loaded with just the subset of items appropriate for Easter.

This version is called "Easter Pictems", appropriately enough, and you can get it here, if you're curious about Pictems, but didn't feel like ponying up the $2.99 to find out whether you liked it.

I'm hoping that folks will download the free version and like it enough to upgrade to the full version. This seems to be a common tactic among developers on the App Store. Of course, people have to find out about your free app if it's to be of any value as a marketing tool. I'll update this post if anything dramatic happens with sales.

In related news, product #2 is coming along nicely. It's a puzzle game, along the lines of the sliding-squares puzzles you might be familiar with, but with a twist (literally, in this case). For this game, the idea of Free and Pay versions makes a lot of sense, so I'm going to release both at the same time. Here's a preview of the (as yet unnamed) puzzle game:

Thursday, March 05, 2009

Obsolescence is a pain in the neck...

I'm trying to clean out some of the unused/unloved technology around the house. An interesting case that I'm currently working on is Yvette's old laptop. She used this thing back in her college days, and it'd be nice to be able to get the data off it (for nostalgic purposes), then send it to the great computer graveyard.

It's an approximately 20-year old NEC DOS-based laptop, with a black-and-white LCD screen, and a massive 20 MB hard drive. It boots and seems to run just fine, a bit of a miracle in itself, but I haven't yet figured out how to get the data off of it.

You'd think that it'd be relatively easy to copy the data off this thing, but:

1. Accessing the floppy drive causes the computer to reboot.

2. Neither the serial port nor the modem are recognized by the communications software installed on the thing, so I can't transfer data that way.

3. This computer is old enough that those (and the printer port) are only external I/O ports - there's no USB, no network port, and no wireless network ability.

I took the thing apart, and discovered that the hard drive in it is actually an IDE drive. Wow - that's almost a current-generation drive technology. I figured I could just get an adapter, and connect the old hard drive directly to a new system. Piece of cake, right? I've already got a Firewire-to-IDE external drive case, so it ought to be just a matter of hooking things up.

Not so fast. They do make a 44-pin to 40 pin adaptor just for connecting laptop 40-pin drives to an IDE connector, and I can connect that adapter to my Firewire-to-IDE external drive enclosure, and the drive spins up on power-up and everything. However, it isn't recognized properly. Apparently the firewire-IDE adapter doesn't work correctly with this drive. If I had to take a guess, I'd guess that the adapter doesn't support IDE drives which don't do DMA transfers.

It's a bit frustrating to have a drive that I know is readable, and have no way to get the data off of it. I'll probably try another IDE bridge and see if it works with this drive, but if that's a bust, I may be in the market for an OLD PC that I can connect the drive to, copy the data off of it, and then recycle.

There may be a trip to Weird Stuff Warehouse in my near future...

Monday, February 16, 2009

Grr. Blogger hates me.

It won't even scale images correctly if I use the "upload image" tool. Oh, well. click the image to see the full comic...

A New Kind of Science meets XKCD

400 pages down, 450 to go. Here's my impression so far, with a little help from xkcd:

Conspiracy Theories



String Theory

Saturday, February 07, 2009

A New Kind Of Science

I'm currently struggling my way through Stephen Wolfram's book A New Kind Of Science. So far, I've made it to about page 200 or so (of 850, not including almost 350 pages of end-notes). I'm not going to review it until (unless?) I've gotten to the end, but so far, I'm not very impressed. This book is really frustrating to read.

For starters, the title of the book ends up getting repeated over and over in the text. It's fairly common when writing about new phenomena or new ideas to assign names to them, for purposes of shorthand if nothing else. But no - phrases like "a new kind of science", or "the new kind of science I've discovered", or "the new kind of science described in this book" appear over and over in the first few chapters. This is really hard to read, and gives the impression of really trying to "sell" the idea that there's some kind of radical new idea here, which, 1/4 of the way in, there is so far no sign of.

It's also really hard to read a book where the author seems to be taking personal credit for well-known results in computer science, without so much as a reference to the work other people have done in the area. There are some references in the end-notes, but the main text doesn't seem to make any kind of distinction between what's new, and what's well-known or borrowed. For someone who isn't familiar with the field, it'd be easy to get the impression that Wolfram invented everything here.

I expected that this book would be fascinating. I've been interested in Cellular Automata since the 80's, and some of the things people have been able to do with the Game Of Life, or the Wireworld CA are pretty amazing. So far, though, there's been a lot of build up for the "big discovery", and some fairly rough-shod introduction to CA theory, but I feel like I'm not making much progress towards any kind of goal.

Yesterday, in an attempt to see whether it's just me that's having a problem with this book, I did a search for reviews of the book. The results were not encouraging.

I'd really like to hear from anybody who has made it all the way through this book. In particular, I'd like to know if I should just skip ahead to the grand conclusion, or slog through the rest of the text.

Tuesday, February 03, 2009

Well, I'm getting better...

I updated my Blogger layout to the "new and improved" form of the old layout. I'm not sure how "improved" it is, but I ended up with a hierarchical archive, which makes it really easy to see how many blog posts I've had in any given month or year, over the history of the blog.

As I start my 4th year of blogging, I can see that the trend looks like this:
2005: 3 posts
2006: 12 posts
2007: 14 posts
2008: 25 posts

Last year was the first year that I managed to post at least one blog post a month. That's nowhere near where I thought I wanted to be, but at least I'm getting better at consistently writing. I think the writing has gotten easier for me, as well. I suspect that the quality hasn't gone up much (if at all), but I've effectively trained myself not to edit my posts to death, and I'm no longer taking months to get one paragraph just right for publishing.

So it's a qualified success. Onward and upward!

Saturday, January 24, 2009

This week's iPhone SDK sob story

I have ranted about this before, I know, but I'm a little irritated. Every single time I update the iPhone tools, I run into some crazy issue building code that worked just fine on a previous version.

This week, after digging my office out from under all the mess from moving to a new house, I revisited one of my older projects (yes, Pictems is finally getting an update!). And I ran into not one, but two of these issues. That's not counting the usual Code Signing errors, which I don't even pay attention to - I just click randomly on the Code Signing options until they go away.

(For my friends on the XCode team: Yes, I will file bugs on these issues, once I figure out what's going on. This is not a bug report)

Issue #1: During some early experimentation, I had set the "Navigation Bar Hidden" property on one of my Nib files. It didn't seem to do what I wanted, but I didn't bother to change it back. At some point, a change was made such that it now works. Great, but apparently the change was actually made in one of the iPhone tools, so even if I build my old project, with the SDK set to 2.0, I still get the new behavior. Easy to fix, but it's weird to have to change my "archived" version of my source so it builds correctly with the current version of XCode. If I build my old project against the old SDK, I'd expect to get the old behavior.

Issue #2: One of my resource files has a $ character in the name. One of the XCode copy scripts apparently changed such that it's not escaping the filename correctly, so now the resource doesn't get copied. Amusingly, no error message results - the file just ain't there. Yes, it's dubious to name a file with a $ in the name. But, again, it used to work just fine.

Oh, well. In the bigger scheme of things, I still prefer XCode/iPhone to Eclipse/Android...

Sunday, December 28, 2008

A math problem

Okay, so here's an example of where dropping out of math classes after Differential Equations is coming back to bite me a bit. I'm working on a kind of puzzle, mostly for fun, but possibly to incorporate into a future software product.

At its most basic, the solution process for the puzzle turns out to be solving a system of simultaneous equations. Which is something I learned how to do way back in High School, and for linear equations, I can even find off-the-shelf algorithms and libraries for doing so.

The catch, of course, is that these aren't linear equations. They use modular arithmetic, which is something I understand at a basic level, like anybody who programs for a living probably does, but I don't know where to even start breaking this down to solve a non-trivial version, and Google isn't helping me.

Let's start with a simple linear example:
5x + 7y + 4 = 0
4x + 3y + 1 = 0

Use whatever method you like, and you get:
x = 0.3846
y = -0.846

Piece of cake. Now, what if the equation looks like this?
5x + 7y + 4 = 0 (modulo 16)
4x + 3y + 1 = 0 (modulo 16)

If we want to find a few integer solutions for x and y, how do we find them? I could write a program to just guess every integer between 1 and 1,000,000 for each of the coefficients, and that'd find me a solution, but it doesn't scale well if I have a large number of variables. In the example equations given, there are rather a lot of solutions ([9,9],[9,25],[25,25]...), but I suspect that some other (carefully chosen?) sets of coefficients would have a much smaller set of solutions. Actually, that's kind of the point of the whole exercise.

Anyone out there got some hints for me?
Googling "simultaneous modular equations" got me:
http://en.wikibooks.org/wiki/Discrete_mathematics/Modular_arithmetic#Simultaneous_equations
and
http://www.nada.kth.se/~johanh/rsalowexponent.ps
,both of which are interesting, but not quite what I'm looking for.

For the case where the modulus is 2, addition is equivalent to XOR, and so logic minimization techniques from EE can be used, but it's not clear to me how to move those up to work in a higher modulus.

Thursday, November 13, 2008

Synchronicity...

A couple of posts ago, I said:
Hopefully backsliding on the Java thing doesn't mean I'm about to backslide
on the WoW thing - I can't afford the lost time. I've got to learn about how you
do things in Java again.

Today, I got an email from Blizzard, makers of World of Warcraft:
Mark,
You've been summoned back to Azeroth! Your World of Warcraft®
account has been selected to receive 10 FREE days of game time and a FREE trial of The Burning Crusade® expansion pack.


Weird timing. On the other hand, 10 free days can't hurt, right? right?

Tuesday, November 11, 2008

Just In Time compilation vs. the desktop and embedded worlds

Okay, rant mode on. As I was waiting for Eclipse to launch again today, it occured to me that one of the enduring mysteries of Java (and C#/.NET) for me is the continued dominance of just-in-time compilation as a runtime strategy for these languages, wherever they're found. We've all read the articles that claim that Java is "nearly as fast as C++", we also all know that that's a bunch of hooey, particularly with regard to startup time. Of course, if Eclipse wasn't periodically crashing on me with out-of-memory errors, then I'd care less about the startup time - but that's another rant. Back to startup time and JIT compilation...

If you're creating a server-based application, the overhead of the JIT compiler is probably pretty nominal - the first time through the code, it's a little pokey, but after that, it's plenty fast, and you're likely throttled by network I/O or database performance, anyway. And in theory, the JIT compiler can make code that's optimal for your particular hardware, though in practice, device-specific optimizations are pretty minimal.

On the other hand, if you're writing a desktop application (or worse yet, a piece of embedded firmware), then startup time, and first-time through performance, matters. In many cases, it matters rather a lot.

There are a number of advantages to writing code in a "managed", garbage-collected language, especially for desktop applications - memory leaks are much reduced, you eliminate buffer overflows, and there is the whole Java standard library full of useful code that you don't have to write for yourself. I'm willing to put up with many of the disadvantages of Java to gain the productivity and safety advantages. But waiting for the Java interpreter to recompile the same application over and over offends me on some basic level.

On a recent project, we used every trick in the book to speed up our startup time, including a "faked" startup splash screen, lazy initialization of everything we could get away with, etc, etc. Despite all that effort (and unecessary complication in the code base), startup time was still one of the most common complaints from users.

Quite a bit of profiling was done, and in our case, much of the startup time was taken up deep inside the JIT, where there was little we could do about it. Why oh why doesn't anybody make a Java (or .NET) implementation that keeps the safe runtime behavior, and implements a simple all-at-once compilation to high-performance native code? Maybe somebody does, but I haven't heard of them.

For that matter, why don't the reference implementations of these language runtimes just save all that carefully-compiled native code so they can skip all that effort the next time? The .NET framework even has a global cache for shared assemblies. Why those, at least, aren't pre-compiled during installation, I can't even imagine.

Update:
I was helpfully reminded of NGen, which will pre-compile .NET assemblies to native code. I had forgotten about that, since so much of my most recent C# work was hosted on Mono, which does things a bit differently. Mono has an option for AOT (ahead of time) compilation, which works, sort of, but could easily be the subject of another long article.

Tuesday, November 04, 2008

Vote.

It's election day today in America. THis is just a quick reminder for all my friends out there to get out and vote.

Vote.
  • Even if "your guy" isn't going to win.
  • Even if some irresponsible news organization announces "winners" for your state, before the polls are even closed.
  • Even if "the election has already been decided" before your state's polls close.

There's a lot more going on than just elections for the Federal Government. Whether you're pro-growth or pro-environment, whether you want to support gigantic infrastructure programs in a time of depression, or if you just want to reduce the cost of parking at the airport, ensure that your voice is heard.

Sunday, October 19, 2008

Returning to Java, after 10 years away


I'm once again writing Java code professionally, something that I haven't done in nearly 10 years (no, really - I had to stop and think it through because I didn't believe it, either). A couple of thoughts did occur to me, after I'd figured out the time frames involved.

I was a little taken aback by the very idea that Java is more than 10 years old. It just seems weird that a new programming language could go from introduction to being a major part of the world's IT infrastructure and college curriculums, in less time than I've been living here in California.

Java sure has evolved a lot in the last 10 years. There have been major changes to the language, the libraries, and the tools. I'd bet that some of my 10-year old Java code would throw deprecation warnings for nearly every line of code...

On the other hand, my final thought is along the lines of "Oh, my god. So much has changed, but Java is still irritating in nearly all the ways that made me crazy ten years ago! What have these people been up to for the last decade?"

Oh, and I was the first person I knew to "quit" Java, much like I was the first person to "quit" World of Warcraft. Hopefully backsliding on the Java thing doesn't mean I'm about to backslide on the WoW thing - I can't afford the lost time. I've got to learn about how you do things in Java again.

One good thing for my loyal readers (if any exist) is that I have a bunch of stored-up vitriol about Java that I can just uncork and pour out, so I should be updating more frequently.

Sunday, September 28, 2008

So, what's it good for? (XO Laptop, part 3)

(I wrote this quite a while back, but was never really happy with how it turned out. Here it is, nevertheless)

See also Part 1 and Part 2 

Okay, so I've had a chance to play with the XO some more, and I've been thinking about how it might be useful for school kids in the developing world. You can read more about the project and their official justifications for it at the OLPC web site.

But as a computer geek, and an early adopter of the personal computer in my own country (the USA), I thought it might be interesting to look at it from the perspective of my own experience.

History

I first encountered Personal Computers some time in the mid-to-late 1970's, when they started appearing, in small numbers, in schools, at my friends' houses, and in stores. The first time I sat down at a computer and typed in a BASIC program, I was totally hooked. I experiemented with computers at other kid's houses, played with the systems on display at local stores, and even stayed after school and took summer classes at the local community college to get access to computers.

For the next few Christmases and birthdays, when my parents asked me what I wanted, I only had one answer: "I want a computer!". Unfortunately, it wasn't until about 1982/3 when my parents could scrape together the nearly unimaginable sum of $500 or so to buy me my first computer - a Texas Instruments 99/4a. I loved that thing to death, and it was a major part of my life for several years. I would have been ecstatic if someone had come to me at age 9 or so and said "here is a computer of your very own, to use at school, and to take home with you at night".

I got my first computer-related job my Junior year in High School. In theory, I was hired to do simple assembly and software loading on PCs, but I very rapidly got into more and more programming on a regular basis. You could fairly say that I wouldn't be where I am today without that early access to computer technology.

I went to my 20-year High School reunion recently, and one of the things that struck me was the number of folks who were working in more-or-less high-tech fields, particularly computer software. For a bunch of middle-class midwestern folks, we did really well riding the tech wave. I think that having computers in our schools (and a mandatory computer literacy class in high school) was a major factor there.

Okay, back on track...

So, having access to computers at an early age changed my life, and led to me to a highly-paid job in the technology industry. So what? That's probably not a reasonable goal for a poor kid in South America or Africa, there being no reasonable local high-tech industry for them to move into when they grow up (yet).

But, as the OLPC folks put it, "this is an education project, not a laptop project". So it's not (just) about providing computer literacy, but improving the educational process overall.

One example of this is textbooks - textbooks are surprisingly expensive, and as a result, aren't readily available, or frequently updated, in developing countries. If every child has their laptop, then textbooks can be stored on them, greatly reducing year-to year costs, allowing for more frequent updates, and freeing the students from carting a heavy load of books to and from school.

Or take language instruction - if you live in a developing country, one of the best things you can do to improve your chances at a better career is to learn a major language of commerce - English, Japanese, Chinese, Arabic, or whatever. But if there aren't any native English speakers in your village, who are you going to learn from? It'd be *really* easy to write a basic English primer to run on the OLPC, complete with video of a native English speaker demonstrating pronunciation.

Other features of the laptop are especially geared towards communication. In addition to the ability to access the internet, every laptop has an integrated video camera. In addition to giving the kids another device to experiment with, the teachers can use it to "send a note home" with the child, even if the child's parents are illiterate.

But, aren't there better places to spend the money? Don't these people need food and medicine first?

Yes, that's a common criticism - what's the point of giving children laptops, if they're dying of malnutrition, dysentery, malaria, and AIDS?

First, not everybody in the developing world is starving

In fact, there's no good reason for anybody to go without food, given the surpluses in the USA and elsewhere. If someone is starving out there, it's a political problem (i.e. someone in power doesn't care enough about them to feed them).

Second, who's to say we can't do both?

There are already lots of charities working on addressing basic human needs. The Gates Foundation is working to improve the health and basic welfare of children and adults all over the world. They're vaccinating children, helping small businesspeople bootstrap local economies, etc, etc. Meanwhile, the World Health Organization and UNICEF are doing their part as well. As an exclusively education-focused initiative, OLPC can provide services that aren't being covered by other agencies.

Knowledge is power
Finally, you can easily make the argument that a lot of the problems in the developing world are actually educational problems at the root. One reason that AIDS infection rates are so high in Africa is because of lack of education about the causes of AIDS and how to avoid becoming infected.

Similarly, rampant governmental corruption is not inevitable, but if you don't actually know that things don't work that way elsewhere in the world, how are you ever going to start down the road of cleaning it up?

I'd like to think that hundreds of thousands of schoolchildren running around with laptops that can function as digital camcorders would help bridge the gap of understanding between the folks in the developing world, and us in the "developed" world.

In conclusion
I think that despite the much-publicized management problems with the OLPC project, it's an interesting approach that I hope will have a positive effect on the children that participate. Even if the program as a whole doesn't quite work out as planned, hopefully we'll all learn something from it about how to "do it right" the next time.