terriko: (Default)
2024-09-27 06:00 pm

Best practices in practice: Black, the Python code formatter

This is crossposted from Curiousity.ca, my personal maker blog. If you want to link to this post, please use the original link since the formatting there is usually better.


I’m starting a little mini-series about some of the “best practices” I’ve tried out in my real-life open source software development. These can be specific tools, checklists, workflows, whatever. Some of these have been great, some of them have been not so great, but I’ve learned a lot. I wanted to talk a bit about the usability and assumptions made in various tools and procedures, especially relative to the wider conversations we need to have about open source maintainer burnout, mentoring new contributors, and improving the security and quality of software.





So let’s start with a tool that I love: Black.





Black’s tagline is “the uncompromising Python code formatter” and it pretty much is what it says on the tin: it can be used to automatically format Python code, and it’s reasonably opinionated about how it’s done with very few options to change. It starts with pep8 compliance (that’s the python style guide for those of you don’t need to memorize such things) and takes it further. I’m not going to talk about the design decisions they made but the black style guide is actually an interesting read if you’re into this kind of thing.





I’m probably a bit more excited about style guides than the average person because I spent several years reading and marking student code, including being a teaching assistant for a course on Perl, a language that is famously hard to read. (Though I’ve got to tell you, the first year undergraduates’ Java programs were absolutely worse to read than Perl.) And then in case mounds of beginner code wasn’t enough of a challenge, I also was involved in a fairly well-known open source project (GNU Mailman) with a decade of code to its name even when I joined so I was learning a lot about the experience of integrating code from many contributors into a single code base. Both of these are… kind of exhausting? I was young enough to not be completely set in my ways, but especially with the beginner Java code, it became really clear that debugging was harder when the formatting was adding a layer of obfuscation to the code. I’d have loved to have an autoformatter for Java because so many students could find their bugs easier once I showed them how to fix their indents or braces.





And then I spent years as an open source project maintainer rather than just a contributor, so it was my job to enforce style as part of code reviews. And… I kind of hated that part of it? It’s frustrating to have the same conversation with people over and over about style and be constantly leaving the same code review comments, and then on top of that sometimes people don’t *agree* with the style and want to argue about it, or people can’t be bothered to come back and fix it themselves so I either have to leave a potentially good bug fix on the floor or I have to fix it myself. Formatting code elegantly can be fun once in a while, but doing it over and over and over and over quickly got old for me.





So when I first heard about Black, I knew it was a thing I wanted for my projects.





Now when someone submits a thing to my code base, Black runs alongside the other tests, and they get feedback right away if their code doesn’t meet our coding standards. It hardly any time to run so sometimes people get feedback very fast. Many new contributors even notice failing required test and go do some reading and fix it before I even see it, and for those that don’t fix issues before I get there I get a much easier conversation that amounts to “run black on your files and update the pull request.” I don’t have to explain what they got wrong and why it matters — they don’t even need to understand what happens when the auto-formatter runs. It just cleans things up and we move on with life.





I feel like the workflow might actually be better if Black was run in our continuous integration system and automatically updated the submitted code, but there’s some challenges there around security and permissions that we haven’t gotten around to solving. And honestly, it’s kind of nice to have an easy low-stress “train the new contributors to use the tools we use” or “share a link to the contributors doc” opening conversation, so I haven’t been as motivated as I might be to fix things. I could probably have a bot leave those comments and maybe one of those days we’ll do that, but I’m going to have to look at the code for code review anyhow so I usually just add it in to the code review comments.





The other thing that Black itself calls out in their docs is that by conforming to a standard auto-format, we really reduce the differences between existing code and new code. It’s pretty obvious when the first attempt has a pile of random extra lines and is failing the Black check. We get a number of contributors using different integrated development environments (IDEs) that are pretty opinionated themselves, and it’s been freeing to not to deal with whitespace nonsense in pull requests or have people try to tell me on the glory if their IDE of choice when I ask them to fix it. Some python IDEs actually support Black so sometimes I can just tell them to flip a switch or whatever and then they never have to think about it again either. Win for us all!





So here’s the highlights about why I use Black:





As a contributor:






  1. Black lets me not think about style; it’s easy to fix before I put together a pull request or patch.




  2. It saves me from the often confusing messages you get from other style checkers.




  3. Because I got into the habit of running it before I even run my code or tests, it serves as a quick mistake checkers.




  4. Some of the style choices, like forcing trailing commas in lists, make editing existing code easier and I suspect increase code quality overall because certain types of bug are more obvious.





As a an open source maintainer:






  1. Black lets me not think about style.




  2. It makes basic code quality conversations easier. I used to have a *lot* of conversations about style and people get really passionate about it, but it wasted a lot of time when the end result was usually going to be “conform to our style if you want to contribute to this project”




  3. Fixing bad style is fast, either for the contributor or for me as needed.




  4. It makes code review easier because there aren’t obfuscating style issues.




  5. It allows for very quick feedback for users even if all our maintainers are busy. Since I regularly work with people in other time zones, this can potentially save days of back and forth before code can be used.




  6. It provides a gateway for users to learn about code quality tools. I work with a lot of new contributors through Google Summer of Code and Hacktoberfest, so they may have no existing framework for professional development. But also even a lot of experienced devs haven’t used tools like Black before!




  7. It provides a starting point for mentoring users about pre-commit checks, continuous integration tests, and how to run things locally. We’ve got other starting points but Black is fast and easy and it helps reduce resistance to the harder ones.




  8. It reduces “bike shedding” about style. Bikeshedding can be a real contributor to burnout of both maintainers and contributors, and this reduces one place where I’ve seen it occur regularly.




  9. It decreases the cognitive overhead of reading and maintainin a full code base which includes a bunch of code from different contributors or even from the same contributor years later. If you’ve spent any time with code that’s been around for decades, you know what I’m talking about.




  10. In short: it helps me reduce maintainer burnout for me and my co-maintainers.





So yeah, that’s Black. It improves my experience as an open source maintainer and as a mentor for new contributors. I love it, and maybe you would too? I highly recommend trying it out on your own code and new projects. (and it’s good for existing projects, even big established ones, but choosing to apply it to an existing code base gets into bikeshedding territory so proceed with caution!)





It’s only for Python, but if you have similar auto-formatters for other languages that you love, let me know! I’d love to have some to recommend to my colleagues at work who focus on other languages.

terriko: (Default)
2014-04-26 11:33 am
Entry tags:

Mailman 3.0 Suite Beta!

I'm happy to say that...


Mailman logo

Mailman 3.0 suite is now in beta!

As many of you know, Mailman's been my open source project of choice for a good many years. It's the most popular open source mailing list manager with millions of users worldwide, and it's been quietly undergoing a complete re-write and re-working for version 3.0 over the past few years. I'm super excited to have it at the point where more people can really start trying it out. We've divided it into several pieces: the core, which sends the mails, the web interface that handles web-based subscriptions and settings, and the new web archiver, plus there's a set of scripts to bundle them all together. (Announcement post with all the links.)

While I've done more work on the web interface and a little on the core, I'm most excited for the world to see the archiver, which is a really huge and beautiful change from the older pipermail. The new archiver is called Hyperkitty, and it's a huge change for Mailman.

You can take a look at hyperkitty live on the fedora mailing list archives if you're curious! I'll bet it'll make you want your other open source lists to convert to Mailman 3 sooner rather than later. Plus, on top of being already cool, it's much easier to work with and extend than the old pipermail, so if you've always wanted to view your lists in some new and cool way, you can dust off your django skills and join the team!

Hyperkitty logo

Do remember that the suite is in beta, so there's still some bugs to fix and probably a few features to add, but we do know that people are running Mailman 3 live on some lists, so it's reasonably safe to use if you want to try it out on some smaller lists. In theory, it can co-exist with Mailman 2, but I admit I haven't tried that out yet. I will be trying it, though: I'm hoping to switch some of my own lists over soon, but probably not for a couple of weeks due to other life commitments.

So yeah, that's what I did at the PyCon sprints this year. Pretty cool, eh?
terriko: (Default)
2013-10-17 03:32 pm
Entry tags:

Book review code

One of the things that bugs me when I'm doing book reviews is that I prefer it when reviews have a picture of the cover and link to the book of some sort, but I didn't love the output from Amazon's referal link generator, which would have been the easiest solution. I've been doing it manually, but that's a lot of cut and pasting and I kind of abhor doing tasks that are easy to automate.

Thankfully, I'm a coder and a user of greasemonkey, so I have all the skills I need to automate it. Seriously, being able to tweak web pages to suit my own needs is the greatest thing.

In the spirit of sharing, here's the script I'm using to generate the code I wanted for my reviews using the book page on LibraryThing:

// ==UserScript==
// @name        Book review header generator
// @namespace   tko-bookreview
// @description Takes any librarything book page and gives me a nice link to the book with cover and author details
// @include     http://www.librarything.com/work/*
// @version     1
// @grant       none
// ==/UserScript==

// Get all the data we'd like to display at the top of a review
var coverimage = document.getElementById('mainCover').outerHTML;
var title = document.getElementsByTagName('h1')[0].innerHTML;
var author = document.getElementsByTagName('h2')[0].innerHTML;
var librarythinglink = document.URL; 


// Trim down the title and author info
title = title.replace(/ *<span .*<\/span>/, '');

author = author.replace(/href="/, 'href="http://www.librarything.com');
author = author.replace(/<hr>/, '');

// Generate the code for this book
var reviewheader = '<a href="' + librarythinglink + '">' + 
   coverimage + '<br />' +
   '<b>' + title + '</b></a> ' +
   '<em>' + author + '</em>';

// Add code around this for embedding it into the page
var textbox = '<h4>Review Code</h4>' +
	'<textarea name="embedHTML" onFocus="this.select();" rows="5" ' + 
	'style="width: 250px;" wrap="virtual">' + reviewheader + '</textarea>';


// Find a good spot and add it to the page
var insert = document.getElementsByClassName('gap')[0];
insert.outerHTML =  textbox + insert.outerHTML;


Please feel free to consider this open sourced and free for any type of use: alter it to suit your needs as you will!

Edit: Github link, for those so inclined.
terriko: (Default)
2011-11-22 04:44 pm
Entry tags:

How much math do you need to write code?

I got a really interesting query today that boiled down to, "How much math do you need to write code?"

The short answer to this is, "Not that much" or perhaps "it depends on what you want the code to do." But here's part of what I actually wrote back:

---

To be honest, the level of math required to write code is pretty small. A grade school understanding is often sufficient; there's a reason we can teach 7 year olds to program! Modern programming languages are much less math-oriented: I once spent an afternoon teaching my then 11 year old sister and her friends how to write dynamic database-driven websites, and the only math they used was to add up the scores on the "what animal are you most like?" quizzes they wanted to write.

The math in computer science comes a lot later: for deeper analysis of algorithms and running time, we use algebra and mathematical proofs in an academic setting. But... to tell the truth, relatively few programmers need or use this kind of deeper understanding in their day-to-day jobs. And in my experience teaching students, many people find this stuff easier to learn by doing, so they only really begin to grasp it *after* they have gotten comfortable writing programs.

In short: you probably have all the math skills you need to write code, and if you decide you want to do more hardcore CS later, it'll be easier to learn the math along the way anyhow!

---

There's some nuance there that I didn't really tease out -- the deeper understanding of algorithms and program behaviour is what characterizes the real "science" out of computer science. And maybe the world would be a better place if more programmers did actually use deeper analysis in their day-to-day jobs. But you don't have to be an academic-style computer scientist to write code! Still, it's a very interesting question, given that historically programming actually did require a lot more math, and our perceptions and stereotypes haven't really kept up with the reality of the field.

Perhaps it's time for me to write another presentation? ;)

(For context: my old slideshow about women, computing and math got included in this TechCrunch post about Racism and Meritocracy, so I've been getting a lot of mail, including the one that spawned this post.)
terriko: (Default)
2011-06-26 12:24 pm
Entry tags:

Upgrading fink from mac os X 10.5 to 10.6

More notes from getting myself set up to write code:

The fink project has a page about upgrading from 10.5 to 10.6 with fink.

It's very easy to get distracted by the nice step-by-step description that takes up most of the page.

The pertinent bit of information is at the top, though:

you will probably find it easier to do a clean install from source instead.


I probably should have just done that first, since the lovely instructions didn't work at all for me. Oh well.
terriko: (Default)
2011-06-26 10:27 am
Entry tags:

hasAttribute deprecated? using querySelector.

I have a Firefox add-on I made several years ago to help me explore page composition and generate (theoretical) web security policies, and I decided to pull it out of storage and see if it could still be helpful. Of course, my browser decided to update Right Then, and I decided it wasn't worth fighting to stop it from doing so.

So I updated the add-on so that it included versions 5.* and actually, it mostly still worked (despite having been written for, I believe, a very early version of Firefox 3, or maybe a late version Firefox 2? This is one of my earliest add-ons.) except that apparently hasAttribute/getAttribute doesn't exist anymore.

I can't seem to find anywhere telling me that they've been deprecated, and more importantly, what I should be using instead, which is irritating. But the end result is that it doesn't work, so I needed to find something else. It looks like the solution for at least some of my code is to instead use a querySelector to look for all elements with that attribute.

Of course, I never seem to want to do exactly what the darned examples show. So in case you're like me, the way to search for any tag with a given attribute using querySelector is like this:

document.querySelectorAll("*[myattribute]");

And if you wanted to search just a specific type of tag, then you'd specify that instead of *. So if you were looking for the alt tags for every image, you'd do...

document.querySelectorAll("img[alt]");

But I'm concerned by this note in the querySelectorAll documentation, which tells me that it "Returns a non-live NodeList of all elements descended from the element on which it is invoked that match the specified group of CSS selectors."

There's a big warning elsewhere that it's non-live too, unlike other such methods. So my questions are... why is it non-live, and what do I need to do to get a live list? For my particular purpose at the moment I don't think I need it to be live, but for some of the older code that I might want to update in the future I probably do.

I'm mostly just recording this for my own reference later, but if someone happens to be able to tell me if there's another function that more directly replaces hasAttribute, or there's a good way to get a live list of elements with a given attribute, I'd love to know!
terriko: (Default)
2010-10-26 06:39 pm
Entry tags:

More pumpkins! More interface hacks!

Another flickr interface hack test:

Pumpkins chez Dan 2010

IMG_1075IMG_1076Glowing vodka skullIMG_1080IMG_1081IMG_1082
IMG_1085IMG_1086IMG_1087IMG_1088IMG_1091IMG_1092
IMG_1093IMG_1094IMG_1095IMG_1096IMG_1097IMG_1098
IMG_1099IMG_1101IMG_1102IMG_1103IMG_1104IMG_1105
IMG_1106IMG_1107IMG_1108IMG_1109IMG_1110IMG_1111
IMG_1112IMG_1113IMG_1114IMG_1117IMG_1119IMG_1123
IMG_1124IMG_1129IMG_1131IMG_1132IMG_1135IMG_1137

This gives me a box with code for entire set of photos as thumbnails in an Nx6 grid. Again, no clue if it's going to break RSS/layouts/feed readers, so please let me know if it does.

Here's the code:


// ==UserScript==
// @name           Blog flickr set
// @namespace      tko-flickr-set
// @description    Make cut and paste code for blogging entire sets of flickr photos as thumbnails
// @include        http://www.flickr.com/photos/*/sets/*
// ==/UserScript==

var thumbsHTML = document.getElementById('setThumbs');

var allImages = thumbsHTML.getElementsByTagName('a');
var title = document.title.replace(/ - a set on Flickr/, '');

var code = '<h2><a href="' + location.href + '">' + title + '</a></h2>';

for (i = 0; i < allImages.length; ++i) {

	code += '<a href="' + allImages[i].href + 
	'" title="' + allImages[i].title + '">' +
	allImages[i].innerHTML + '</a>';

	if (i > 0 && (i+1) % 6 == 0) {

		code += '\n';
	}
}

// Insert after the date
var insertPlace = document.getElementsByClassName('vsDetails')[0];

var newBox = '<h4>Embed Code</h4>' +
	'<textarea name="embedHTML" onFocus="this.select();" rows="5" ' +

	'style="width: 250px;" wrap="virtual">' + code + '</textarea>';

insertPlace.innerHTML = insertPlace.innerHTML + newBox;



terriko: (Default)
2010-10-26 05:14 pm
Entry tags:

Pumpkin photo and my flickr interface hack




I'm testing out my greasemonkey script which generates boxes with the HTML for posting a flickr photo with title/caption, so you all get a picture of a pumpkin. It is the end of October, after all!

The script is still brittle if the interface changes, but it is just a little interface hack so I'm not too concerned about it. I'll just rehack if necessary, after all! What it does is makes a set of 3 boxes down the right hand side of the page containing HTML for cutting and pasting the photo with the title as a caption (the default code Flickr gives you doesn't include a caption, and I find the menus kind of irritating if I'm posting a lot of photos in one day).

Here's the script. You should be able to cut and paste it into greasemonkey if you want to use it yourself. (And here's to hoping that all these font colour, size and layout tricks won't break everyone's feed readers/friends pages/layouts!)


// ==UserScript==
// @name           Flickr Blog HTML
// @author         Terri Oda -- http://terri.zone12.com
// @namespace      tko-flickr
// @description    Adds a box with cut-and-paste code for blogging images
// @include        http://flickr.com/*
// @include        http://www.flickr.com/*
// ==/UserScript==


// Get all that necessary photo info
var img = document.getElementsByClassName('photo-div')[0].getElementsByTagName('img')[0];

var title = document.getElementsByClassName('photo-title')[0].innerHTML;

var url = location.href;
var imgsrc = img.src.replace(/_z\.jpg/, '.jpg'); 
	// we want the smaller of the medium photos for most blogging purposes


// find the username for credit
var userHTML = document.getElementsByClassName('username')[0].getElementsByTagName('a')[0];

var user = userHTML.innerHTML;
var userUrl = userHTML.href;


// Make that cut and paste-able code
var code = '<div style="float: right; margin-left: 10px; margin-bottom: 10px;">' +
	'<a href="' + url + '" title="' + title + '">' +

	'<img src="' + imgsrc + '" alt="' + title + 
	'" style="border: solid 2px #000000;" /></a>' +

	'<br /> <span style="font-size: 0.9em; margin-top: 0px;">' + 
	'\n<a href="' + url + '">' + title + '</a> <br />' + 
	'by <a href="' + userUrl + '">'+ user + 
	'</a>.</span></div><br clear="all" />';

var codeSmall = code.replace(/\.jpg/, '_m.jpg'); 
	// I'm amused how small is _m, but whatever works!

var noExtras ='<a href="' + url + '" title="' + title + '">' +

	'<img src="' + imgsrc + '" alt="' + title + '" /></a>';

// figure out where to put it
// this puts it right after the "this photo belongs to..." so I don't have to scroll much.
var insert = document.getElementsByClassName('secondary-contexts-label')[0];

// Make the actual box
var newBox = '<h4>Embed Code</h4><h5>Medium</h5>' +

	'<textarea name="embedHTML" onFocus="this.select();" rows="5" ' + 
	'style="width: 250px;" wrap="virtual">' + code + '</textarea>' + 
	'<h5>Small</h5>' + 
	'<textarea name="embedHTML" onFocus="this.select();" rows="5" ' +

   'style="width: 250px;" wrap="virtual">' + codeSmall + '</textarea>';
var noExtrasBox = '<h5>No Extras</h5>' +

	'<textarea name="embedHTML" onFocus="this.select();" rows="5" ' +
   'style="width: 250px;" wrap="virtual">' + noExtras + '</textarea>';

// Add it to the page
insert.innerHTML = newBox + noExtrasBox + insert.innerHTML;


terriko: (Default)
2010-01-17 02:45 am
Entry tags:

Backing up Dreamwidth entries using DWSM

I decided it was time to start backing up my dreamwidth entries. After looking at some of the available clients I decided the quickest way to do this was probably going to be a shell script, and thankfully there was a list of tools for the purpose of backing up livejournal entries.

So, I chose the one that seemed to back up the most stuff, LJSM, and tweaked it for Dreamwidth. This wasn't that much work (I needed to change livejournal.com to be dreamwidth.org in one place, then I needed to fix it so the titles were set correctly in the index) but in case anyone else wants it, here's my modified version, DWSM:

http://terri.zone12.com/code/dwsm.pl

I'm sure I'm not the only lazy person out there who'd do more backups if they didn't have to think too much about it. I think everyone's new year's resolutions should include "make more backups" and I'm doing my part to make this a reality. So here you go: one less excuse!

Instructions



Download DWSM: http://terri.zone12.com/code/dwsm.pl

Basically, you need perl and you need to know how to run stuff from the command line. If this makes no sense to you, you might want to ask someone else for help. For those you know what I'm talking about, you'll want to run something like:

./dwsm.pl -a -u terriko:password terriko

Only you need a real password and probably you'll want to supply your own username in both places. Or only the first if you really want a copy of my journal. Or you can set the second one to any journal name if random acts of backup are your thing. Grab all your friends' journals and print a newspaper! Automate it to run every day and never think about backups again! Whatever. You have fun there!
terriko: (Default)
2009-10-14 12:08 am
Entry tags:

Coding brain != reading brain?

The exhaustion/stress from fixing crud and trying to get my thesis done at the same time hit me hard today, so I came home at 4pm and immediately fell asleep.

As these things usually go, this resulted in me awakening sometime later, still feeling like a zombie, but unable to go back to sleep. I completely failed to read a magazine because I found myself skimming before I'd read a couple of sentences. So I figured I'd go mess about with flickr... time flies, and I find I've written a greasemonkey script making it easier for me to blog photos. Which is fine, except how the heck does it work that I can't concentrate long enough to read two sentences, yet I can write JavaScript code just fine?

I am concerned that in the dystopian future, some evil megacorp will take advantage of this and generate worker drones who are incapable of reading but perfectly good at writing code.

No, wait, that's just the exhaustion talking. In that spirit, though... Have some tentacles, and I'm going back to bed:


terriko: (Default)
2009-08-14 01:02 am
Entry tags:

Why DON'T we teach computer science earlier?

My friend Gail and I stopped by the Girls@VV (the girls-only version of a local science/engineering summer camp) to give them a presentation on computer science. Gail already has an excellent write-up of our chat with the girls on her blog.

One of the things we asked the girls about is what we could do to encourage more young women to explore computer science, and a very prominent suggestion was that we start teaching it earlier, so people have some idea of the possibilities.

So it got me thinking, why don't we start earlier? I taught my sister how to program when she was in elementary school. One of my friends always asserts that I shouldn't generalize based on my sister and her friends, who are incredibly smart and exceptional people, but honestly programming isn't that difficult. My brother and I learned at 13 from a book for kids. So why don't the schools teach it?

Here's some reasons I've been told in the past:


  1. Teachers don't have the time. This is especially true at the elementary level, as illustrated by Diane Scaiff's excellent summary of teachers work hours in Ontario. Adding stuff to the curriculum takes time that many teachers just don't have.

  2. Schools don't have equipment. Computers are expensive to buy, maintain, and they are common targets for theft.

  3. People think computer science is hard. Often they think it requires advanced math. You do not need significant math skills to program, despite this perception. When I was teaching basic programming to my sister's friends, we started with web quizzes. The only math was simple addition. But this perception intimidates a lot of people who haven't tried it.

  4. Teachers don't have the knowledge and skills required to teach computer science. And, as stated before, they don't have time to learn and may be intimidated by the perception that computer science is incredibly difficult. This is especially true since many elementary school teachers feel that they are weak in math (at least according to the gentleman who started JUMP math tutoring).

  5. People don't think kids will be able to do more "advanced" stuff. This irks me. Kids are a whole lot smarter and more capable than many people take them for.


As you might guess, this isn't just relevant to computer science. My parents, who are biochemists, hit some of the same roadblocks when they wanted to make sure I got a good science education from a young age. They found ways around it and ways to supplement my education.

And what you might not realise (but I think the girls did) is that because this stuff isn't taught in the schools, girls especially aren't getting exposed. Guys often seem to get exposed to computer science in other ways, but more women rely upon the curriculum. (A recent study suggests that girls may have less spare time than boys, which is one reason that might explain this.) So while this extra education could help all children, it's likely to be especially helpful to girls.

So, I'm going to leave you all with two questions:


  1. Why else don't we teach younger children computer science?

  2. What can we do to alleviate these problems?



I obviously have opinions and suggestions on number 2 (For example, freely available materials like the CS Unplugged activity we ran this morning!), but I'd like to see what other people think first.
terriko: (Default)
2009-08-07 04:27 pm
Entry tags:

And disappearing error messages too!

I forgot to mention my favourite issue in my previous post about JavaScript and Firefox extension development.

Sometimes, magically, your entire log on the error goes poof! 'cause, you know, it wasn't hard enough to debug.

I'm pretty sure the error log goes poof if you try to print something undefined to it, but there may be other cases where it does.

Special.
terriko: (Default)
2009-08-07 02:45 pm
Entry tags:

Writing Firefox Extensions in JavaScript (or possibly in the dark ages)

I'm working on a Firefox extension.

For those of you who have not attempted this, let me tell you a few things about the experience:

(a) I'm working in JavaScript. JavaScript likes to fail gracefully, which means that it doesn't tend to spew error messages every time something goes wrong. That's nice if you're using it, but annoying when you're trying to track down an error.

(b) And then, in case it wasn't quiet enough, I put it into an add-on, where it's even more silent, and on top of that I can't bring my usual JavaScript debugging tools to bear on it because they only operate on the code in a web page.

So basically, I've been programming for the past few days without all the usual modern coding conveniences. I have been reduced to debugging almost entirely from the equivalent of printf or echo. Thank goodness I at least have syntax highlighting. To use a terrible analogy, this is akin to writing everything on a typewriter -- better than a quill and ink perhaps, but still not quite up to the modern computer when it comes to the easy fixing of mistakes.

I've lost track of the number of times where I've deleted my non-working code, retyped it all, only to find that this time, it works. The problem before was almost certainly a typo, but it was less trouble to re-write than try to find the missing character. Incredibly frustrating.

That said, I actually kinda like Firefox extension development, even if the minutiae are irritating. It's incredibly satisfying when it works, and I can then try my code out on any web page I want, really easily. So much data. And the idea that other people will be able to install my code is surprisingly appealing. (Well, perhaps not that surprising -- I used to write IRC scripts back in the day.)

But I do feel a little like I'm the dark ages here, and I find it hard to believe that other people placidly program in this environment. So I'm guessing there are tools out there, I just don't know them. Last time I tried any was probably pre Firefox 2.0, and I wasn't thrilled, but I'd be happy to take some recommendations now if things have gotten better now that we're up to 3.5!