I've just completed a first-draft, unstable, patch implementing a XPath generator in native mozilla.org code. (It is highly unstable, so unless you're a developer willing to help fix bugs in it, don't use it.) It's been a marathon for me, writing a component from scratch with (until now) only peripheral experience in C++. I'm sure there are many in #developers who can attest to the large number of first-timer mistakes I've begged for help on.
As for the title of this blog entry, I'm pretty sure it's accurate. First, you start off with a lot of pain. Read the "Full Article" link for a list.
#ifdef DEBUG
const char* realHash = NS_LossyConvertUTF16toASCII(hashKey).get();
printf("hashKey: '%s'\n", realHash);
#endif
All this, just for the first draft. An experienced C++ developer reading this will probably chuckle ruefully at having gone down this sort of road before. What makes this so much harder for me is that this is literally my first attempt at writing a major C++ based tool. Until now, my major tools have been chrome or JavaScript-based tools. I've done smaller fixes in C++ code before (I implemented Attr.isId specifically for the XPath generator). But for me, this is a giant leap. Believe me, I'm not Superman.
As for the working-out analogy: You start out with a lot of pain. The exercises are not fun. When you go home at the end of the first day, you're sore, tired, and thinking you don't want to go back. But you go back anyway, because you know it's the right thing to do.
A few days later, you're doing better. You're starting to get a feel for how it's done. The workouts start becoming easier. You come back with better abilities, and you don't have to ask for help on every little thing. You start to experiment, try to lay down some patterns to follow.
Finally, it becomes so routine that you look for ways to branch out and do other stuff. You don't have to ask for help; you just do it, and you feel good. Really, really good. Pretty soon, you're casually talking with other people just starting out, giving them little tips from your own experience where you made a big mistake and paid for it.
That's where the analogy ends for me; I haven't gotten further in my gym workouts than this third stage, so I can't explain how it feels. On C++, I'm probably at the second stage. There are probably four or five other stages in the pipeline, some in between the stages I list here, but you get the idea. It's a lot of work. But ultimately, it does pay off.
With that, I'm going to bed. I think that, when all is reviewed and super-reviewed, I will finally go get the CVS checkin privileges which I would need to land this patch. It's just time.
Posted by WeirdAl at February 11, 2006 11:51 PMI'm puzzled about the nsISecurityCheckedComponent vs. nsIDOMClassInfo. Could you elaborate on that one?
(From Alex: Perhaps in a later blog entry. Both need to be documented on DevMo. Drop me an e-mail sometime in the next few days, not today, and I'll see what I can do.)
Posted by: Axel Hecht at February 12, 2006 5:18 AM
#ifdef DEBUG
const char* realHash = NS_LossyConvertUTF16toASCII(hashKey).get();
printf("hashKey: '%s'\n", realHash);
#endif
For some strings it may be simpler than this; all the nsC*String classes as far as I know let you get away with this (at least, since 2004 and Darin's string code update):
nsCAutoString foo = NS_LITERAL_CSTRING("foo");
printf("foo: %s\n", foo.get());
Presumably you were working with |PRUnichar| strings far more than with |char| strings and thus this wouldn't have been useful in your case, but the last time I wrote any major code I was working with C strings the entire time and found it invaluable.
Posted by: Jeff Walden at February 12, 2006 6:30 AM(By the way, I'm totally unclear why it's happening, but I'm being told I'm a first-time commenter every time I say something here, so all my posts seem to be delayed. Either that message should be changed to be more accurate or the configuration option should be fixed so my comments actually do get posted without delay. And by the way, feel free to remove this comment after dealing with it, if you so choose. :-) )
(From Alex: No, it's quite deliberate, actually. I had to change my blog settings so that I personally approve all comments that show up in public. That blocks the spam from getting through.)
Posted by: Jeff Walden at February 12, 2006 6:31 AM>#ifdef DEBUG
>const char* realHash = >NS_LossyConvertUTF16toASCII(hashKey).get();
>printf("hashKey: '%s'\n", realHash);
>#endif
Actually, that's wrong. You need to either not use the temporary ptr, or have the S_LossyConvertUTF16toASCII object live at least as long. As written, the code can crash depending on allocation patterns.
Posted by: Boris at February 12, 2006 11:42 AM