Miško Hevery gave several presentations at Google last year that are worth checking out, I think even if you’re familiar with Dependency Injections and unit testing. They cover the ways that global state can sneak into applications, how undeclared dependencies make classes harder to test and reuse, and how DI in general eases a lot of pain. He’s just a good teacher and the examples are clear and made me want to attack a lot of old code. Hig blog also covers a lot of the same topics.
Year: 2009
Thoughts on the Cost Conundrum
This New Yorker article on health care proposes that we shouldn’t focus on who writes the checks, but rather that hospitals have a well-coordinated team in place keeping costs down.
Imagine that, instead of paying a contractor to pull a team together and keep them on track, you paid an electrician for every outlet he recommends, a plumber for every faucet, and a carpenter for every cabinet. Would you be surprised if you got a house with a thousand outlets, faucets, and cabinets, at three times the cost you expected…
Even if facilities had identical rates for procedures, the cost of a given inpatient stay is impossible for anyone to predict. Neither the incoming patient nor the insurer are in a great position to judge what care given would be unnecessary or inefficient, yet hospitals in McAllen, Texas (and likely all over) appear to deliver a lot of care that might qualify as such. So what can we do about it?
In other news, there’s probably never been as much public support for single-payer care as there is now, but like many of Obama’s promises, it’s off the table. Again, a single-payer switch might only shave minor administrative costs, but it should also give us more control over providers to encourage more to operate like the Mayo Clinic.
I still find the free market health care dream intriguing. If we could just remove all government regulation and insurance, the market would just work its magic and care would be affordable (and for enough people to be considered a success). It would be a grand experiment* to just say, “OK, you get ten years to make it work.” (*Does any country have a freer market health care system I should look at?)
The reality:
- Voters will never ditch Medicare, so the experiment will never happen.
- Democrats, like Republicans, will be driven by existing industry dollars, so single-payer will go nowhere (unless unemployment got much, much worse).
- We’ll inevitably raise taxes to cover Medicare (no politician facing re-election will let it (or SS for that matter) go insolvent on ideology).
So we’ll continue to have a system that few are happy with, and we’ll pay too much for it.
You Probably Don’t Need ETag
(updated 3/4 to include the “Serving from clusters” case)
As I see more server scripts implementing conditional GET (a good thing), I also see the tendency to use a hash of the content for the ETag header value. While this doesn’t break anything, this often needlessly reduces performance of the system.
ETag is often misunderstood to function as a cache key. I.e., if two URLs give the same ETag, the browser could use the same cache entry for both. This is not the case. ETag is a cache key for a given URL. Think of the cache key as (URL + ETag). Both must match for the client to be able to create conditional GET requests.
What follows is that, if you have a unique URL and can send a Last-Modified header (e.g. based on mtime), you don’t need ETag at all. The older HTTP/1.0 Last-Modified/If-Modified-Since mechanism works just fine for implementing conditional GETs and will save you a bit of bandwidth. Opening and hashing content to create or validate an ETag is just a waste of resources and bandwidth.
When you actually need ETag
There are only a few situations where Last-Modified won’t suffice.
Multiple versions of a single URL
Let’s say a page outputs different content for logged in users, and you want to allow conditional GETs for each version. In this case, ETag needs to change with auth status, and, in fact, you should assume different users might share a browser, so you’d want to embed something user-specific in the ETag as well. E.g., ETag = mtime + userId
.
In the case above, make sure to mark private pages with “private” in the Cache-Control header, so any user-specific content will not be kept in shared proxy caches.
No modification time available
If there’s no way to get (or guess) a Last-Modified time, you’ll have use ETag if you want to allow conditional GETs at all. You can generate it by hashing the content (or using any function that changes when the content changes).
Serving from clusters
If you serve files from multiple servers, it’s possible that file timestamps could differ, causing Last-Modified dates sent out to shift and needless 200 responses when a client hits a different server. Basically, if you can’t trust your mtime to stay synched (I don’t know how often this is an issue), it may be better to place a hash of the content in an ETag.
In any case using ETag, when handling a conditional GET request (which may contain multiple ETag values in the If-None-Match header), it’s not sufficient to return the 304 status code; you must include the particular ETag for the content you want used. Most software I’ve seen at least gets this right.
I got this wrong, too.
While writing this article I realized my own PHP conditional GET class used in Minify, has no way to disable unnecessary ETags (when the last modified time is known).
Safari Cache-Control:must-revalidate bug
Update Apr 8 2009: Apparently this bug existed in previous Safari versions (at least back to 3.1), i.e. including “must-revalidate” in Cache-Control means Expire and max-age will both be ignored by Safari. Here’s the Apple bug, if you happen to be an employee. I created an Apple account but still couldn’t find it.
Short version: Safari 4 beta incorrectly interprets the Cache-Control “must-revalidate” directive and re-requests the file each time despite freshness info sent via “max-age”.
Long version
When a server sends Cache-Control with “must-revalidate”, this tells clients/caches that, after it expires, the cached resource should not be used without first checking with the server (sending a conditional GET). From the spec (my emphasis):
When the must-revalidate directive is present in a response received by a cache, that cache MUST NOT use the entry after it becomes stale to respond to a subsequent request without first revalidating it with the origin server. [HTTP/1.1]
In other words, while the cache is fresh, there’s no need to revalidate.
E.g. I serve this Javascript file with the header “Cache-Control: public, max-age=1800, must-revalidate”. This tells clients: “consider this fresh for 30 minutes, then check back before using it again”. Unless you force a refresh, the browser won’t re-request the file for 30 minutes, after which it will send a conditional GET request. If the file hasn’t changed, the servers returns a “304 Not Modified” and the same Cache-Control header. This tells the browser to keep using the cache for another half hour and check back again. (Yes, half an hour is too short, I’ll change this later.)
Well, Safari 4 beta re-requests the file each time it needs it, seemingly ignoring the “max-age” directive. At least it’s sending a conditional GET, but it’s still a waste of bandwidth and time.
Plan Juarez
If you haven’t noticed, Juarez and many other Mexican cities are facing a violent crisis. The drug cartels are so well funded and armed that they can bribe officials and even threaten police chiefs into retirement. The drugs moved by the traffickers can, of course, cause harm, but Mexico’s problem isn’t a “drug problem” but rather a prohibition problem.
The relatively rich people of U.S. and Canada create a huge demand for drugs, both government regulated and illegal. By waging war on some drugs, we outsource much of our illegal drug production to South America. Mexico has traditionally given lip service to our prohibition, but not devoted much to the effort in practice, forcing the U.S. deal with the problem on our side of the border and in Colombia. This allowed the cartels to work in relative peace for many years, but this was still unacceptable to former president Vicente Fox. Fox battled the cartels and managed to unseat a few kingpins, which only led to more violence. When Calderón replaced Fox in 2006, he declared his own war on the cartels, calling in federal troops to replace the police and greatly escalating the war.
U.S. officials and drug warriors, of course, find the violence acceptable. “There will be more violence, more blood, and, yes, things will get worse before they get better. That’s the nature of the battle,” said U.S. Ambassador Tony Garza. (Would these people find it acceptable if thousands of U.S. citizens were dying and living in a police state to prohibit sales of goods to Canadians?)
A Solution for the People of Mexico
It is not your money, guns, or addictions that are feeding the violence in your country. I propose that you end the war on your fellow citizens.
- Create a license to legally produce and traffic “illegal” drugs strictly for export to the U.S.
- Allow licensees to freely operate, but with taxes and rules, while continuing to fight unlicensed organizations.
- Allow law-based disagreement resolution mechanisms and revoke licenses from organizations linked to violence.
In other words, you should make your narcotraficante industry look more like UPS and Budweiser than Al Capone’s Chicago Outfit.
Resistance to such a policy would come primarily from key players in the drug war. Your cartels will want to maintain control, but their profits will die as non-violent businessmen take up licenses and take their business. Our DEA may suggest closing your border or even replacing your government by force; we’ve done it before.
In the end you’ll have to decide what is in the best interest of your people. Is it worth their lives and the very stability of your government to prevent Michael Phelps from hitting a bong?
Sorry Jerks, Intimidation Won’t Change the Web
Shameful law firm Jones Day sued real estate news site BlockShopper claiming “trademark infringement” over the way the site used link text, but really because the firm didn’t like how the site reported the home purchases of their partners (which is public record). The case should’ve been thrown out, but the judge allowed it, and, in doing so, allowed the firm to bleed the site of $110K in legal fees. BlockShopper finally agreed to settle out of court and to format its links to the firm in a particular way.
…it signals to companies that they can force sites to revise their linking styles by alleging trademark infringement. And Judge Darrah’s decision not to dismiss the suit signals that Web publishers may have to spend significant sums to deal with this kind of litigation. [Slate]
Paul Levy noted the law firm is “a serial abuser of the trademark laws to suppress commentary that it does not like.”
Personally, I would’ve just used this URL to link to the bullies: http://google.com/search?btnI=1&q=Paul+W.+Schroeder+Professional+Biography
E.g., “Paul W. Schroeder likes to strongarm web authors.” Or you could use a 3rd party redirect site like tr.im. In fact, there should be a redirector designed to shame site owners who attack linkers like this.
Update: We now have one: http://mrclay.org/warning/
E.g.: Paul W. Schroeder.
Zero Tolerance Nets Another Slimebag
What if we had zero tolerance for laws that have a lot of ugly side effects? Like busting an amazing teacher in front of her kids… for finding a couple Xanax pills… in a suspicion-less search of her car.
Herrick, 59, has taught at Roberts for 17 years. Parents describe her as “inspirational,” “talented” and “loving.”
She comes to work early so kids can finish projects they didn’t have time to complete in class. So many kids wanted to join her after-school art club that it had to be restricted to fifth-graders. More than one parent tells how she dropped by a student’s house, bearing art books that she thought might be of interest.
She’s a ferocious doubles tennis player, nationally ranked, so fanatical about her game that she hesitated a year before taking cholesterol meds that her doctor prescribed.
In 1995 and 1999, Herrick was Roberts’ teacher of the year. For 2005-06, she was teacher of the year for HISD’s entire Central District. And in 2009, she was busted.
In the middle of a class, police escorted her from her classroom. After she unlocked her car, police found a baggie with two Xanax pills.
Herrick said she has no idea how the pills got into her car, which other people in her family drive.
But no matter. She was hauled away from the school she loves in the back of a squad car and charged with possession of a controlled substance within 1,000 feet of a school. If convicted of that third-degree felony, she could serve two to 10 years in prison.
Even though she’s passed the drug test and a lie detector test, she’s out of the classroom for the time being. As Pete Guither writes, “It’s, you know, for the kids.”
What if she does have a Xanax problem? Having teachers like this lady, personal habits and all, is what builds kids that never need to try drugs. How about the experience of watching your favorite teacher taken to jail? or growing up a paramilitary police state?
Unstimulated
If this National Review article is accurate, the stimulus bill is worse than I was imagining. It’s not that I’m against every piece of it, but wrapping up countless unrelated projects under one bill and/or pushing it through Congress as an “emergency remedy” is a terrible way to create laws.
This is how we got the Patriot Act and the Commodity Futures Modernization Act of 2000.
Although the right is ablaze over this, I think I’m a little too cynical to believe that there’s a good/evil party boundary in this. I fear it’s in times like these that both parties will “reach across the aisle” and push through pet projects via a monumental bill to tell citizens they “did something about the recession”. It’s the minority party’s role to “oppose” and break out their own pens to fair it up.
If the Senate Reps oppose this with the same zeal, they’ll win some respect from me. If it passes, for years to come we’ll be discovering wonderful new treasures similar to the Enron loophole and unregulated credit default swaps, and plenty of junk both parties are opposed to. We’ve already found a revival of the Byrne grants frequently abused in our drug war.
I don’t see how any elected official can look us in the eye and say, “all this is what we need and we need it immediately, there’s no time to read the fine print.”
New general rule: the level of debate and time for press scrutiny of a bill should be proportional to its scope. Maybe there should even be some limitation of scope within a single bill.
Rational Debate Across the Pond: House of Lords Wants Harm Reduction
What if Congress debated the prohibition of drugs for over 2 hours, finding surprisingly that most members already favored harm reduction policies and, in some cases, regulation over criminalization?
This just happened in the U.K.’s House of Lords. On January 22nd, a debate was held (full transcript) to encourage the government to send a senior (rather than a junior) Minister to the U.N.’s upcoming conference on drug policy, and for that representative to push for harm reduction rather than blanket prohibition. (background).
The transcript shows a frank and open discussion of the negative effects of prohibition on many levels of society. At some point I’ll pull quotes, but basically members desired increased funds for treatment, expressed dismay that the U.N. treaties prevented countries from experimenting with alternative policies, recommended the U.N. officially recognize the difference between use and abuse of drugs, and agreed that the 40 year old policy has been a failure at reducing the use, and especially reducing the harms of drugs in the world. One mentioned that, even if the goal was to “sustain” the current level of drug abuse (as our Drug Czar frequently states), that that level of abuse and the societal price of prohibition is too high to continue to tolerate.
If the U.K. is not the only country that wants to get smarter rather than tougher on drugs, we may see some revolutionary reform discussion come out of the March meeting in Vienna.
Lying in your job description? You may be our Drug Czar.
The deeper you dig into the history of the Drug War the more craziness you uncover. You’d think an office in charge of drug policy on a national level would monitor science and policy outcomes and work to refine those policies over time, or in the very least not break laws spreading misinformation about drugs.
You’d be wrong! In 2003 Congressman Ron Paul found this out when he pointed out that it’s illegal for the ONDCP to propagandize untruths about marijuana, especially in attempt to lobby against legislation (typically for its medicinal use). The General Accounting Office’s response a year later? Sure it’s illegal, but technically not against state legislation! And since the drug czar’s job description includes doing “such actions as necessary” to oppose legalization attempts of any kind, why look into the misinformation claim at all.
If you’re curious to know what kind of lies come out of this office, I covered those of drug czar John Walters in detail on StopTheDrugWar.org. His writing is practically a guide for constructing logical fallacies.