No joke.

Posted in Humor | Leave a comment

Strict mode for Javascript – continued

Seems the prior post gathered some response.

To set expectations – this is my personal weblog. What I put here is the bits that (to my mind) might be otherwise missing. I am not interested in repeating material covered elsewhere. If you are already well-read, then I hope these bits will nudge your thinking forward a bit (even if you do not entirely agree with my conclusions).

On the other had, if you are seriously short of clues, I am not going to help you. Spent enough time on USENET News (long ago) to note the point of diminishing returns. Since I write these bits as an entertainment (of sorts), I am not going to invest a lot of time with folk who are too many laps behind.

Javascript is at heart a dynamic, prototype-based sort of object-oriented language. Most folk coming to Javascript are acquainted with static, class-based languages – and have little or no experience with anything different. The natural inclination is to transfer learned habits from the old to the new language – and that is a mistake.

Back in the late-1980′s or early-1990′s one writer came up with a classification scheme for object-oriented languages. There were many variations proposed and explored in that time, so a scheme that enumerated the important aspects was very useful. (Wish I knew how to find the article – it was in an ACM or IEEE publication of that period, I believe.) As a guess, I suspect that most of the current generation of programmers is not aware of the possible variations, and assume all object-oriented languages must be like Java / C++ / C#, and expect the same learned habits to still make sense with Javascript.

Disregarding the usual noise, there is one bit which it is worth responding, as it (quite unintentionally) illustrates my point.

New gives you prototype inheritance, performance benefits, and it’s about language semantics.

That is exactly my point! … only the reality differs from the assumptions of the guy making the comment (and I suspect he has a lot of company). Back in the late 1980′s / early 1990′s the pragmatic consensus was to move forward with object-oriented languages that could be made to run efficiently on the then-current hardware. How to generate optimal code for static class hierarchies was fairly well understood, at that time. More dynamic object-oriented languages were simply too hard to optimize.

The v8 Javascript engine offers a good example. The combined memory and CPU footprint of an efficient Javascript engine was simply impossible on circa-1990 computers. What is practical and reasonable on current-generation computers was – twenty years back – completely not practical.

My reading of the articles on the current-generation Javascript engines was that the toughest problem – and main aim of implementors – was to optimize in the absence of static-class hierarchies, and that quasi-static classes are not particularly optimized.

This makes sense. Writing script for web pages is programming in the small. The number of entities on a web page is small, as are the number of repeated instances. Static classes with efficient support for huge numbers of behavior-identical instances are essentially useless in a web page. If you are creating large numbers of instances for a web page, you are almost certainly doing it wrong. (Note the “flyweight” class pattern is useful here.)

My assumption (from what I have read) is that “static” class hierarchies yield no particular benefit in client-side Javascript.

Assumptions should be checked … so I wrote a micro-benchmark.

Method dispatch – Microbenchmark – Javascript
The aim was to measure method-dispatch for three cases:

  1. The method is bound to the instance.
  2. The method is bound to the “class” (via the __proto__ member).
  3. The method is bound to the “class” (via the function invoked via new).

What I see (in terms of exact results) will likely vary as each browser vendor tweaks their Javascript engine. The point – in the case of the current discussion – is that static class hierarchies yield no significant advantage. It does make perfect sense that static-class languages can deliver bare-hardware performance numbers (which I do expect to use). For web page script, I expect static-like class usage to yield no significant benefit.

For programmers coming from C++/Java/C#, the notions that made sense no longer apply. Thus the emphasis on denying any semblance to static-class languages. This was exactly my point.

Posted in Javascript, Software | Leave a comment

Is Tivo still a good bet?

I have a Tivo Series 2 that I bought when the model was new. For the most part, I have been very satisfied with the Tivo service … but not so much lately. There are now many sources for video that I would like to watch on the TV, and the Tivo box is not useful for those new sources.

Still … my Tivo box is relevantly old, and you might expect new features to be introduced mainly on new boxes. This is not a complete excuse – the Tivo is basically a small computer with a hard disk and a network connection. A software upgrade on the old boxes could do quite a lot, within the hardware capabilities of the box … and I was paying a subscription fee.

My old non-HD TV finally died, and bought a new HDTV. Time to upgrade the DVR. Do I want to buy a new Tivo? The new Tivo seems a bit … limited? If I buy the full-up version with the most cost-effective service, the cost is a bit under $900 (without discounts). Do I trust the Tivo company and brand enough to spend that money of their box? Maybe.

When the Google TV announcement came out, that was enough to defer upgrading the Tivo until I saw Google’s product.

In the time between, the (not so) good folks at Tivo changed my mind.

Near two months back, the Tivo folk starting sending nasty emails, claiming my credit card was about to expire, and … let’s just say I did not appreciate the tone. Somehow they had decided my credit expired, two months before the actual expiration. The updated credit card arrived at the usual time, but by then the Tivo folks had sent a month’s worth of nasty emails. Just after I got the updated card, I went to the Tivo site, and updated my credit card information with the new expiration.

About a week later I got another nasty email from Tivo. I sent a response.

Guessing I might have made a mistake, somehow, I went back to the Tivo site, and updated my credit card information … again. Noticed all the fields on the web form offered auto-complete, so obviously I had been to the site recently. (I reset all the saved information in the web browser a couple months back, as a part of testing some of my software.) After submission, I checked the result carefully to be sure that their web application reported success – and it did.

About a week later, I got an even less pleasant email from Tivo. I sent a response, then I called their support phone number.

Has the Tivo company has gone sour? I have noted a pattern where a business with substantial cash flow is bought out, and the new owners cheapen the product and/or service (presumably with the hope of boosting profits). Customers eventually notice, and start to go elsewhere. In response, the owners further cheapen the product (in hope of maintaining profits on smaller revenue?) … and the business does badly.

Has the Tivo company been bought out, or adopted the same philosophy? That would explain the slow change in technology, and the unpleasant customer service.

As a good customer, I did exactly what I should, when I could. Personally, I would rather not do business with a rude company. On the phone with Tivo support, I did not appreciate the assumption that the mistake was mine. (I suspect most customers surrender on this point.) I want Tivo to fix the problem, and to not be rude to good customers. I refused to update my credit card information over the phone. Instead they could tell me when they fixed their broken web application, and I would (for the third time) update my information there.

Today it seems they turned off my Tivo service. The fault is theirs for losing a good customer. Probably not a loss. For now, I can wait to see what the Google folk (and associates) deliver.

Posted in General | Leave a comment

Status check

A human being should be able to change a diaper, plan an invasion, butcher a hog, conn a ship, design a building, write a sonnet, balance accounts, build a wall, set a bone, comfort the dying, take orders, give orders, cooperate, act alone, solve equations, analyze a new problem, pitch manure, program a computer, cook a tasty meal, fight efficiently, die gallantly. Specialization is for insects.

— from Robert A. Heinlein

Refactoring … to what I want yet to do.

  • Design and build a house that works well.
  • Practical knowledge of firearms.
  • Learn to hunt, and butcher the animal, after.
  • Learn to fly an airplane.
  • Design and build an airplane.

In roughly the above order.

Posted in Personal | Leave a comment

Strict mode for Javascript

A small item…

Javascript is a hash (pun not entirely intended). There are good parts to Javascript, and bad parts. For folk attempting to learn Javascript for the first time, they could use some help avoiding the icky bits.

My first cut at rules for a “strict” mode for Javascript:

  • No use of “function name(){}” declarations
  • No use of “document.write()”
  • No use of “new”

No doubt I could come up with more rules, with a bit more reflection, but this is a start.

No use of “function name(){}” declarations
There are two means of declaring functions, and I strongly prefer the second form. Programmers coming from other languages tend most often to use this form:

function foo() {
}

For an entire collection of reasons I prefer this form:

var foo = function() {
};

The second form is better suited for later refactoring, and offers subtle emphasis to the learning programmer of the difference offered by Javascript. The first form can also lead to subtle bugs (which I do not want to explain) – certainly not what you need when first learning a rather different language.

As a partial hint, I tend to make rather a lot of use of namespaces, so my function declarations most often look like this:

var ZOT = {};
ZOT.foo = function() {
};

Or in the more elaborate use:

var ZOT = (function() {
    var foo = function() {
    };
    return {
        foo: foo
    };
})();

This last form makes full use of closures, and allows for private data and functions.

No use of “document.write()”
Programmers tend to want to generate HTML from program code. This is a huge mistake.

To me this is a classic application of separation of concerns. HTML describes page structure. CSS describes page presentation. Script describes dynamic behaviors. Best to keep each concern separate.

No use of “new”
On this point I am certain others will differ. They might even be right. Certainly the “new” operator is of huge advantage in static languages. But that is not the domain of Javascript – certainly in the web browser, and possibly even for server-side usage.

The “new” operator misleads programmers when first learning Javascript. The pattern of usage most appropriate to a static-class language is not the same as the most appropriate usage in an entirely dynamic language.

Conflicted over Crockford
There is a measure of irony in the last point. Douglas Crockford has consistently served to promote better usage of Javascript. Crockford was hired by Yahoo. The quite elaborate user interface library in Javascript developed by Yahoo, is first invoked with “new YUI()”. YUI obviously represents a substantial body of work, at least partially in what seems the right direction. Yet I cannot yet quite get past the beginning.

Posted in Javascript, Software | Leave a comment

Perfect Pineapple Pizza

Bit of nonsense….

Have experimented occasionally but steadily on how to make really good pizza. I do not have a massive coal-fired brick oven, so I have to make do with a slightly fancy counter-top oven. Note also that I am allergic to tomato, onion, and garlic – so the most common recipes are not useful.

Early on I made mushroom and sausage pizzas, and got decent results. Turns out a simpler(?) pineapple pizza is harder to get right. My kids have many likes and dislikes, but they all like pineapple pizzas. So the occasional challenge – every week or so – is to make a better pineapple pizza. Got results my kids happily accept a long time back, but I was not satisfied.

Tricks that get closer to that perfect pizza:

  • Empty a can of crushed pineapple into a sieve, dump yeast and a bit of flour into the juice, and put the mix into a warm (120°F) oven for an hour. The yeast go nuts, and add a bit to the flavor of the eventual crust.
  • Add a bit of fresh-ground black pepper to the pineapple. My daughter did not notice the pepper, but liked the result (as did I).
  • Dry out/caramelize the pineapple a bit – one hour at 250°F seems a good start.
  • Add the shredded mozzarella to the pineapple, before topping the pizza.
  • Add sliced (and drained) olives to the topping. The saltiness of the olives nicely accentuate the sweetness of the pineapple.
  • Add a bit of olive oil to the topping.
  • Add lemon juice to the topping. The sweetness and acidity boosts the pineapple.
  • Add flour to the starter to make a dough, spread on a pizza pan, add topping, and put in a 120°F oven for 30 minutes. The sugar from the lemon juice seems to boost the yeast in the dough, and adds a bit of lemony flavor.
  • Set the oven to 425°F for 15 minutes (or less – watch carefully).
  • … and I am still working on this. Results are good, and improving.
Posted in Personal | Leave a comment

Vodka and Lime

Random bit…

The cover of “Hazy Shade of Winter” by the Bangles is one rare instance where the copy surpasses the original. The original is great. The cover by the Bangles is better. (Even minus the “babe” factor.)

My only wish is for a longer version.

Posted in Personal | Leave a comment

VirtualBox as free software

File this under “Missing the Obvious”.

I bought VMware Workstation several years back. Used virtual machines quite a lot in developing and testing software. The company I work for licensed the enterprise version of VMware, at least in part due to developer experience using VMware. A few of the VMs currently hosted under the enterprise version of VMware started out running under VMware on my desktop.

A few years back – well after EMC acquired VMware – I got the distinct impression that the desktop version of VMware was somewhat neglected. I was losing increasing amounts of time to locked-up VMs, messed up keymaps, and even main desktop lockup. This provided an incentive to try Sun’s VirtualBox, which proved more reliable for my usage.

Oracle gained ownership of the VirtualBox software with the Sun acquisition. Is there any strong reason for Oracle to offer and develop the “free” version of VirtualBox, or will the desktop version of VirtualBox suffer the same apparent neglect as did the the desktop version of VMware?

Of late I was reviewing the documentation we sent to our customers with the last software release, as we are rolling up to a small update in the near future, and a larger release a bit later. In the documentation we send to customers, we have a prominent declaration of support for running under VMware. This was an easy declaration to make, as developers used VMware heavily in development and testing. We knew our product ran under VMware.

Now this is somewhat less true. Certainly the more elaborate test setups (mine) are all run under VirtualBox. I expect things all still work under VMware, but I personally no longer have a basis to make that assertion. For the next release, we will likely add an statement of support for VirtualBox.

As to the obvious bit I had missed:

Many of our customers are still not using virtualization software. Generally customers move from a physical machine to a VM at the time of a major version upgrade. At the next major version upgrade, we will offer a recommendation for VirtualBox.

Oh. Right. I had forgotten about that multiplier. Selling enterprise virtualization to our customers represents many more opportunities than any in-house usage at our development outfit. Nevermind my misgivings – offering free software to developers is about the best advertising Oracle could buy.

Does Oracle know this?

Posted in Software | Leave a comment