Categories
JavaScript Writing

Learning JavaScript errata

Recovered from the Wayback Machine.

If wishes were horses, book authors would have a herd. All too often you see the ‘oops’ and such only after the book is in print. In my case, I’ve worked with JavaScript for so long (since the very beginning) I brought along a couple of bad habits that made it into the book.

One new errata that is going in for the book is the following:

Several examples in the book use document.write, but with an XHTML doctype. The document.write or document.writeln functions do not work with XHTML when the page is served with the application/xhtml+XML MIME type. The examples in the book work with the most common browsers because the examples have an .htm extension. These pages are served up with an HTML MIME type, regardless
of which DOCTYPE was used, therefore the use of document.write or innerHTML does not fail. When the page is loaded with an XHTML MIME Type, though, the examples will fail.

The examples will work in the most common browsers, and to ensure they continue to do so, you can change the DOCTYPE to an HTML one, though you’ll need to modify automatic closings such as that on the meta tag (remove the ending ‘/’) if you want them to validate.

The author is apologetic for not explaining this in Chapter 1. The alternative is to use the DOM to create new page elements and append to the document, but since this wasn’t covered until later in the book, document.write was used instead.

Typically, you’ll want to use the DOM, just because this ensures the examples work fully with XHTML, as well as HTML. To see this demonstrated more fully, the author is working on modified examples using DOM calls and ensuring the examples work as XHTML. As soon as these are finished, they will be posted and a note added to this errata page.

In this, the DOCTYPE is XHTML but the page is served up as HTML. As Anne Van Kesteren succinctly puts it it doesn’t matter what DOCTYPE you use if the page is served up as text/html. And yes, I am using document.write and innerHTML, bad me.

I don’t necessarily share in the universal condemnation of document.write or innerHTML, especially when you’re learning. I have 98 examples in the book, and a simple document.write sure saves on book space rather than having to use the DOM to get document, and use create element and create text node and append and yada yada. What I should have done, though, is create a library and make my own version of ‘write’ that is XHTML friendly, and used this. Note, though, that in the book I don’t cover the DOM until chapter 11, so the only alternatives I had were document.write or an alert, and the latter doesn’t work if you’re using focus and blur events.

However, in pages where I used document.write, I should have used an HTML DOCTYPE, and also made mention of document.write and its incompatibility with XHTML. I should also have covered this in more detail in chapter 1. I should have also covered quirks mode in more detail in chapter 1.

As for innerHTML, now that one is open for debate. There’s bunches of Ajax developers who will only give up their innerHTML if you pry if from their cold, dead browser. BUT, it’s also not XHTML friendly, though it is the handiest darn thing (and again, one could create a library alternative).

The reason why these are a problem is they both allow us to add XHTML formatted data directly to the document, but without going through the XHTML validation process. When one serves valid XHTML, one doesn’t want one’s page developer putting crufty XML or HTML into one’s perfectly lovely XML formatted document. Gives one heartburn, causes one to tear hair out, does odd things to one’s browser and so on.

For now, I asked O’Reilly to put in this errata. Next, I’m going through all of the examples and updating them to be more forward looking and using the DOM, only. These will be provided as secondary downloads, because comparing the two–the original example and the modified–is a learning experience in itself.

The use of document.write and innerHTML is incidental to most examples. I only used such to print some result out or demonstrate some other feature of JavaScript. Still, if I’m going to stress best practices, I blew it with both of these. All I can say is I think it is a good book regardless, these errors aren’t that common or that essential, and mea culpa. Twenty lashes with Firebug.

Here’s a discussion on the problem and code workaround. Note that both Google Maps and Google’s adSense use document.write, so I’m in good company–the use of these really are ubiquitous, but NOT a best practice, so no excuse for me.

Categories
JavaScript Writing

New Year

Recovered from the Wayback Machine.

I just posted a note at Mad Techie Woman about an error in the Learning JavaScript book I could kick myself for. It has to do with quirks mode, and the fact that browsers interpret an XHTML document as HTML when served with an .htm extension, and the fact that I used document.write as a way of doing a quick print out of a JS example. Sure it works now, but it’s a bad habit to get into and I shouldn’t have done so.

Some people might think it’s easy to write on JavaScript because it’s not a ‘real’ language, but it’s actually the opposite: an extremely difficult language to write about because the environment that surrounds it is in a constant state of flux. People use old browsers, new browsers, old markup, new markup, old styling, new CSS, and so on. When you’re writing on C++ or Java, there is a minimum level of compliance that must be met or the damn language just doesn’t work.

Not with JavaScript, oh no, siree. You can do almost anything and it will work with most browsers, as they labor mightily to ensure applications, old and new, work. Rightfully so, but as in the case of my “document.write”, you can get in a habit of using an easy and simple (and ubiquitous) piece of code, and it is not Right, or Best Practice, and when you realize what you’ve done (after the book is published, of course), you kick yourself ten ways to Sunday for Being So Stupid.

It’s lovely being an author with its constant reminders of how dumb you are. Or being a tech with the constant reminders of how much smarter that 18 year old is then you. It’s only followed by being a photographer whose work is received with silence, or a weblogger subject to so many variations of sneers and disdain that upon presenting ourselves as such, should be immediate grounds for a poor dear, at least. What is a weblogWhat is a weblog? It’s toilet paper. It’s the toilet paper we use to blot our blood, our tears, the sweat of our work, the grime of our living, the dirt of our dishing, and to fold into pretty swans when all is well (though don’t try to float these swams because they’re not meant to last).

You have to question the mental health of anyone who not only does any one of these acts, but does all four. And doesn’t get paid for two, and isn’t especially rolling in dough for the third and fourth (that 18 year old, you know).

That is the life of a writer of tech books, which is why most people only do one and then run, screaming. Why don’t I just place my head in the path of a truck, rather than go through the pain in dribbles and dabs. I’d made the news, then (“It sounded just like a ripe watermelon…”).

But this is about the New Year, not being an author or the pain of a thousand words we want to take back. I started to write a New Year post and got as far as the following:

I’ve been trying to come up with a last post for the end of the year, something positive and hopeful, but it seems like I keep putting up stories of anger or sadness.

I think that rather than being well informed via the internet, the constant stream of news batters at you until you eventually either give into the despair, or become completely indifferent. Years ago, when we got our news from the newspaper or the evening news, we had a chance to discuss the news, with friends, co-workers, family, before getting fed the next burst. Now, our friends are just as likely to be the source of the news as Fox or CBS, and we don’t talk as much as we broadcast at each other. It’s overwhelming.

I realized that rather than sounding optimistic or upbeat, I come across as hanging lower than a slug’s belly, and feeling about as oogie. Oogie. Yes, that is a word. It’s a beautiful word. I am an author and I can decree what is a word, and what is a beautiful word, and make it so in print. I’ve done so frequently.

Where was I? Slug’s belly. No one has an ‘excuse’ for being low, but I have traipsed legitimate steps down into the murky waters of Feeling Kinda Shitty, so I feel vindicated for my lowness, if not necessarily excused for same (“…people being excused as in, ‘there are people in the world who are tortured, imprisoned, forced to work at Google, who is now fashionably evil’, yada yada…”)

I worry and fret over every error in “Learning JavaScript”, have become obsessive with trying to ensure absolutely no error in “Adding Ajax”–a task that’s as impossible as it is imperative, because the Ajaxian world is not a tolerant world–and I’m facing a possible court battle against this country’s largest arbitration forum, without any legal help other than advice from Smart People (most of whom can’t recommend I take the action I’m planning because though it may end up helping lots of people in the end, it could end up costing me everything if the gamble fails).

Some people want a free computer from Microsoft; I’d settle for a good night’s sleep. Oh, and perky breasts again, which is as likely as getting anything truly free from Microsoft, or any other Big Corporation. (Free as in, ‘no strings attached’, which could, in an odd way, be used to describe my breasts).

Yet, yet, for all this doom and gloom (and “My God, Shelley, why do these things happen to you? Don’t you realize that weblogging is reserved for good times, marketing, or bleeding The Right Way; flowing gushily and with exquisite pain–not your tawdry drip drip, drip after inexorable drip: cut the vein, put yourself out of misery”)…I digress, yet for all this doom and gloom I wake, I eat, I pet my kitty, I walk in the sun, I correct the errors, I kick at the box I find myself in, I sneer as I’m sneered at in turn–I continue, because that’s what people do, you know; we continue. We’re all bleeding, and we trail metaphorical gore behind us, but we continue. To quote the good folks of Firefly, “That makes us mighty”.

So, from one of the Mighty to the rest of the Mighty, Happy New Year.

Categories
People Political

No slam dunk

Recovered from the Wayback Machine.

Norm Jenson came out with an endorsement of John Edwards:

John Edwards has announced his intention to run for President of the United States, that he is in favor of universal health care for every American is reason enough to support him, but equally important is that he is electable. I think he is overall the best candidate the Democrats have to offer. I urge you to join me in helping John make our dreams reality in 2008.

I am not so willing to vote for a head of chestnut hair, or skin so white he looks bleached. I guess both does make him ‘electable’ but not necessarily palatable. I heard Edwards talk about making things work, as he labored in a yard in New Orleans. Where was he six months ago? A year?

I tire of empty rhetoric from Democrats as well as Republicans. If someone mentions universal health care, then sit still for a minute and tell me how you plan to implement such, what steps you’ll take. All I hear from the Democrats now in charge in DC is is stay the course, and lookee now Democratic lobbyists can make the big bucks.

No person and no party has my vote in two years. They’ll have to earn it, and do more than curry favor with webloggers and wear a khaki shirt to do so. Universal health care, break up that stupid Homeland Security department, end our involvement in Iraq, because we’re just making it worse, let the gays marry instead of penalizing a small group of people for being different–these are just a start, a beginning. Edwards said that he’s for civil unions for gays but can’t wrap his mind around gay marriage. Well then, I’m for him as president, but can’t wrap my vote around the candidate who will get in the way.

I want to see change in two years. If I see more of the same, I swear to whatever deity rings your bell, I’ll vote for Cheney as a write in candidate, out of spite.

Categories
JavaScript

Prototype is not the de facto standard

Recovered from the Wayback Machine.

Ajaxian has a pushback at Prototype criticism. Among the criticism is:

A lot of javascript tutorials written today are based on the prototype framework. So, I thought it would be nice to see how other people use prototype.js . What I found is that the majority of people use it only because they think it is easier when in fact, they use only a couple of prototype functions ($() and the AJAX functions primarily).

This is a good point. If you’re only using Prototype to access a page element or make an Ajaxian server-side call, you’re not using Prototype to the fullest, and you’re better using your own homegrown.

I agree with Ajaxian, though, in that there is documentation on Prototype, though the creator of the library seems to be reluctant to make this known. Where I don’t agree with the writer, Rob, is his statement:

…although I’m disappointed to see that Sergio hasn’t updated his excellent reference since May, there are still so many fantastic howto’s and tutorials written using Prototype. Plus the books out now that base much of their code on Prototype.

Nope. My book, Adding Ajax, doesn’t. Covers it, yes, but also covers other libraries, too. More importantly, I create original JavaScript for all my examples so that a person can ‘see’ what’s happening without having to dig through the cryptic Ajax libraries, or without having to take a ‘leap of faith’. Then I demonstrate the examples using one library or another, Prototype among them, so the reader can learn how to use these, as well as write their own code–or do both. I don’t think a book author is doing the readers a service by making them dependent on one library that could go *poof* if the developer got bored with maintaining it. Yes, even a widespread use library like Prototype that’s open source.

I also dig into the libraries, exploring the code, and that includes Prototype because it does have some very clever implementations and nice use of JS. Still, I don’t just write “we’ll use Prototype for this” without explaining why. I don’t know of a lot of other Ajax books that are completely dependent on Prototype, either. Too much is changing in this environment to make folks dependent on one library or another.

I respect Prototype much more than I originally did when I first started using it. However, I still think that $() is confusing to new JavaScript developers, though it’s too widespread now to change. I also don’t fully understand why there isn’t a link to some form of documentation with the library.

Categories
Weblogging

The Giveaway

Recovered from the Wayback Machine.

I find it humorous that after the Blogger meeting with Bill Gates–where he walked into a room of bloggers, all of whom were using Apple laptops–Microsoft works with Acer to send out Windows laptops to webloggers. As Jeneane notes, primarily male webloggers (and I’ve not seen anything among the ASP.NET webloggers about them receiving anything from the company).

It was a foolish move if, for no other reason, they sent laptops to many people who can easily afford to buy a laptop. More, the same people who get offered so much anyway, creating a strong divide between the tiny haves and the many have-nots. A better approach would have been to provide a random drawing, a contest, or some other event if they wanted to provide webloggers with Windows laptops. Then the event would have generated attention without the acrimony.

That’s that not the point, though. Microsoft wanted to influence the influencers, tossing a few machines to some on the edges more as distraction (“See? Not everyone we gave one to is an A Lister.”) It was a rather amateurish act, and I have to wonder about these PR companies and their inability to get things right.

I don’t begrudge the folks getting one who could not afford such, and more power to them. I hope they keep the machines, because it would cruel to make them give up something that has become a real and unexpected treat. If you know such, then back off and let them enjoy something delightfully unexpected.

I do wonder, though, at those who have so much already who continue to take and take. The words “gluttony” and “greed” come to mind, but I’m sure that such surfacing is purely coincidence, webloggers being the selfless bunch that we are.

I did get a kick out of the Slashdot commentThis is typical MS behaviour – entirely immoral and calculating … and where do I sign up?

No, I did not get a machine. The only times I’ve been offered a freebie is when Clay Shirky and Tim O’Reilly and others offered to pay my plane ticket to an O’Reilly tech conference, though I would have to pay for my own hotel and food. That was back when I first started pointing out the fact that O’Reilly conferences had few women. Blogher did the same, but I think they were working on seeing I was fed and housed, ungrateful pup that I was.

Microsoft did offer to give me the deluxe treatment at the Search Camp Spa, back when I had blogging cred. I declined, forever banishing me to the hinterland of “those who don’t get it”. Literally it would seem.

Oh and folks who followed the old Burningbird weblog site have helped me out from time to time so I could keep the site running. See? It’s all your faults. You could have gotten rid of me years ago.

Ooops. Oops. I forgot, I did get a free gift.

When I wrote about lens cleaning and pointed folks to Copperhill and their lens cleaning kits, they were nice enough to send me a DVD cleaning kit as a note of appreciation. It has the cutest little iPod screen cleaner you’ve ever seen — just like a baby felt covered squeegee.

Oh god, now I’m forever tainted. I’ve failed Scoble’s and Arrington’s criteria for ethical webloggers. I will be known for now and forever as the Woman Who Took the Baby Felt Covered Squeegee and Didn’t Disclose.

This sucks. I feel so ashamed.