Archives For jsdd

JavaScript Best Practices

February 10, 2012

I recently came across two good resources that discuss some best practices when it comes to JavaScript. The first is an article at Developer Drive, titled Top 10 “Must Follow” JavaScript Best Practices, written by Salman Siddiqui (it’s a good enough article that I’ll ignore the dubious use of quotation marks). It’s a pretty good list, with a range of beginner to advanced topics. I would disagree with one, however: “Better to avoid DOM.” While DOM manipulation is expensive, it’s often required, so I think it’s better to acknowledge that this is a necessary evil we’re stuck with and hope that browsers continue to make improvements in this area. I liken it to the common economic theory that getting a loan to buy a car makes poor monetary sense (because it’s a loan on something that depreciates). The fact is most people need a car to work and make money, so a car loan is often necessary. But I digresss…

The second resource is a presentation titled JavaScript “Best Practices” (again, the quotation marks), by Christian Heilmann. Heilmann presents about 20 specific suggestions and then explains them all in detail. The presentation itself lacks pretty much any style whatsoever, but content is more important, no? There’s lots of code in the presentation precisely demonstrating both good and bad behaviors, along with explanations as to why something is problematic.

I’m in the process of writing my own article, titled “The 10 Best JavaScript Development and Design Habits”, to be published at Peachpit.com. I’ll post a link to that when it goes online.

I am very happy to say that last week my latest book, Modern JavaScript: Develop and Design, went off to the printer. It’s still slated for a late February release (in the US). Because of the increased page count (624 pages), the price of the book was raised $5.00. However, it seems that Amazon only raised its price like 50 cents. Amazon is currently selling it at $31 (US) and you can buy it using the link below (note: I’ll get an extra dollar or so if you use the Amazon link).

For the first time ever, I plan on selling copies of select books myself. The books will, of course, be signed (inscribed however you want). For the Modern JavaScript: Develop and Design book, I believe I will be able to offer it at $35 $40 (US), plus shipping. This is slightly more than the Amazon price, but I have more overhead (well, different overhead) and fewer employees than Amazon! Plus, Amazon has that whole “economies of scale” thing working for it. I’ll confirm the price and get the e-commerce system setup in the next couple of weeks. If you have any questions or comments, let me know.

ADDITION: Presumably, the book will be available internationally in time, starting with English-language countries such as Canada, the UK, and Australia, followed by translations in other European countries and Asia (that’s my educated guess, based upon how things have gone in the past). Buying the book directly from me will be the fastest way for international recipients to get a copy, by far. I’ll need to receive my copies of the book before I can estimate the shipping costs.

UPDATE: I just heard back from my contact at the publisher and it will cost me more than I had thought to purchase the book for resale. In order to cover my costs, I’ll need to charge $40 (US) plus shipping. Admittedly, this is almost $10 more than Amazon, but the $40 covers the cost of: the book itself, getting the book shipped to me, and packing materials. I think shipping within the United States via media rate will be around $4.

In this edition…

Continue Reading…

UPDATE: Amazon currently has the book for sale at $30.47, as I write this.

I am very happy to say that my latest book, Modern JavaScript: Develop and Design, is official done. Well, not done, but close enough to blog about it. I just submitted the last chapter to be written, Chapter 13, Frameworks. In it, I quickly discuss how to choose a framework, when you should use a framework, and some common libraries (as a framework alternative). The bulk of the chapter introduces and uses jQuery and the Yahoo! User Interface (YUI) Library. For both I explain how to perform common tasks—selecting DOM elements, DOM manipulation, event handling, and Ajax, and then walk through more advanced examples. For both, the chapter explains an autocomplete example, using a PHP script as the data source. For jQuery, I also discuss the DataTables plug-in. For YUI, I also discuss and demonstrate the Yahoo! Query Language (YQL). For it, I go through a couple of examples, including fetching a weather report and a stock quote. (For the record, I specifically target YUI3, which is an improvement over YUI1 and 2, even if some of the framework is currently in beta.)

Chapter 13 is the first chapter in Part 3 of the book, Next Steps. I already wrote Chapter 14, Advanced JavaScript, which has a heavy focus on closures. Chapter 15, A PHP and JavaScript Example, creates a pseudo-complete auction system. Auctions are set to expire on a certain date and time. Logged-in users can bid on items. All dates and times are shown using Coordinated Universal Time (UTC) or the user’s timezone, if the user is logged-in. Then, JavaScript used to enhance the experience. This includes using Ajax for the login and bid forms, retrieving the latest bids via Ajax (and updating the table of bids with them), and creating countdown timers that show them amount of time left in an auction, when that’s less than an hour. I think the chapter turned out well, and it emphasizes the various ways to pass data back and forth between PHP and JavaScript, a common point of confusion.

All of the initial writing is now complete. I’ve also done the rewrites on the first nine chapters. I still have to do the rewrites on the last six chapters, but that won’t take long. I will also be doing supporting videos and articles related to the book.

I believe the book will still ship, as originally planned, at the end of February. I am now going to go celebrate!

In this edition…

Continue Reading…