Yet another infrequently-updated blog, this one about the daily excitement of working in the software industry.
Sunday, December 28, 2008
A math problem
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...
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
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.
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.
Sunday, September 28, 2008
So, what's it good for? (XO Laptop, part 3)
Thursday, August 28, 2008
Cleaning out the backlog...
It occurs to me that writing a long blog post, then saving it as a draft, and sitting on it for months, occasionally tweaking the wording, then putting it back on the drafts pile to languish is exactly the kind of behavior I was trying to wean myself off of when I started this blog.
So, I'm going to go back through the "drafts" folder and either publish or delete everything in it over the next week or so. So, y'all can look forward to lots of sentence fragments and unfinished thoughts over the next few days.
Team Building: cautionary tales
What I've learned over the last 20 years or so is that your team either gets along on a day to day basis, or they don't. If management keeps the more dysfunctional members of the group in line, and encourages working together, rather than finger pointing, you've probably already got as coherent a team as you're likely to get, and having them all go go-carting together isn't going to matter.
On the other hand, if the management plays favorites, or allows bullying to go unchecked, or actually engages in a bit of anti-social behavior themselves, no amount of pot-luck parties are going to change that.
Having said all that, here are some of my experiences:
Always remember rule #1: If the activity is competitive, do not divide your larger team up according to their everyday organizational structure - e.g. Marketing vs. Engineering, for example. Do it however you have to (alphebetical by last name?) to make sure that the distribution is essentially random. Inter-group rivalry is exactly what you're trying to eliminate, or should be, anyway.
Athletic Competition: One former employer had a yearly multi-event athletic competition (mostly "fun" events, like a sack race, or water-balloon toss). Any group of interested employees could form a team, and t-shirts were printed up for the event, and medals given out. As you might well imagine, given that this is an Engineering-heavy organization, injuries were fairly common. Over the years, they gradually rotated out the most physically-stressful events, but I think at least one person still gets injured every year - I had a nerve in my hand crushed during the Tug-of-War one year, for example.
The hyper-competitive types still worry way too much about doing well, sometimes dragging other folks into their sphere of influence (I mean really, what kind of person organizes drills for a Pictionary competition?). But overall, it works well, because everybody knows it's just for fun. Since teams are formed on an ad-hoc basis, it has very little of the "you are now part of a team, go be excellent together" aspect of other team-building exercises. Generally, managers don't force their "best" employees to form a team with them, for example.
Okay, so we can't all work at a company that's willing to throw huge amounts of money and time at something like that. Here's some other experiences I've had:
Laser Tag: I have done this a few times, with different teams. There is a bit of a tendency for the more blood-thirsty team members to enjoy themselves a little too much, but at least the chances of physical injury are minimal. The poor losers will whine that "my gun didn't work", or "I totally shot you first", but the rest of us are used to that (they do it at work every day), so it won't be a problem.
Most LT arenas can be set up to report only the aggregate team score, which helps the whole team feel like they're working together (which is the whole point, after all), and cuts down on whining. I highly recommend not getting individual stats for each player - those of us who suck at the game, or just aren't as into it, don't need a reminder of how poorly we did.
Movies: This can be fun, and usually goes over pretty well, but there's relatively little interaction between team members at a movie. Also, consider that some folks aren't going to want to go to any particular movie you might choose, so have a plan for them to have some fun at the company's expense, too.
One thing you can do to make this more of an interactive experience is to combine the movie with a pre-or-post get-together (catered lunch, maybe?) where people can get together and mingle casually - maybe even discuss the movie together. Many movie theater chains have an "events person" to help arrange this stuff.
If you really want to get the biggest bang for the buck, talk to your local theater about renting out an entire theater for your team (if you're large enough), and have the employees choose which movie they want to see, by voting. Or surprise everybody by renting out a theater for the big summer blockbuster movie on opening day.
Pot-luck lunches: You'd better combine this with something else, or you're in trouble. Some of us really like cooking for a group, but for a lot of employees, this just seems like the company trying to cheap out. At the very least, combine the pot-luck with a 1/2 day, or do it for Halloween and combine it with a costume contest, or something. See also: Picnic in the Park, below.
Miniature Golf: This was a surprising (to me, anyway) success. I figured that all the little cliques would go off and do their thing, but we actually had a pretty good mixing thing going on. We played for fun, rather than running some kind of a tournament structure, which probably helped. It's low-impact, so people can chat, and in general, few team memebers are invested enough to get over-competitive.
Bowling: You might want to try to figure out ahead of time if any of the team members are "serious" bowlers - they might not enjoy playing with a bunch of losers who bowl in the low '60s. But in general, this can work out great - bowling is a "do stuff, then wait" kind of activity, so there will be socialization between rounds. Beer helps with that aspect as well, of course.
Picnic in the Park / Beach day: You're probably located not very far from a nice park of some sort. Take all the employees out for the day, and feed them barbeque, or (if budgets are tight) have them pot-luck it, making sure that the basics are covered, using a sign-up sheet. Make sure frisbees and other fun toys are available, and make sure you have some shade. For extra points, make it an "employees and their families" event.
Amusement Park: Yeah, everybody will be really excited about this, but you likely won't see anybody after the initial arrival, unless you have a very large group, or a very small park. You can plan to have lunch together at one of the "group areas", and that'll get everyone in the same place for a while, but as a team-building experience, it's low on interaction.
So, that's my experience, what's yours? I'm particularly keen to hear from folks that have done more strenuous team-building activities, like the ropes course, or paintball...
Wednesday, August 13, 2008
Julia Child, International Super-spy
By BRETT J. BLACKLEDGE and RANDY HERSCHAFT, Associated Press Writers
24 minutes ago
WASHINGTON - Famed chef Julia Child shared a secret with Supreme Court Justice Arthur Goldberg and Chicago White Sox catcher Moe Berg at a time when the Nazis threatened the world. They served in an international spy ring managed by the Office of Strategic Services, an early version of the CIA created in World War II by President Franklin Roosevelt.
Apparently the CIA is finishing up the transfer of old OSS documents to the National Archives, and the list of OSS employees was one of the most recent things to get approved for declassification.
The article on Yahoo! News has a link to this page, a CIA page describing the history and activities of the OSS during World War II.
Sunday, August 03, 2008
Pictems, three weeks in

Friday, July 11, 2008
Pictems!
Pictems is now available!
Hey, so my first iPhone application is currently available on the iPhone App Store. It's been a tremendous amount of work to get to this point, but now it's out, and I can step back a little and take a deep breath and think about what was good, what was bad, and what I would do differently next time.
We even have a website set up!
So, what is it?
The name "Pictems" is a conflation of "Pictures" and "items". Pictems is a simple application that lets you take the pictures from the photo library on your iPhone or iPod touch, add a variety of fun embellishments to them, and save them to send them to your friends and family.
Monday, June 16, 2008
The Problem with Magic...
Hint to API implementers. Saying: "I loaded your file, but **** isn't set correctly" is not at all the same thing as "I tried to load your file, but I couldn't find it, and therefore **** couldn't be set up". Finding a typo in a textfield in Interface Builder by starting from scratch and re-building the whole interface kind of eats into the productivity advantage of using IB in the first place.
Oh, well. At least I didn't have to burn one of my tech support incidents to have someone point out a typo for me. That would have been really infuriating.
Friday, June 13, 2008
What a week...
Five days, 21 sessions (not including the keynote), and 12 rides on Caltrain up to San Francisco and back. My head is spinning, but my first two iPhone applications are installing and running.
I think I'm ready to go back to work and take it easy for a while. Unfortunately, I think my boss has other ideas...
Friday, June 06, 2008
WWDC 2008

I'm really excited to be going to WWDC this year, for the first time as an attendee. WWDC is Apple's Worldwide Developer Conference, which is 5 solid days of technical education and on all things related to Mac and iPhone development.
The only other times I've gone to WWDC, it was as an Apple employee, and I spent my time there helping customers with their issues. Not that that wasn't fun - it was probably the most enjoyable part of my time at Apple. But I am looking forward to sponging up mass quantities of information, and asking my former co-workers stupid questions :-)
I know a lot of the Mac enthusiast and rumor-tracking sites are wildly speculating on what new Apple products might or might not be announced at WWDC. I'm only vaguely interested in any possible hardware announcements. I think the most important announcement form Apple in the last 10 years was the introduction of the iPhone - not because the hardware was so special, but because they built it on OS X, and released an SDK relatively soon thereafter.
Hardware is interesting, but it tends to follow a fairly predictable pattern. This year's Macs will be some combination of faster, lighter, and thinner, and there will inevitably be iPhones with more storage, faster network connectivity, and more features.
More interesting to me is that Apple has really started to embrace having a single platform that supports multiple kinds of products. I wrote a whole blog post on that subject a while back, but the fact that Apple can now get a microprocessor for $10 or so that'll run OS X means that they can aggressively move into whatever new kinds of products they want, based on variations of the new iPhone platform. It's an exciting time to be a developer for Apple's platform.
For those of you who'll also be there, keep an eye out for me - I'll be haunting the iPhone sessions, and working furiously to finish up a couple of projects I've been working on, now that I can actually test and debug them on iPhone hardware (my developer certificate arrived just in time for WWDC).
Wednesday, May 28, 2008
Why you should visit the Computer History Museum sooner, rather than later

If you live in Silicon Valley, you've probably at least heard of the Computer History Museum. If you're like me, you probably even planned on going "one of these days". There's a very good reason to schedule that visit sometime in the next 10 months or so, though.
A full-scale working model of Charles Babbage's Difference Engine Number Two is currently on display at the CHM until May of 2009. There is only one other like it in the world, at the Science Museum in London, UK.
It's one of the most beautiful pieces of machinery I've ever seen, as well as marking a significant milestone in the evolution of computers. We went down for the exhibit's opening, and actually got to see the machine in operation. I gather that they're not running it all the time on regular days - that's a pity, but seeing as it cost millions of dollars to make, and they're merely borrowing it, I guess I understand that.
It's almost hypnotic to watch, with the carry mechanism rippling up the columns of digits, and hundreds of pounds of brass and steel moving up and down for each step of the calculation.
In addition (ha, ha!) to the Difference Engine, the museum has a large number of other historic computer systems on display, including a Connection Machine, several Cray super computers, and pieces of the SAGE system. Walking through their "Visible Storage" area, a loosely-organized subset of the museum's collection, was fascinating. There's everything from abacuses to supercomputers in there, along with various bits of esoterica that the younger generation wouldn't have seen or even heard of before - drum memory, magnetic cores, etc, etc.
All in all, well worth a visit. The museum is definitely a work in progress, but admission is free, and there's nothing quite like it anywhere else. They also have a regular lunch lecture series, starting up again soon, with discussions of various people and machines in computing history. Since I work right down the street from the museum, I'm planning to try to attend events at the museum more often.
Tuesday, May 06, 2008
The intermediate approach...
Well, you might have heard that Microsoft (with some assistance from the academic community and hardware vendors) is working on their own solution to the "multicore dilemma". Unsurprisingly, they're not recommending that everybody throw away their imperative C++ and C# code, and adopt an entirely new programming paradigm, like functional programming. Instead, they're implementing a series of tools that make it much easier to get a lot of the benefit of multiple processors, without having to learn a new way of thinking.
Late last year, the first fruits of this work became available. The "Parallel Extensions to .NET" (or Parallel FX) are available from Microsoft as a free download, as a Community Technology Preview (basically, an open Beta). You can read much more about it at Microsoft's website here. There's a great MSDN Magazine article that hits the high points, as well.
One key point in their design is the realization that anonymous functions (they call them anonymous delegates, but that's just jargon) provide a simple way to package up a "unit of work" to pass off to another processor. This is nothing new to the functional programmers out there, I know. But for folks who are firmly rooted in the C/C++ tradition, learning that they can replace:
for (int i = 0; i < 100; i++) {
a[i] = a[i]*a[i];
}
with
Parallel.For(0, 100, delegate(int i) {
a[i] = a[i]*a[i];
});
and get a massive speedup on multi-core machines, is likely to be something of a revelation. Parallel FX does some fun stuff under the hood with all those delegate invocations, as well, enabling better work sharing - see the MSDN article for details. I thought this was an interesting hybrid approach, rather than the "all or nothing" approach to addressing concurrency.
For those that are already familiar with OpenMP, it's a somewhat similar model, in many ways. The additional abstraction provided by having an anonymous function does simplify the simple cases, though - the arguments to the function are "private", and everything else is "shared", basically.
One of these weekends, I'll have to take a deeper look into Parallel FX. I did find it fascinating that a single language feature (anonymous delegates) can be leveraged to do so much, though.
Wednesday, April 09, 2008
Tolkien is probably rolling in his grave
The Friends List Of The Ring
edit 2008/05/06: The original link is gone. Here's a YouTube link.
Wednesday, March 19, 2008
Most surpising headline of the year
Unfortunately this turns out to be bad reporting...
Tuesday, March 18, 2008
Is it my imagination?
Am I mis-remembering, or did Internet Explorer formerly produce more helpful error messages than this one when failing to connect to a website? Is this another IE7 "feature"? Why would you display the exact same error message for no network connectivity, a DNS failure, and a site that doesn't respond?
Given that it's trivially easy to distinguish each of these three from the other cases, why not at least tell me which is actually the problem?
Grr.
Wednesday, March 12, 2008
L. U. A. That spells Moon!
As I mentioned previously, I've been working with Lua recently. I'm really enjoying it. I'd place Lua somewhere slightly to the right of Tcl on my Programming Language Complexity Chart, which probably explains why I found it so immediately appealing.
There are many kinds of simplicity. I think that one of Lua's strong points is that it tries to get the most possible mileage out of each language feature. For example: Lua is dynamically typed, meaning that values have a type, but any variable can hold a value of any type. Lua defines the following value types:
- number
- string
- boolean
- nil
- function
- table
- thread
- userdata
For purposes of this discussion, we're going to ignore the userdata type, since that's mostly used when dealing with opaque data from the "host" program (Lua being designed to be used as an embeddable interpreter).
Now, this is obviously more types than some other scripting languages, but it's still a fairly short list. Most of the types are fairly self-explanatory - number represents a numeric value, strings are used for text, booleans are used for true and false, nil is the value of an uninitialized variable, and function represents a function.
Tables are an interesting case. Tables are Lua's implementation of the Associative Array, everybody's (or at least my) favorite universal data structure. Once you've got a data structure that can index arbitrary values with arbitrary keys, you can use it for all sorts of things - and Lua does. As the book Programming in Lua puts it:
Tables in Lua are not a data structure; they are the data structure.
Tables are used to implement records, arrays, Object-Oriented Programming features, namespaces (the package system), and a variety of other features. Even global variables are implemented as entries in a table.
One extremely powerful feature of Lua is metatables, which are tables that affect the behavior of other tables. Every table can have a metatable attached to it, which controls the behavior of the table when certain operations are perfomed on it. This is conceptually similar to operator overloading in C++, but again just implemented as a series of entries in a table.
People have implemented both class-based and prototype-based OOP systems for Lua using just a few relatively simple functions that manipulate tables and metatables. That's a pretty good example of the power that's available.