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
Just Shelley

Why I’m writing more on Missouri

Recovered from the Wayback Machine.

Dave Winer writes that Daylife is in business. I vaguely remembered hearing something about it once, and then remembered, “Oh, yeah. That’s that Jarvis thing.” To make sure it was that Jarvis thing, I looked it up online and discovered this phenomenally self-referential post at Valleywag, that perfectly explains why I now write more about Missouri and other things.

As ParenthetiGal wonderfully puts it, that was the most satisfying comment-sex i’ve ever witnessed on valleywag. thanks boys!.

Damn! And here I was hoping to get a job with The Man.

update

Ut Oh! Someone forgot to sacrifice to the Mikey!

update

I must provide a disclosure on Daylife: I submitted a resume when the company was hiring people, was consequently sneered at and treated with disdain.

As homey as that left me feeling (“Hey! It’s just like being on Techmeme!”), I can’t say I have the most positive feelings about any one damn person involved with this really useless site that took a year and half to create.

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
Just Shelley Web

A work in progress

Recovered from the Wayback Machine.

I apologize for late replies to emails and such. I’ve not been checking either email or weblog posts that frequently lately, and will only be doing so erratically for the next couple of months. If I don’t reply, don’t think me rude. Well, don’t think me rude only because I’m not replying right away.

As mentioned in the last post, I’ve had a heck of a time trying to figure out what I want from my new sites. The trend now, especially with tech sites is white or gray or gradient backgrounds, centered content, no or minimum graphics, and ads. It’s all very purposeful, professional, but there’s not a bean of personality in most of it.

I don’t think returning to the days of yore when we had paisley backgrounds and bright blue fonts is necessarily the way to go, but I wonder sometimes at the parsimonious nature of web sites–especially ones related to technology. True, we don’t want to load the sites down with graphics, but we all dump in photos from Flickr and videos from YouTube, so I don’t think bandwidth is the consideration. It’s as if we’re afraid that adding our personality to the page lessens its value, which is a hell of a thing.

Regardless, I do want the new sites to project a level of competency along with the personality, and therein becomes the challenge. I just couldn’t come up with a general theme to drive out the sites, not until this last week.

I’ve taken up book binding as a hobby again. I really can’t spare the time, but I find it helps with stress, and I need something other than work on tech, work on book, work on weblog, shuffle out for a walk and a pic, and repeat. I need something to do with my hands, and I find it wonderfully soothing to touch the many different hand pressed papers; to enjoy the rich colors and the infinite variety of patterns and forms.

This has, in turn, acted as inspiration for the design of the new sites, each of which will celebrate a specific form of craft: such as batik, bookbinding, engraving, stained glass, and the delicate enamel and metal popular in the Art Deco period. I like the idea of writing about modern technology in a site whose design is inspired by a textile method as old as time. At a minimum, it’s a fun challenge and a way of growing my design skills, slight as they are.

Speaking of crafts, O’Reilly recently started a new magazine and site, Craft as companion to its Make magazine. One reason given is to attract a female demographic, which made me wince at the stereotyping. I think, though, if the site dumps the obvious pink lettering and doesn’t completely focus on female centric projects, it can successfully attract both men and women.

The whole concept of ‘craft’ encompasses both culture as well as artifact and goes beyond that which was taught in home ec or shop. Any person who has seen a person lovingly oil a hand carved cherrywood table, spin a pottery vase, create a magnificent mosaic of glass–or bind a book–understands what I mean when I say craft. Many people would disdain to call themselves ‘artist’, preferring the more solid craftswoman or craftsman. Not all boys want to build robots to scare the dogs, and not all girls want to knit mittens, but both sexes can take pride in their skill working on a craft, whatever that craft is.

Book binding, batik, wood carving, embroidery, weaving, engraving and metal work, and so on–there is nothing in any of this that’s inherently unique to any specific sex, though there are gender specific practices. In Jakarta, for instance, using a pattern tool or cap in batiking is traditionally done by men, while batiking by hand is traditionally done by women. Why this difference, I don’t know, but it is an interesting question. Therein lies the point: a site that’s focused on attracting both men and women leads to such questions, which in turn generates discussion and understanding, which can lead, someday, to a lessening of such gender-based boundaries and stereotypes.

O’Reilly can do much to ensure a good audience of both men and women in Craft–as long as the company remembers the long history and legacy associated with the word ‘craft’, and doesn’t focus only on knitted iPod holders and making Halloween decorations out of tampons, (though kudos for such imaginative use of every day material).