Friday, November 28, 2008

ABC (meme)

Everyone's doing this, it seems.

A
ActiveSync
B
Bug 71728
C
CSS 2.1 spec
D
Pork (on MDC)
E
Hiragana (Wikipedia)
F
FailBlog
G
comp.lang.java.programmer
H
Hunter × Hunter (manga)
I
I can has cheezburger?
J
Java Language Specification, Third Edition
K
OpenJDK
L
I can has cheezburger?
M
[ School resource ]
N
[ School resource ]
O
Bleach (manga)
P
Planet Mozilla
Q
Questionable Content (webcomic)
R
[ Anime video site ]
S
/. (Slashdot)
T
[ School resource ]
U
BOFH (web... column)
V
VGCats (webcomic)
W
Worse Than Failure
X
XKCD (webcomic)
Y
YouTube (specifically, part of a walkthrough for Golden Sun)
Z
Zero Punctation (web video columnist)

A public service announcement

If you are a programmer who is writing code that will be released to the world as open source, this announcement is for you.

If your code will be seen by the world at large, one of your first tasks should be to write documentation. Document all functions as soon as you write them (before is also helpful). Provide samples on how to use code as soon as you finish a module (or earlier, if possible). Do not wait until your 5.0 release. Do not wait until your 1.0 release. Do not even wait until your 0.5 release. Do it as you write your code. The sooner, the better.

Users of your code will thank you profusely if you manage to provide comprehensive documentation along with the actual binaries of reference builds. DO NOT make them have to scour source code or bug developers in IRC channels to figure out a simple task like "get all cards from an address book" or "how do I write a synchronization conduit?"

Wednesday, November 5, 2008

Why I bemoan Tuesday

On Tuesday, November 4, the United States held its presidential and congressional elections. As I am sure most of my readers know by now, the outcome was to elect the Democratic nominee, Obama, as well as increase Democratic gains in the House and Senate (although probably not filibuster-proof). To many, this news was greeted with elation; I do not count myself as one of those people. Let me explain why.

First and foremost, I dislike the results because the United States missed out on an opportune time to make up for its polarization. A Republican presidential victory would leave the government divided, a prospect I feel would be ideal for the government. In lieu of a true multiparty system, we have two major parties who will, by necessary of definition, tend to stake opposite sides of issues and, furthermore, stake them at opposite ends of the spectrum. Giving the entire government solely to one party—actually more, giving it to one with strong enough majorities to evade some mild dissenters—would have the effect of hindering debate.

During the Constitutional Convention, one issue that the drafters considered was the tyranny of the majority. One of the Federalist papers, No. 10, dealt with this topic, mostly by the argument that a larger region would have more diverse parties. However, the two-party system (among other factors) tends to dilute the power of size; another mechanism should be present.

This second mechanism is the tortuous process of law creation. A common criticism of Congress is that it is slow to act. Yet why should lack of speed of action be a bad thing? If one wishes to expedite a bill, one has to cut something out. Almost all of the time it takes to pass a bill is spent on debate. So improving Congress's reaction time would mean that one has to debate less and therefore rely on the bill being correct as it is. We don't regret any rushed actions, do we?

A divided government would force moderation as the Democrats would not have enough votes to override a Republican veto, so a bill would have to amenable to both (and therefore moderate in effect) to pass. With a Democratic president, the extreme positions could show up in laws more easily without general discourse. The large gains in Congress give the Democrats more ability to cut off dissent; thankfully, though, the Senate looks to not be filibuster-proof.

I have discussed enough on the theory of divided government; I also support the Republican candidate on several issues. On social issues I vary between whether or not I agree with McCain, but I do not base my decision on these. Chiefly this is because I think the president has no real power to enforce these opinions on a national level or even be able to have one of these opinions enter into law.

The primary issues I concern myself are more economic in nature. I am an ardent supporter of free trades and no economic subsidies (especially agricultural ones). In terms of policies such as energy, I opine that the government should not favor one alternative over another in terms of, say, research funding, as history has shown the government to be bad at picking winners.

A more generalized position I hold is that I am not in favor of socializing certain fields. One such field is health care; the issue I have here is not one of universal versus non-universal health care but one of privatized versus socialized health care. I am skeptical of claims that socialized (as opposed to privatized) health care would control costs or make health care more efficient. All studies I have seen compare across countries without accounting for factors that would vary between countries.

Another problem with socialization is that government needs restraint. Historically, governments have shown much delight in stealing from funds to pay for general costs, such as Argentina's pension system. Indeed, the United States is quite guilty of this, as our budgetary deficits are partially ameliorated by taking funds from the Social Security Trust.

The final issue I am concerned about is that of regulation. The recent economic and financial crisis has renewed a call for increased regulation. Lack of regulation played little part in the causes of this crisis. In fact, the entire mess started with the mortgage industry, which is the most regulated financial industry. Similarly, calls for caps on executive wages and windfall taxes have increased, both of which are known to discourage innovation. Note how many major oil producers with nationalized oil companies (like Venezuela) are facing problems maintaining output.

On all of this issues, Obama's policies are in clash with my views. He has called to renegotiate NAFTA, create a single-payer health system, enact windfall taxes, and, naturally, called McCain out on supporting deregulation. At least McCain is candid that the economy is his weak point.

And, most importantly of all, he would likely be able to rush his ideas to completion with less discussion. Oh well, we won't get another National Recovery Administration… I hope.

Tuesday, October 28, 2008

Fakeserver

As of 8:18:19 PDT, comm-central now has a mostly-complete (but definitely usable) implementation of an IMAP fakeserver. This means we now have at least partial implementations of all 4 major mailnews protocols: POP, NNTP, IMAP, and SMTP.

Saturday, October 25, 2008

Synchronization

Since my original plan for mailing list sanity was upset by an underestimation of the insanity, I looked into fixing it in the various components. One place where this happened was in palm sync code. This code is so perilous I wouldn't be surprised to find that it broke somewhere along the line. As happens a lot, though, I got a little sidetracked. I tried to sit down and actually figure out what the heck goes on in there.

Like every other time I forayed into this code, I started thinking about how to improve it. What this code most needs is to be generic; there are bugs for adding support for SyncML, ActiveSync, OpenSync, BlackBerries, and even N-Gage devices. There are a few more bugs not citing a specific protocol or device; surprisingly, though, there are no bugs on supporting Microsoft's or Apple's synchronization APIs, as well as iSync. One might also consider something like Google Contacts to be a synchronization architecture.

In short, for Thunderbird and SeaMonkey to support most devices, they need to bridge at least six different APIs. So how can this be done? Fortunately, there are basic steps that need to be done that are common between them: registration, getting the data from the handheld and locally, resolving conflicts, and pushing between them. The primary differences I could find (aside from exact API semantics) were that some APIs requested changes from the applications (calling back when there were conflicts) while others just dumped handles to everything on the application and let the application figure it out.

How could these functions be abstracted from an API point of view? Here's a rough interface:

interface mozIExternalSynchronizer : nsISupports {
   /** The name that one would see in a dialog to enable/disable. */
   readonly attribute nsAUTF8String displayName;
   /** True if the OS sync manager will grab the changes. */
   readonly attribute boolean wantsChanges;
   /** Register this with the appropriate OS sync manager. */
   void enable();
   /** Unregister this with the appropriate OS sync manager. */
   void disable();
   /** Push a set of changes. (Called only if wantsChanges is true) */
   void pushChanges(in nsISimpleEnumerator changes);
   /** Get the records from the other end. (Called only if wantsChanges is false) */
   nsISimpleEnumerator getOtherRecords();
}

Hmm... if we can mostly abstract away the main sync manager stuff, why not abstract the other part? After all, if we're already doing work to synchronize the address book, it's not a large jump to synchronize calendars as well. And who knows what extension developers may be interested in synchronizing? The managers already abstract over various types; we would only need to provide a common glue over this.

Such a feature would need interfaces for defining what could be synchronized (and UI for doing those separately). I don't have these planned out (I need to look more at the APIs, an endeavor I do not have sufficient time for yet). One thing is certain, though: with these changes, Mozilla could add "cross-platform synchronization manager" to its list of features. Indeed, though my main impetus comes from mailnews's current palm sync feature, it does not need to be specific to Thunderbird and SeaMonkey.

Friday, October 24, 2008

Mailing list sanity

With IMAP fakeserver awaiting review, kill-rdf mostly out of my hands (well, except for the subscribe dialog, which needs something I didn't have this morning), my relatively big news change blocking on news connection sanity, and that sanity now just needing some final touchups, I decided to look around for some more things to start on. I therefore turned back to the address book rewrite, which I haven't touched for about a month. What better thing to fill up one's time than by performing the holy grail of the rewrite, mailing list sanity?

Why do I personally consider this one task to be so important? It's because mailing lists, as they stand, are obstinate little things. They are both cards and directories. As two distinct objects, naturally. Yet they are also not quite cards and not quite directories. That they don't fully implement the scope of either makes them unwieldy to work with: one has to invoke isMailList tests in several places. There are approximately 75 such checks in mailnews/addrbook/src alone.

The extent of reliant code puts me off trying to do a one-patch-to-fix-it-all, so I devised some partial steps:

  1. Make an nsIAbMailingList class…
  2. …and temporarily inherit it from nsIAbCard. This will allow me to remove the isMailList from nsIAbCard (in favor of an instanceof-like check) and move mailListURI to the new interface, thereby simplifying nsIAbCard to almost its final state (copy and equals need more work).
  3. Tweak the directory/collection interfaces so that they return nsIAbItem in key places instead of nsIAbCard. This still needs more spec'ing, but the basic framework is in place.
  4. Move nsIAbMailingList to inheriting from nsIAbCollection. Key milestone here in that mailing lists can no longer be viewed as cards.
  5. Flesh out nsIAbCollection. Doesn't need to be in this order, but this is around the latest feasible time.
  6. Shunt nsIAbDirectory mailing-list-specific stuff to nsIAbMailingList. At this time, mailing lists will also no longer be nsIAbDirectory objects.

Steps 1 and 2 are really more like Step 1a and Step 1b. If you're following along on the road map, these correspond to roughly items 3a (first two items), 3b (the last one), and an extended version of 2 (the third and fourth ones). Nice and simple, the changes are in nice, smallish, relatively atomic batches.

Oh wait. Outlook cards and OS X cards could also be mailing lists. The palmsync nsAbIPCCard (which inherits from nsAbCardProperty as well) also cares about being a mailing list. So to complete the first step in the hackery—making the mailing list cards extensions of regular cards—I have to fix generation of mailing list cards in four different places, three of which I can't build on my normal Linux setup and one of which I can't touch on my Windows build (which I touch but rarely). Not to mention that this is probably complex enough to require a few patches on their own. At least fixing these issues will also fix a few ancillary ones as well…

In other news, I have a plan to do some Linux address book integration post-TB 3. This is no way related to any aggravation I may or may not have stemming from using as my primary development system one that has the least number of OS-specific code. I swear… :-)

Tuesday, October 14, 2008

I can has pony?

Not too long ago, I was working on killing RDF in the subscribe dialog. When doing a stress test (a server containing over 180 thousand newsgroups), I noticed that the nsStringStats output at the end had gone up to somewhere in the realm of 180 thousand strings. It couldn't be coincidence, so I ran some leak logs.

Debugging leaks is never fun. Debugging a leak where the object is stored in a global holding pen for almost the entire session is aggravating, as you need to match the references across practically the entire tree. The worst part, however, was that the leaking reference came from JS. After a very long, arduous job of matching up the global references, I narrowed down the suspect to this call (190 characters of whitespace happily elided):

js_Invoke
 XPC_WN_GetterSetter(JSContext*, JSObject*, unsigned int, long*, long*)
  XPCWrappedNative::GetAttribute(XPCCallContext&)
   .L1287
    NS_InvokeByIndex_P
     nsMsgDBFolder::GetServer(nsIMsgIncomingServer**)
      nsCOMPtr::swap(nsIMsgIncomingServer*&)

I just need to look for the JS code that calls nsIMsgFolder.server. There's only… a bit more than 100 of those. Furthermore, the leak didn't seem to stay, so I chalked it up to some sort of GC thing and moved on. (It actually was a valid leak in that the server was left with a reference to a JS object referring to the server again... but I fixed that after I realized what was going on)

In any case, it did leave with an extreme sense of frustration at debugging the leak. Seeing all those js_Invokes lining the stack was the worst part, as the information so is tantalizingly close, yet just out of reach. So I naturally reiterated an opinion I've had for a while: "Why not just integrate JS stacks in the stack trace?" The problem with that is that most tools have different ways of walking the stack…

But wait! There is one place in Mozilla code where there's a common way to walk the stack: nsStackWalk. Therefore, it might be possible that I could coerce that code a little to replace each js_Invoke with the information for the JS function it's actually calling. And, success! With some caveats:

  • It only works in the one definition I have access to (x86 gcc Linux).
  • It relies on being able to tell that I'm calling js_Invoke during the stack trace, i.e., the symbols must be in the same binary.
  • It doesn't do function names, only filenames and line numbers (better than nothing!).
  • It makes xpcom/base depend on js (but not xpconnect!).
  • It relies on js_Invoke's first function parameter being the JSContext *, and relies on the cdecl function call (i.e., the parameter is the one right above the return address).

It's not perfect, not even review-ready, but it's usable.

If you don't get the title, it's parodying this relatively popular internet meme. Without any pictures, though