Here’s the total amount of US debt owned by foreign governments. They own about 25% of the total $10 trillion dollar debt. Here’s a breakdown of ownership of all the debt (doc) over the last 10 years. Right now China owns a mere 7% of the total US national debt. In fact, investors are withdrawing their money from markets around the world and stuffing them into US Treasuries, which are perceived to be the safest place for money right now. From June’07 to June’08, foreigners bought ~$450B more and US mutual funds added ~$200B of US debt. Remember this the next time a politician stirs up nationalism and racism by complaining that China owns the US. Here’s a good source for more info on the debt.
Who owns our debt?
March 1, 2009 by PinkuLimited pattern matching for Java
March 1, 2009 by PinkuProject Coin on OpenJDK is soliciting ideas for small language changes for Java 7. The ideas so far appear to suggest features from C#, which is a superior language IMHO. In principle, I hate the idea of baking in cosmetic changes to a language. Scheme and Lisp macros are a profoundly better solution to syntactic issues, but mainstream programmers will never grok it. So Java has no choice but to add more stuff. Therefore, I think the switch statement is seriously underutilized in C-like languages. One idea is to add support for a limited degree of object pattern matching. Think of it as a painfully limited version of the case expression in many functional languages.
The switch in Java currently only allows a few primitive types. Change it so now you can have switch(objectType). Allow the case arms to support a boolean expression. To simplify things, allow access to object fields like this: “.field”. So the new switch would look like this:
1: switch (myCustomer) {
2: case (.name == "Bob"): stmts ;
3: case (.age > 21 && .income > 20000): stmts ;
4: default: stmts ;
5: }
A simpler idea is to stick with the regular switch statement, but support multiple switch variables. Right now, you can only do “switch (oneItem)”. Instead, you could allow “switch (oneItem, twoItem)” and more. In the case arms, right now they allow “case constant:”. Instead, this can be extended to allow “case constant1, constant2″ and more. Obviously, each constant is matched with the switch variable in the same position. If there are too many constants, that’s a syntax error. If there are fewer constants, then ignore the remaining variables. Here’s an example:
1: switch (document, output) {
2: case "pdf", "printer": print it out;
3: case "pdf", "screen": use acrobat;
4: case "jpg", "printer": turn on fancy colors and print;
5: default: b/w print;
6: }
Finally, the absolute simplest extension to the existing switch statement is to allow case ranges. This is already implemented in Visual Basic.NET with their Select Case statement. You say “Case 1 to 10″ to match that range. Lots of languages support this. This feature won’t change the world, but it does make switch a bit more useful.
How many friends can you have?
February 27, 2009 by PinkuI first ran across Dunbar’s number in The Tipping Point. Robin Dunbar estimates that humans can maintain, on average, a group size of 150 people. Beyond that people are more like strangers. The Economist interviewed Cameron Marlow from Facebook, who has analyzed how people socialize on Facebook. The numbers are better summarized here. The key point is that people appear to have a close relationship (measured by regular communication) with only 5% of their overall group. The average number of friends on Facebook is 120 (though a big range), but people regularly communicate with only around 6 of those people (women have a few more close friends than men). I don’t think you can equate Facebook friends with Dunbar’s number because it’s too easy to add random people and never think about them again. But it’s interesting that the average is around the same.
All-you-can-read subscription for news
February 12, 2009 by PinkuNewspapers are dying. Walter Isaacson says newspapers must charge for content, but Michael Kinsley says it will not work. In particular, Isaacson likes micropayments, but almost everyone else hates the idea. This blog explains the problem with newspapers better than most. Before everyone gives up on the idea of charging for content, let’s remember that Apple succeeded with music, Amazon’s Kindle looks impressive with books, NetFlix is going strong with DVDs & streaming movies, HBO is still going strong with plain old TV, and the Wall Street Journal and the Financial Times require a subscription. The New York Times had a subscription for some stuff, took it down, but are now rethinking the issue. I believe the solution to building a viable news business is to take a two-pronged approach; nevertheless, there are too many subpar newspapers that should go bankrupt anyway (NYT agrees).
Espresso machine buying guide
February 12, 2009 by PinkuMy current espresso machine, a Francis!Francis! X5, has been losing pressure and producing swill for several weeks. After reading tons of information scattered on the web, I’ve decided to write it all down for posterity and save others from doing all this work. First, it’s important to understand that the toilet water served at Starbucks and other cafes is not espresso. Try an espresso or cortado at one of these fine coffee shops to understand why.
Solving the Great Recession
February 11, 2009 by PinkuAfter reading a million contradictory economics articles and blog posts about out current financial meltdown, here’s my ignorant attempt at a solution. The economy is like a series of tubes: the Keynesian formula is consumption + investment + government + exports – imports = GDP. All of these values have dropped markedly. Many banks have lost so much money that they are bankrupt but refuse to admit it (zombie banks); therefore, they are sitting on whatever capital they have left and making fewer real loans. Consumers have been hit hard by the fall in real estate and investments, and by growing unemployment. For the first time in years they are saving rather than consuming (paradox of thrift), which reduces demand for goods. In the long run, the government is doomed to bankruptcy because of the steady growth in entitlements, mostly due to health care. Finally, the financial collapse is global, so we can’t depend on exports to tread water like Japan did during the 90s. So the world is royally screwed.
Complexity Matters
January 18, 2009 by PinkuIn my previous post, I complained that the performance of my concurrent skiplist was outrageously slow. I ran it with a profiler, but all operations were slow. By accident I narrowed it down to the randomLevel function. Then I realized that I had limited the height of the skiplist to 6 when I was testing it. This is fine for a small collection of 2^6 (=64) items. In my performance testing, I was using a list of 200K items. That means the bottom row contains a singly-linked list of ~3000 items which must be searched linearly. That is very very slooow. The morals of the story are that (1) complexity effects performance enormously and (2) it’s hard to find those bottlenecks by just profiling and staring at code.
The solution is to remove the call to Math.Min in line 37. It runs fine after that.
Concurrent Skip List woes
January 15, 2009 by Pinku[ed: I've removed the code. Look here for an explanation and the updated code.]
Java has a very fast, very complex ConcurrentSkipListMap, but .NET does not. I implemented a simpler concurrent skip list algorithm (pdf) in C#. I ran 2 threads to add/remove entries with high contention. It runs quickly for a short time and then suddenly slows to a crawl. I haven’t figured out the problem yet. I’m not even sure how to debug it. Code after the jump. [fixed it, explanation here]
Numbers everyone should know
January 1, 2009 by PinkuJeff Dean, a brilliant engineer at Google, gave a talk a while ago listing the numbers every engineer should know. I copied these from here.
- L1 cache reference 0.5 ns
- Branch mispredict 5 ns
- L2 cache reference 7 ns
- Mutex lock/unlock 100 ns
- Main memory reference 100 ns
- Compress 1K bytes with Zippy 10,000 ns
- Send 2K bytes over 1 Gbps network 20,000 ns
- Read 1 MB sequentially from memory 250,000 ns
- Round trip within same datacenter 500,000 ns
- Disk seek 10,000,000 ns
- Read 1 MB sequentially from network 10,000,000 ns
- Read 1 MB sequentially from disk 30,000,000 ns
- Send packet CA->Netherlands->CA 150,000,000 ns
Windows Activation Problem
November 4, 2008 by PinkuMy laptop died recently. I removed the hard drive and converted it into a virtual machine using VMware Converter. I verified the virtual drives by mounting them as disks using VMware’s Disk Mount Utility. Then I ran the VM in Player and hit the Windows Activation screen. This is expected because the hardware has changed radically from a Sony laptop to a virtual machine. Unfortunately, my previous XP license key did not work. I called Microsoft’s Activation support as directed by the wizard. The computer said I had an invalid key, so I talked to a customer service rep who also told me I had an invalid key. The rep, of course, is a moron who couldn’t explain why this might be the case. It turns out an OEM license (pre-installed OS) is only licensed for that machine and cannot be transferred to another machine. However, activation still failed even if I type in a legitimate retail key for XP. Now I was stuck.
I need to change the key, but the activation wizard won’t let me use the computer to fix it. One of the screens on the wizard has a link to the Windows Activation web site. Click that to get a web browser. Go to Google and search for Windows Product Key Update Tool. Download and run it. Enter your legitimate retail Windows XP key and restart the computer. Everything should work now. I had to uninstall all the laptop drivers and install VMware tools to get good performance. It’s working great now. The moral of the story is that Windows Activation sucks, the license for the OEM version of XP is unfair (can’t transfer to new computer), and customer reps are useless meat puppets.