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
Writing

A critic’s value

Recovered from the Wayback Machine.

Sometimes I enjoy writing; other times, I hate being a writer.

For those of you who think it would be just wonderful to publish a book: think again.

There’s few things that can make you more vulnerable than to work your butt off on something and then have it trivialized, panned, and dismissed–usually by some anonymous pundit. Months of writing, months of editing and production work gets reduced in five minutes by a critic with an attitude.

One is tempted to reject all critics but there is value in criticism, even when such is unpalatable or unpleasant. Via 3QuarksDaily’s, I found the Boston Review article, Why Photography Critics Hate Photography to be an intriguing writing; especially the part on the critic’s rejection of the emotionalism of photography, and hence their suspicion of same:

Brecht was right. Photographs don’t explain the way the world works; they don’t offer reasons or causes; they don’t tell us stories with a coherent, or even discernible, beginning, middle, and end. Photographs live on the surface: they can’t burrow within to reveal the inner dynamics of historic events. And though it’s true that photographs document the specific, they tend, also, to blur—dangerously blur—political and historic distinctions: a photograph of a bombed-out apartment building in Berlin, circa 1945, looks much like a photograph of a bombed-out apartment building in Hanoi, circa 1969, which looks awfully similar to a photograph of a bombed-out apartment building in Baghdad from last week. Yet only a vulgar reductionist—or a complete pacifist—would say that these three cities, which is to say these three wars, are fundamentally the same cities or the same wars. Still, the photos look the same: there’s a very real sense in which if you’ve seen one bombed-out building you have indeed seen them all. (“War is a horrible repetition,” Martha Gellhorn wrote, and this is even truer of photographs than of words.) It is this anti-explanatory, anti-analytic quality of the photograph—what Barthes called its stupidity—that critics have seized on with a vengeance and that they cannot, apparently, forgive.

But the problem with photographs is not only that they fail to explain the world. A greater problem, for Brecht and his followers, is what photographs succeed in doing, which is to offer an immediate, emotional connection to the world. People don’t look at photographs to understand the inner contradictions of monopoly capitalism or the reasons for the genocide in Rwanda. They—we—turn to photographs for other things: for a glimpse of what cruelty, or strangeness, or beauty, or suffering, or love, or disease, or natural wonder, or artistic creation, or depraved violence, looks like. And we turn to photographs, also, to find out what our intuitive reactions to such otherness might be. (This curiosity is not, as the postmoderns have charged, an expression of “imperialism,” racism,” or “orientalism”: the peasant in Kenya and the worker in Cairo are as fascinated—if not more so—by a picture of New Yorkers as we are by an image of them.) None of us is a creature solely of feeling, and yet there is no doubt that we approach photographs, first and foremost, on an emotional level.

One of my favorite photographers is Walker Evans, who took what he called a ‘documentary approach’ to his photography–rejecting any hint of emotionalism in his work. About his most famous work, in the book Let Us Now Praise Famous Men, one reviewer wrote:

The images are quintessential of Evans’ “documentary style”; Evans’ dis-interested approach to these families resulted in portraying them with dignity and strength, although they lived in complete poverty. He sought to show the beauty of order and respectability within such an impoverished condition. Thus, many of the photographs are posed portraits, often made with the 8×10 view camera…Evans’ use of objects, as well as interior and exterior(architectural) shots, which were all components of his strategy to build a comprehensive documentary work. Although at times Evans used his Leica(35mm),a small format camera, he did not take “snapshots” of daily activites; he despised that journalistic approach. Evans kept his images, as usual, in sharp, hard-focus, and also varied his focal length–sometimes up close, other times, wide-angle.

Reviews of the book referred to the “naked realism which is the truth as Walker Evans’ camera eye sees it.” The effect is one of confrontation with the reader–not with Evans, but with the tenant-farming families themselves. In this regard Evans became the visual translator of these people to the rest of the alienated American public. In so doing, and in conjunction with his work for the FSA, Evans revolutionized the concept of documentary photography. That is, he artfully removed himself from the equation. His objective style brought the viewer into confrontation with the subject, with no hint of subjective authoritarian influence. These images are the best example of that fact, and accordingly were the hallmark images for which Evans became known.

Categories
Writing

Learning JavaScript on the streets

Recovered from the Wayback Machine.

I received my first author copy of Learning JavaScript this week and it’s now for sale at Amazon and elsewhere, though it may take a few days to reach full stock.

O’Reilly really moved on this book in order to get it into the store shelves before the Christmas rush. Just in time for all of your holiday gift shopping. Now I need to get the book support site up. Layout and tech is easy: design, now that’s hard.

If you happen to buy it, I hope you’ll feel moved to add comments out at Amazon and elsewhere.

I’ve also modified the organization and focus of the Adding Ajax book. There’s a great number of Ajax books on the street, so we really needed something that sets this apart. Luckily we have some time to slide with this book so that I could do a re-organization. I feel now that it’s a much better book.

Categories
Writing

Comments to comments

Recovered from the Wayback Machine.

I don’t remember this being written about anywhere, and I don’t know how old the ability is, but you can now add comments to individual product reviews at Amazon.

As an author, what a wonderful way of responding to comments on one’s work. For others, what a great way to get more detail from the original commenter, or provide counter-point and/or appreciation.