Showing posts with label computers. Show all posts
Showing posts with label computers. Show all posts

Wednesday, September 08, 2010

Desktop specs for the entry level programmer

A friend recently asked for advice. His son is looking to become a professional computer programmer and wants specs for a new desktop computer. I'm no longer up to date on the subject, but that didn't stop me from writing a 900-word opinion on the matter, which I present to you know.

---

This is a tough question to answer in a specific sort of way, made more difficult since I hardly buy desktops anymore. You can get an idea for basic specs by looking at any development IDE package (e.g. Visual Studio.) Here are some overall suggestions, though:

Important items: CPU, Memory, 7200RPM disk (as opposed to 5400 RPM), expandability
Less important items: Video card, audio card, USB ports, Firewire, hard disk quantity.

CPU +

CPU is important, not necessarily because of clock speed, which has recently been topping out, but because of the "number of cores" or "number or processors". Cores and processors aren't the same thing, but for the sake of this conversation let's say they are. More processors means more things the computer do at the same time. This can sometimes be valuable when you're writing software. But don't let yourself get carried away, particularly with a starting computer. If there's only one processor, I'm sure your son will do fine.

Memory +

This is pretty important, particularly as you deal with larger pieces of software. Developer tools can take up lots of memory, it's certainly possible. That depends on how large the products are that your son plans to write. But don't let 'budding professional programmer' get in the way here. I think getting memory is good. And you don't need to max it out now. Memory always gets cheaper (In the as houses always increase in value, well, not really, the takeaway from that is I really mean "mostly always" instead of "always")

Disks +

Disk: Disks are cheap. I mean, wow I can't believe how cheap they get. Unless your son is planning on processing lots of video (in which case a better video card might be necessary, but only might.)  When it comes to disks, though, performance can matter a great deal. Think about how long it takes to load Microsoft Word, for instance. You could think about it for a looooong time. Disk drives operate like platters, which is why they're measured in RPM, just like LP records, but instead of 33 1/3, 45, 78 RPM, we're looking at 5400 and 7200 RPM. So drives that spin at 7200 RPM spin 33% faster than those that spin at 5400 RPM. That's useful.

Most desktop PCs will support 7200 RPM disks, shouldn't be a problem.

Expandability +


I hesitate to put this on the list, because sometimes you find that the idea of expandability is nice, but in reality, by the time you expand anything more than memory, you're out of room, and you need a new motherboard to keep up with new operating systems anyway. But at the same time, I've always appreciated the ability to make room for a second disk somewhere.

Video card -

High quality video cards are good for playing games, or writing games, writing complex graphics software (memory and more CPUs help here as well.) Even then, I'm sure you'll do fine for an entry level computer with almost any video card they give. I'd probably do some research personally on video card technology to supplement it, but honestly, he can do fine with almost any entry level video card.

Audio -

Take the standard, get something better if he's specializing in audio, which means games or music.

Ports, Firewire -

Most of that is expandable and can be after market purchases.

Disk Capacity -

Not critical for getting started. Nowadays, hard disk quantity is usually taken up my media files such as video and audio. If the upgrade for more hard disk space is small, then, sure, go for it, but don't stress about it.

---

And even after all of this, more questions linger: memory is more than just "How Many Gee Bees?" One computer advertises its memory as "8GB Dual Channel DDR3 SDRAM3at 1333MHz - 4 DIMMs." Which of that matters and why? Whooooo, I'm getting woozy just thinking about it. (Hint: a DIMM is what you might call a single memory "chip", the thing you stick into the computer. If the computer supports up to 4 slots, then 8GB taking up 4 DIMMs (at 2GB apiece) means you can't upgrade, well, at least, not without pulling out one of the 2GB DIMMs. But an 8GB DIMM taking up a single slot means you can add much more memory. But watch out: 1 8GB DIMM is more expensive than 4 2GB DIMMs, sometimes much more expensive.)

Of course, this is vanilla advice for programming. Your son may be interested in hard core video games, in which case you need much better graphics capabilities, and even more memory. Or just playing games, which requires less so, but still. And while I didn't give a concrete number, splurge on 8GB of memory, with room to expand. If you find yourself spending close to $1K you ... well I spend $3K on my last machine, but $1K for a starting development machine is probably more than enough. As a reference point, the Dell Studio XPS 8100 is a decent starting point.

So, that's my advice. It's all over the place, lacks a reference to current standards, yet somehow has the gall to pass itself off as authoritative. You should do fine.

Tuesday, August 03, 2010

Back from the dead-tris

Short version

I found copies of the two lost Tetris clones that I wrote in 1990 and 1991. [download] Now it's time to reminisce.

Long Version

In 1990 I was a college Junior. For extra money I worked as a student consultant in the computer center. The consultant's office had two computers, a DEC VT220 and an IBM PC AT. We put a couple of games on the PC. My two favorites were Level 42, which I can no longer find, and a Tetris clone called Nyet. In fact, everyone in the office loved Nyet, and we all played for hours on end.

I was the fourth best Nyet player among the consultants. I know this because three people always inhabited the top ten high-score list, and I fought hard to get my spot on it. Occasionally I would manage to wrangle my way to the number seven spot, only long enough to brag about it before the other three would attain new high scores effectively pushing me off the list.

By Spring Break of 1990, I was tired of being unable to gain a solid foothold in the top-ten spot, so I did the only thing I could think of, I wrote my own Tetris clone. Armed with Turbo Pascal and a quiet week on campus, I wrote The Soviet Block. I added an extended block set, and some other nice features, making it sufficiently attractive to play.


Surely, if it was my own version of Tetris, I should have a spot in the top-ten, right?

Wrong, of course. The same three people dominated the top ten spot. So I wrote another one.

Every good game needs a sequel

But this one was going to be a competitive two-player version. This sounds like old hat, but in 1990 there was no such thing as a competitive two-player version of Tetris. I envisioned it as a game of tug-o-war, where players faced off on opposite sides of the board. Bricks didn't move down, but toward the center. By clearing blocks you would actually shift the whole board toward your opponent. You win when your opponent loses the game, but more interesting is when you shift the board far enough into your opponent's space that it reaches a goal line, which ends the round.

The game board has almost shifted entirely to the end-of-round markers on the left.

Buying game features for the next round.
By ending the round, you could use "dollars" accumulated by doing things like clear multiple rows simultaneously to buy features. For instance, you could slow the rate your pieces fall to the center for $3, but for $4 you do the opposite to your opponent. From there you start again with an empty board, pieces move slightly faster, and you need to clear more rows before being able to shift the playing area.

One of the interesting facets of this game was that once you started losing, you kept losing. It was tough to recover from being slightly behind. On the other hand, if the opponents were well matched, they were in for an exciting fight for survival during the tug-o-war, where both sides tried to lay bricks as quickly as possible without making a serious round-ending blunder, or worse, a game-ending one.

Here's a brief demonstration of Head-to-Head-tris in action.



I brought Head-to-Head-tris to the consultant's office, and, after long last, nobody could beat me! Only one person gave me a run for their money, and it had the desired exciting feeling of a back-and-forth tug-o-war. We were well matched.

I'm pretty proud of Head-to-Head-tris. It's a fairly playable game.

By May of 1991 I graduated, and moved on. As the years went on I lost my copy of The Soviet Block and Head-to-Head-tris, source code and all, until some time last  year, when I found it sitting somewhere on the net. The source code is still gone, but now you can play the lost DOS classic of the 1990's.

To play

Start by downloading the DOS binaries and doc files.

On the Mac I use the DOSBox emulator.

Soviet Block is kind of tough to play nowdays, because I wrote it to work with a specific subset of processor speeds. You know, like, 4.77 MHz, but Head-to-Head-tris uses a processor-speed-free mechanism for its timing mechanism.

You're also likely to need to reset the keys, and remember to turn off the music. It's fun after the first game, after that, it is not.

Head-to-Head-tris is understandably more fun with another competitor, but you can play it alone. After all, that's how I tested it. Better still, let's meet in meatspace and play together.

Saturday, April 17, 2010

Seven on Seven

I had an opportunity to attend Seven on Seven, an event at the New Museum. The idea: pair up seven groups of one artist and one technologist. They were given twelve hours or so to create a project, and today they presented their findings. Each group was given 20 minutes to present with 10 minutes for questions.

The projects were as varied as they were fascinating. They were all in various levels of completion and success: some only managed to compete a full day of research, and some managed to complete a full project. Every project left me with things to think about, and some 

Here are short (and completely unfair) descriptions of the projects, just to give you a taste of the variety:
  • An umbrella with identity; it communicates and broadcasts its locations, images and audio at all times. Take it, leave it, it passes on to someone else.
    • The best part about this project was talking with the team afterwards. I spoke with them about a project I plan to take on this summer, and they gave me great ideas.
  • A new feature on Wordpress: Fun Mode.
    • Man, one of these days I should move to Wordpress, though not necessarily just because of Fun Mode.
  • A mechanical device that only changes when nobody sees it: this might have been my favorite because they actually dared to build something physical.
  • A proposal for allowing users to swap identities on Twitter. This was simultaneously wonderful and utterly preposterous.
    • The first half of the presentation I kept thinking about the film Bubba Ho-Tep: if only Elvis did this instead! The second half of the presentation I thought about my "The Real Mark Jackman" project, which was all about assuming my friend's identity on the web.
  • A video immersion project based on two key constraints: ten second clips identified by three labels only.
    • The two collaborators commented on how much they enjoyed working together and that they planned to keep building on this project.
  • A marketplace for guilt and absolution.
    • Nothing particularly concrete came from this, save a fascinating collection of data using Amazon's Mechanical Turk.
    • Best comment of the day referring to how easy it was to get information out of the Mechanical Turk: "People bared their souls for two cents."
  • An analysis of mental health that was, to be honest, a little difficult to follow. But they shared some of their research which was well-presented.
Congratulations once again to the presenters.

Thursday, April 08, 2010

Thought Experiment: First Response

Give the answer that first comes to mind:

Someone says to you: "I want your opinion. I hate the way [some computer language] handles [some problem] and I wrote a really ugly hack to get around it."

What's your first reaction?

a) You want to help the person solve his problem
b) You want to know the hack

Sunday, March 14, 2010

The Fourth Annual Computer Competition (Part 4 of 4)

(Introduction and Part 1, Part 2, Part 3, Part 4)

The fourth question, Question #5.

Question #5: Senior Division

Compact Disks (CD's) offer the latest advantages in digital sound. Each disk is capable of prividing almost 75 minutes of music. You are currently creating a catalog of your disks (on your computer, naturally) that will list the total time (in hours:minutes:seconds) fro each CD. Unfortunately, while most disk labels list the time for each selection, many do not list the total time for the complete album (although must CD players display this information when you first insert the disk prior to playing it.)

Write a program that (a) asks for the number of selections on the disk (b) asks for the time of each selection in the exact format [minutes:seconds] -- including the colon and (c) outputs the total time of the CD in the format [HH:MM:SS] (Hours:Minutes:Seconds). NOTE: 00:63:29 would be wrong. 01:03:29 would be correct,etc,

IMPORTANT INFORMATION: You may assume that no selection is over 59 minutes and 59 seconds long [59:59] and that the judge will input the data with no spaces between the numbers and the colon. However, the judge may or may not input the minute information with a leading zero. For example, your program should be able to handle 2 minutes and 12 seconds input by the judge either in the form 2:12 or 02:12. Finally your output must be in the format HH:MM:SS or it will not be judged correct. That is, there must be two digits for each position (hours, minutes and seconds) and the output must not have any spaces between the digits and the colons. Some example include (see the SAMPLE RUNS for others):

Correct:Incorrect:Correct:Incorrect:
00:07:3300:7:3302:13:1202 : 13 : 12

SAMPLE RUNS
RUN

HOW MANY SELECTIONS ON THE DISK? 5

TIME FOR SELECTION # 1 (MINUTES:SECONDS)? 29:45
TIME FOR SELECTION # 2 (MINUTES:SECONDS)? 13:32
TIME FOR SELECTION # 3 (MINUTES:SECONDS)? 9:12
TIME FOR SELECTION # 4 (MINUTES:SECONDS)? 02:12
TIME FOR SELECTION # 5 (MINUTES:SECONDS)? 12:52

TOTAL TIME OF DISK = 01:07:33

RUN

HOW MANY SELECTIONS ON THE DISK? 3

TIME FOR SELECTION # 1 (MINUTES:SECONDS)? 4:59
TIME FOR SELECTION # 2 (MINUTES:SECONDS)? 26:26
TIME FOR SELECTION # 3 (MINUTES:SECONDS)? 01:09

TOTAL TIME OF DISK = 00:32:34




The Fourth Annual Computer Competition (Part 3 of 4)

(Introduction and Part 1, Part 2, Part 3, Part 4)
The third question, Question #4.

Question #4: Senior Division

The integers 12, 21, 13 and 31 have the following characteristic:
12 times 12 = 144 and 21 times 21 = 441
13 times 13 = 169 and 31 times 31 = 961
Write a program that identifies all 3-digit integers (if any) between 100 and 400 for which this same kind of relationship holds. (That is, a 3-digit number whose square and the square of its "reverse" are mirror images.)

Important notes:

The number and its "reverse" must:
(a) both be true 3-digit numbers
(b) not be identical.
Examples: the following integers (among others) do not qualify:
100 (because its reverse integer is 1)
120 (because its reverse integer is 21)
121 (because its reverse integer is identical)

SAMPLE RUN
NOTE:

When your program is RUN by the judge it should list all the integers between 100 and 400 that qualify or state that no integers qualify, if that is the case.

The Fourth Annual Computer Competition (Part 2 of 4)

(Introduction and Part 1, Part 2, Part 3, Part 4)

Question #3: Senior Division

Write a program that accepts a sentence for input and outputs the sentence with the letters in each word arranged in alphabetical order, and the words in order of length. Words must still be separated by spaces. If two rearranged words are of equal length they are to be placed in alphabetical order of the output "sentence".

NOTE: The judge will input only upper-case letters and will terminate the sentence with a period. This will be the only punctuation in the sentence and must remain at the end of the output sentence.

SAMPLE RUNS

RUN
WHAT IS YOUR SENTENCE? THIS IS A SENTENCE FOR YOU TO EXAMINE.
A IS OT FOR OUY HIST AEEIMNX CEEENNST.

RUN

WHAT IS YOUR SENTENCE? WE ARE NOT ALL HERE NOW.
EW AER ALL NOT NOW EEHR.


The Fourth Annual Computer Competition (Part 1 of 4)

(Introduction and Part 1, Part 2, Part 3, Part 4)

Introduction

During my junior and senior years at high school I participated in a county-wide computer programming competition.

The day before the first competition, my junior year, the president of the computer club challenged me to a quick on-paper coding competition to see who should go. I beat him handily, and he was kind enough to give me the spot. Charles was a brilliant guy who I'm sure did just fine without the competition on his resume.

Both years, the competition went like so: every student was allocated an observer-judge. The judge was responsible for resetting the programming environment, clearing code and data, watching the student during the test, and then, when the student was done, would test the program with a predetermined data set. Correct exact results meant the student earned one point. Any incorrect result meant zero points.

The junior year I tied for third place with four other kids, resulting in a sudden-death run-off. (I remember getting at least one question incorrect. Did I get two wrong? My ego is struggling with the possibility.) I'm positive that had I not paused to test my program during the run-off I would have taken third-place, and the TRS-80 would have been mine. Alas.

The senior year's competition was the day after my prom, and I chose not to attend the prom in order to get a good night's rest. (This is a lie; I didn't attend the prom for plenty of reasons, most of which was I didn't fit in. My girlfriend and I had dinner at Gasho of Japan instead.) I don't remember doing well enough to win or place.

Tonight, while going through some old boxes in the basement, I came across one of the competition packets. There's no year on the packet, so I can't tell for which competition it was. There are four questions, labeled two through five, meaning that one of the questions is missing.

I'll publish the four questions, each as its own blog post. I won't include sample answers, because mine were built and destroyed quicker than sand sculptures. Plus they were written in BASIC, and I love you, but not that much.

The first question, Question #2.

Question #2 Senior Division

Write a program that will ask for six 3-digit numbers (without signs) to be input one at a time. ANY 3-digit number is valid. (Examples: 123, 049, 899, etc...). If anything else is input (letters, etc.) the program MUST output the EXACT error message "PLEASE INPUT THREE DIGITS ONLY", and then request the number again. After SIX 3-digit numbers are properly input the program is to tally the digits according to their position and output a table listing how many times a particular number appears at each position (hundreds, tens and units place.) See the SAMPLE RUN for clarification.

NOTES:
1. Try to make your output table easy to read, but do not worry about all numbers lining up perfectly since various computers differ slightly in formatting. [The judge will be looking for accuracy of output, not formatting of output.]
2. To make your task a bit easier you may assume that the judges will NOT attempt to input any commas or quotation marks. Any other input, however (letters, numbers, +/-, etc.) is "fair game", so make sure to test your program thoroughly.

SAMPLE RUN
RUN
3-DIGIT NUMBER 1? 364
3-DIGIT NUMBER 2? XYZ
PLEASE INPUT THREE DIGITS ONLY
3-DIGIT NUMBER 2? 446
3-DIGIT NUMBER 3? 780
3-DIGIT NUMBER 4? 8994
PLEASE INPUT THREE DIGITS ONLY
3-DIGIT NUMBER 4? 507
3-DIGIT NUMBER 5? 5B7
PLEASE INPUT THREE DIGITS ONLY
3-DIGIT NUMBER 5? 060
3-DIGIT NUMBER 6? 492


TALLY   HUND    TEN     UNIT
-----   ----    ---     ----
ZERO     1       1       2
ONE      0       0       0
TWO      0       0       1
THREE    1       0       0
FOUR     2       1       1
FIVE     1       0       0
SIX      0       2       1
SEVEN    1       0       1
EIGHT    0       1       0
NINE     0       1       0


Monday, July 20, 2009

How not to empower your users; don't let them use their primary email address.

Awesome.

PSE&G only allows you to set up one customer service account per email address. So, if you live on one property in their service area, and then move to another property in their service area, you must register a new account with a brand new email address.

I'm genuinely still a little shocked. No matter how hard I tried, I could not find a way to either add a second account or remove the first one to my email address. I messed with pseg.com for 15 minutes, so I called them for help. After 20 minutes on hold, I asked how to change the account. The customer service representative told me, no, I couldn't do that, I had to create a new account. Being hasty, I thanked the CSR and ended the call, assuming he was just wrong.

Registering a second account with the same address failed. Registering a second account with email+pseg@domain.com also failed, not because it was a duplicate but because PSE&G considers that an invalid email address. Honestly, not much of a surprise, that.

So I called again. Was it really like that? After another 20-minute hold (whoo, these guys are popular) I confirmed with a second CSR that, yes, really, it was like that. She said I should just "create another email at like yahoo mail." The CSR agreed to lodge my complaint and I rung off for the second time.

I have one email address upon which I rely, the destination of all my important personal correspondence. Why should PSE&G email have to be delivered elsewhere? I could create a second account whose purpose is merely to forward all mail to the primary one. I refuse to have to remember a new email account just to pay my electric bill. I'm still hoping that one day all my accounts can be registered through OpenID, so this is somewhat the opposite of that goal.

Perhaps people are so dissatisfied with PSE&G that they vow to move out of their service area before ever using them again?

This is a bug, plain and simple. Most likely a bug in requirements or design. And  it got me thinking: what different developement phases might have created such a problem?
  • Requirements gathering phase: perhaps nobody mentioned this as a possibility. Better still, someone mentioned it as a very rare occurrence.
  • Design phase: maybe this was an intentional design decision. Maybe they don't particularly care about account history as a person moves between properties.
  • Database design: assuming a SQL database back-end, perhaps the whole product is wrapped around a database that has a single table called ACCOUNT with columns email_address and account_id. perhaps they can get a lesson in Third Normal Form.
  • User acceptance testing: perhaps no managers or testers had recently moved within the PSE&G service area, if at all.
  • Middle-tier design: first thing I'd do is grep for function createaccount($emailaddress, $accountid)
  • Contract negotiations: The back-end support team has a charging structure based on the number of accounts.
  • UI design: I ... can't really find a way that UI design gets in the way. Here's the registration form. Maybe you can see something.

In my many years working in the pharma consulting industry, there was a common phrase for difficult non non-negotiable tasks: Phase 2. Could this just have been considered a Phase 2 project, complete with database normalization redesign?

Could be. After all, this consumer site is just over 100 days-old.


Sunburst2!

Sunday, March 01, 2009

Building a National Pet Identification System in Java

This week I dealt with a rather irritating little problem that wound up having a surprising source. Rather than try to explain it to my wife in technical terms, I went for the more prosaic form, but for those of you that are familiar with Java, it's all about this.



Congratulations! President Obama created a new Cabinet post, and you became the first Secretary of Pets! Your first task: managing and categorizing every pet in the United States: dogs, cats, budgies, snakes, it's your domain. You decide to identify every pet by giving them a unique nationally-assigned number. References to that number are the same as references to the pet and references to the pet are the same as references to the pet's identifying number. You create a huge central station just outside Lebanon, Kansas and process requests as they come in. Someone requests an identifying number for a Maltese cat in Michigan, they get 104558628. The next request is for a wire-haired terrier in Pasadena, CA and they get the next one: 104558629.

You've also been tasked with creating an abstract broad classification system. It's an odd classification requirement: you don't need to classify by species, number of paws, color, gender, geography or fangs, just something that lets you batch them up. So you create a classification based on the identifying number already given to the animals by declaring an animal's classification as the last two digits of the identifying number. So if your wire-haired terrier's identifying number is 104558629, its classification is 29.

So far so good, your central station is humming away, doling out identification numbers. One day your sister's cat goes missing, and she goes to the Lost Pet Center. She doesn't describe the cat, she just gives her cat's identification number 104558628, and a Lost Animal Ticket is stored in the National Lost Pet Database.

Remember when I said earlier that referencing a pet is virtually the same as referencing a pet by its identification number? Thanks to this you were able to build a Pet Identification Station in every town: put the animal up to a station scanner and, presto! It displays the animal's identification number.

Also in every town is a Lost Pet station. It's awesome: if you find an animal you don't even have to bring it to the station, you just supply its identification number. When you do, cogs turn, phones dial and the Lost Pet station connects to the National Lost Pet Database, and asks it: "Is this identification number in your Database?" If the response is no then it's not a lost pet, and if the answer is yes the cogs turn and phones dial. The Correct Authorities are notified and before you know it, your sister's cat is safely returned. In fact, she just told me so about an hour ago, and her cat's making all sorts of happy purrs. Do you like happy endings? I love 'em.

I bet you're a little sad that there's a National Lost Pet Database. Don't be sad - it's not a terribly large list, and it's certainly smaller than before you ever built your pet identification system.

But it's large enough that everyone wants it to respond as quick as possible. Nobody wants the National Lost Pet Database to be the source of delaying a pet returning to its home, particularly not the politicians, at least, not the savvy ones. But right now, how it works is like this: every entry in the database is a Lost Animal Ticket. The Lost Animal Ticket contains the identifying number of the pet as well as a piece of information about the owner to facilitate fast contact. When trying to decide if any pet is missing given its identification number, the system creates a prototype Lost Animal Ticket, and attempt to match the prototype ticket against every entry in the lost pet database. If the identifying number of the first entry matches the identifying number on the prototype ticket, it's considered a match. If not, it moves to the second Lost Animal Ticket entry in the database, and performs the same test. This repeats until a match is found or until the entire database is exhausted. It's a bit like trying to find a playing card in a deck by taking a prototype card from yet another deck and attempting to match it against the first deck through visual inspection.

So to make it faster, you come up with a Great Idea: split the database into several miniature databases. In fact, thanks to the classification system you designed, you can just split the database into a hundred mini databases, and in each mini database you only put Lost Animal Tickets for pets with the same classification number. So now you have one mini database for all Lost Animal Tickets for pets classified as '00', one for all pets classified as '01', one for all pets classified as '02', and so on up to '99'. This really works well because every mini database is about as large as every other, and even better, instead of search through every Lost Animal Ticket, you just search one of the mini databases in 1% of the time. Instead of searching through all the possible missing pets, you only have to search through the mini database for pets classified as '28', which as we know are the last two digits of your sister's cat's identifying number. In some ways this is like trying to quickly search a deck of cards by separating them based on their suit first.




All of this works and is predicated on three important things which may seem obvious: first, everything that tries to classify a pet must consistently perform the same step to get the classification number, which is to create a Lost Animal Ticket, read the identification number from it and use its last two digits; second, that whenever attempting to match one Lost Animal Ticket against another, this must be performed by matching the identification number on each of the two tickets; and third, those first two things agree that the identification number is what matters.

And here's the thing: what happens if any of those assumptions are wrong? For instance: one day you decide to categorize pets by the first two digits of the animal's identification number instead of the last. While your sister's cat's Lost Animal Ticket is sitting in mini database '29', everyone may look in mini database '10'. All of a sudden nobody can find your cat, or it's registered in two separate mini databases.

Here's something else that can go wrong: instead of comparing Lost Animal Tickets using the identification number of the animal, the system uses the identification number of the pet's owner. If your sister lost three cats and one is found, it's quite possible for the wrong ticketto be matched against the prototype ticket. Also consider instead a possibility where the criteria for deciding if tickets matched changed to being the same physical piece of paper. Doesn't make sense? If you and I both have a four of clubs, we could possibly agree they were the same card. (That's basically how the National Lost Pet Database works.) But if instead of playing cards, we had airline boarding passes, it would be safe to assume that if you were standing on an airplane with our own boarding passes, if they referred to the same ticket, someone may call The Correct Authorities, and if we applied that algorithm to the National Lost Pet Database, then pets would practically never be found.

Finally, your system will fail from a poor combination of the first two requirements: if your system's categorization calculation is inconsistent with its test for equality, the system may lose tickets. For example, while the first example of possible failure still used the pet's identifying number, what if classification was something more arbitrary, like the time the ticket was issued? The prototype ticket will have been issued at a different time from the lost pet ticket, and as such will likely be classified in different mini databases, and never be found, or only found due to something repeating the same error (Like the time nobody at the bank could locate my account until someone mistyped my name the same way as the teller who registered it on my behalf. That's another story.)

Luckily for your sister, you didn't make these mistakes. Your National Pet Identification System is a huge success, and President Obama has now tapped you to address the problems with our banking system, just like Moist Von Lipwig.

Keep in mind: if anyone plans to write a National Pet Identification System in Java, read Items 8 and 9 of this book. You may save someone both several hours of work and their wire-haired terrier.

Sunday, September 14, 2008

An observation about facial tagging

I am happy to see that the Picasa team launched their new facial tagging feature. I've had the pleasure of playing with it/testing it/providing feedback before its release and am glad to see it released to the world. While it was internal, I did not dedicate my time to seriously tagging photos. Consider: when something is in an internal testing phase, there's always an outside chance that the engineers might have to clear out historical data. Now that it's public, I've tagged thousands of faces.

I discovered something interesting from tagging this many faces. Let me give you some background: the facial tagging feature does two things very well: it can identify faces in a photograph, and it can identify when the same face appears in multiple locations. In other words, it can easily tell you when several photos contain the same person. What it can't do is tell you who those people are -- that's something you have to do. It may know that these are all the same person but only you know that's Chris's Mom.



So here's the thing. While looking at a nonstop stream of faces that represent my entire social graph, I all too often could not name face. Twice so far I failed to recall the name of colleagues I see every day. Often I see faces that I can only seem to tag as "Ellen's baby" or "Chris's Mom." You can get away with that sometimes but you can't get away with it when it's "your coworker who you mostly remember because of the great socks she wears."

This is unsettling. And it's also a good way to test my recall ability. You typically see faces in conjunction with other related faces. With Picasa, facial tagging lacks the context of related faces, and clusters of faces do not appear next to their related faces, so I find myself going from coworkers husband to niece's friend to next door neighbor. In this case, my brain cannot leverage its ability to cache related concepts up front.

Incidentally, what is Chris' mother's name?

Tuesday, August 12, 2008

Stick with Draft Blogger

I like the recently updated Blogger in Draft. It contains many long-anticipated features, including a nifty new editor, something I desperately wanted. Don't be fooled by the word draft, it's in good shape.

There's one small problem, though: even though I can create new posts using the draft editor, you're still led to the original editor when selecting edit links straight from the blogroll. That can actually cause some formatting problems, since both editors interpret HTML a little differently.

So for the short term, I wrote a small Greasemonkey script that mutates the anchor tag. Have fun with it.

Sunday, August 10, 2008

Watch your return values

Preface - This post was going to be a one-sentence comment to a post by Jeremy Zawodny, but then I remembered my professor, and it went from there.

I had a professor for two semesters that required that all our assignments were written in C. This was his assignment submission policy:
1) Run lint on all your code.
2) All code must have zero warnings from lint, with no exceptions.
3) Any use of strcpy resulted in a zero for the assignment.

#3 was my first lesson about buffer overflows. (We all used strncpy.)

One of the lint warnings pertained to unused return values. For instance, the method signature for printf is
int printf(char *format,...)
How often is printf's returned value given attention? It represents the number of characters written to the stream, or a negative number on failure.

Our linter complained about unused return values for typical uses of printf like:
printf("--done.");
We were required to either accept and process the return value, or explicitly disregard it:
(void) printf("--done.");
This was one of my earliest impressions of studying defensive programming.

In Java, the method java.io.InputStream.skip has a contract that requires you to pay attention to the return value, and the reason may surprise you:
public long skip(long) throws IOException
The skip method may, for a variety of reasons, end up skipping over some smaller number of bytes, possibly 0. This may result from any of a number of conditions; reaching end of file before n bytes have been skipped is only one possibility. The actual number of bytes skipped is returned. If n is negative, no bytes are skipped.
So, you supply a distance to skip, and you likely expect the same value back, at least, most of the time. What amazes me is that the documentation even addresses the common expectation: sure EOF is one way skip(n) != n, and then says, twice, that there may be a "variety of reasons" and a "number of conditions." The author is trying to make up for a troublesome API with special javadoc.

Forget that oftentimes there's no documentation and hence, no contract, you still can't expect that documenting unexpected behavior is going to result in proper use of the API.

Present day, Java has Findbugs, The Lint Of Java (zero results, you saw it here first!) Java's classfile format and FindBugs' semantic analysis makes it much more powerful than lint, it can identify this issue with java.io.InputStream.skip(). From the description as Findbugs reports it:
This method ignores the return value of java.io.InputStream.skip() which can skip multiple bytes. If the return value is not checked, the caller will not be able to correctly handle the case where fewer bytes were skipped than the caller requested. This is a particularly insidious kind of bug, because in many programs, skips from input streams usually do skip the full amount of data requested, causing the program to fail only sporadically. With Buffered streams, however, skip() will only skip data in the buffer, and will routinely fail to skip the requested number of bytes.
That's great, but there's a problem, and that comes with expanding the API. If I build my own API with its own nuances, someone needs to write a FindBugs detector. (Hint: be careful writing a clever API!)

It seems draconian to enforce a policy of "always address return values" with Java outside academia since there's no easy way to mimic the explicit cast to void. Otherwise you wind up with unused local variables, which becomes yet another code smell.

In the end all tools like FindBugs and lint only augment the human analysis that accompanies development.

I hope students today are being told that they cannot turn in any Java assignments without running FindBugs.

Monday, June 23, 2008

Screencast: Using Property Testers in the Eclipse Command Framework

Eclipse 3.4 (codename Ganymede) is on the verge of release. Having struggled with the Eclipse Command Framework, I decided it would be valuable to provide a screencast demonstrating the component I thought needed the most clarification, and where I spent the most time spinning my wheels: the property testers extension point.

Was this worth the amount of effort I put in to it? I can't count the number of hours it took to create my first screen cast - I needed SnapZ Pro X, IMovie '08 and finally, Gliffy, Screen Flow and The Gimp. One thing I learned through this exercise: making a crisp screencast is hard work.

I hope it is useful to you.


Using Eclipse Property Testers with the Command Framework from Robert Konigsberg on Vimeo.

Wednesday, June 04, 2008

Time for me and The Facebook to part ways

To my friends on The Facebook:

The time has come for me to close my account on The Facebook. It's been great and it's been nice to reconnect with many of you, but now, not only do I find myself spending more time on it than I would like.

This isn't a referendum on The Facebook, it's a referendum on my time. See, I spend a lot of time on The Facebook, and I just don't feel that I'm getting the value out of it that I'm putting in to it.

The clincher came this morning, when I chatted with one of my colleagues:
Me: Can you help me with something that will take just a moment of your time?
Him: Sure, whatdya need?
Me: I need you to make a decision for me. But I'll give you no data. All I want from you is 'yes' or 'no.
Him: Shoot.
Me: I won't give you the question.
Him: Or really, no data?
Me: Really.
Him: I've flipped a coin.
Me: OK.
Him: Tails.
Me: So was that Yes or No?
Him: Oh, I don't know. It's tails.
Me: OK that doesn't help me. Let's try again.
Him: OK, this time tails = no.
Me: OK.
Him: It's tails.
Me: Perfect. The question was "Should I delete my Facebook account?"
Him: So you're not going to delete it?
Me: No, I will.
Him: What?
Me: There's this poem which I'm about to butcher [ed: which I then did.]
...
The poem comes from Piet Hein, and I'm copying it from Nelson Minar's weblog:
Decision Making
Whenever you're called on to make up your mind
And you're hampered by not having any
The simplest way to solve the dilemma you'll find
Is simply by flipping a penny

No, not so that chance shall decide the affair
As you're passively standing there moping
But as soon as the penny is up in the air
You'll suddenly know what you're hoping

Helpful advice at a time like this.

This doesn't mean I no longer want to be in touch; I do. It just means I would just be happier using other online media to do so. You can still find me on Twitter, FriendFeed or even my occasionally updated blog. If you use gmail or AOL instant messenger, give me your account information, and we can chat that way. Or you can even send me email through the traditional means, and I certainly hope you do.

Keep in touch. - Robert

Monday, May 26, 2008

Becoming a Java Master, con't.

Last night I read an interesting post by Steve McLeod, titled Becoming a Java Master. The article suggests these "books, techniques, and qualifications that help you become a Java Master." You can browse the article to see what he suggests: a good series of books and a Sun Certified Java Programmer certification. I think these things are helpful, but not nearly enough. Of course, everyone takes their own path to mastery, mine involved a job with some of the greatest engineers I've ever met.

Note: I don't consider myself a 'Master', and that's in part because it's hard to use that phrase when I see names like Bob Lee in my inbox almost every day.

All of Steve's recommendations are good, here are some others:

Read

  • Participate in a reading group. From a personal perspective, the thing that worked best for me was to skip participating and go straight to leading the group. Occasionally, (and this depends on the group,) you don't need to be a subject matter expert to lead a reading group, just a desire to learn a topic, and a few people who will look to you to set the group's tone. I find that the fear of embarrassing myself as an unprepared leader is usually enough to get me through a difficult book. (Except that one time when we read The Haskell School Of Expression. I make no apologies for that one.)

  • Read Java Puzzlers. It doesn't feel like a mastery-type book, but only because it's so much fun.

  • Read the Core Java books. They are invaluable references.
Get Inside
  • Read some of the JDK source. Do you know how ArrayList got its name? Have you tried to understand ConcurrentHashMap from the inside? Go find out.

  • Try to write something meta, like a class file decompiler, a custom classloader, or a debugger. You don't have to finish it, and it doesn't even have to have to be revolutionary. You're doing it for yourself so you come away with a bonafide understanding of the insides. (Personally, I started writing a decompiler in 2004. When I got hired by Google, I stopped putting time aside for it.)
Be Like A Master
  • Regurgitate what you have learned. You choose the format: a blog, an online document, an open-source contribution, a presentation. Heck, you can even write a book. Regurgitating the information helps you become a subject master.

  • Participate in Java Ranch or any other online forum, and the answer questions you find online. Answering other people's questions is a great way to reinforce your own knowledge. Of course, use it to ask questions about things you don't understand. A true master knows it's good to ask questions.

Sunday, April 13, 2008

An advertisement seen in Vienna

I checked evite.com while in Vienna and was presented with this ad:


I couldn't understand why this Viennese ad was in Arabic, and I wondered what it was referring to: was my PC infected with an Arabic virus? I clicked the ad which took me to this page (URL http://www.usafis.org/_sys/EN/count_land3_en.asp?af=add_ab_exm_728x90_ab):



A little searching turned up a site suggesting possibility that this particular green card service is not a scam per se, but not necessarily recommended.

Can anyone tell me what the advertisement's text says?

Friday, April 11, 2008

Integer.getInteger. Are you kidding me?

Photos and diary are on haitus. Now a little technology.

I just discovered a method introduced in Java 5: the method Integer.getInteger(String):

http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Integer.html#getInteger(java.lang.String)
Determines the integer value of the system property with the specified name.

The first argument is treated as the name of a system property. System properties are accessible through the System.getProperty(java.lang.String) method. The string value of this property is then interpreted as an integer value and an Integer object representing this value is returned. Details of possible numeric formats can be found with the definition of getProperty.

So let me see if I understand:
  • Integer.valueOf(String) converts a String to a number by assuming the String is a numeric representation. In other words. Integer.valueOf("12345") yields the number 12345.
  • Integer.getInteger(String) converts a String to a number by assuming the String is the name of a system property numeric representation. In other words. Integer.getInteger("12345") is likely to yield null.
Why would anybody consider this a sufficient distinction? How many bugs are people going to create by using getInteger when they meant valueOf and vice versa?

This type of overloading is called near-phrase overloading. I just made that term up right now. It's when people use very similar words to mean different things. Consider two words x and y, their general meanings gm(x) and gm(y), and their meanings in a given context, cm(x) and cm(y). If
distance(gm(x), gm(y))< distance(cm(x), cm(y))
then it's a bad use of x and y! Go find another x and y for their contextual uses. Really, they could have called it getIntegerProperty.

This is the worst case of avoidable ambiguity I've seen in Java; I expect better coming out of them.

Update: it turns out there is something worse: Boolean.getBoolean("true") is usually equal to Boolean.FALSE.

Sunday, March 16, 2008

Unicode and custom characters on a console display.

When transferring documents from Google Docs to Blogger, the article's title and labels are not set. If I were to edit the document after the transfer in order to set the article's title and labels, I would lose all my non-breaking spaces. Sadly, I must instead post it as-is, and but the article title, labels, and reference link here.