This past Saturday was the JS.Everywhere conference put on by Wakanda. It was a lot of fun, and there were some really great presenters. Douglas Crockford gave a brief history and description of our favorite language,Julian Aubourg showed off jQuery’s “magical” deferreds, and Dave Terry gave a very slick demo of Wakanda.
The above link is for the event’s twitter stream. I’ll likely follow up with more detailed posts about particular topics.
Douglas Crockford on the creation of JavaScript; The Tale of JavaScript. I Mean ECMAScript
(Source: channel9.msdn.com)
I once had to work with some very poorly written code, and I found this gem of a coding horror.
Within the PHP code that printed the HTML markup, there was a section that printed JavaScript. What did the JavaScript do? It selected an element (which had just been printed in the code above) and set the height attribute to a value based on the number of items inside the box. So you have PHP writing JavaScript which sets a style. That’s three technologies to do one simple thing. And the best part of it all: it was totallly unnecessary! I couldn’t understand why the height needed to be set, so I went ahead and set it to auto (the default value), and it worked just fine. (Likely, the items within the box were originally floated, which means they’d be removed from the normal flow, requiring a set height). Needless to say, I removed the entire mess. (to give the developer credit, he was clearly a smart guy and wrote some good code; I’m not sure why he resorted to this elaborate setup)
But let’s say you did float the elements within the box. Then what? Add an empty element after all the floated elements, like so: <br style="clear:both" />. (or better yet, put it in your CSS). The clear attribute ensures the element appears below the floated elements, and so the containing box gets an appropriate height.
Talking about this stuff reminds me how nice HTML layouts are. You almost never have to set the height or width of elements (unless you’re doing something tricky). Contrast this with Flash and ActionScript (to name just one example), in which you must explicitly set a height and width on everything, which is particularly annoying when you have dynamically sized content.