Benchmarking is hard

I’ve seen a lot of people creating benchmarks that are misleading and sometimes I even create some “biased” benchmarks myself. On this post I will try to explain how measuring things the wrong way can make you believe that a certain technique is faster but in real-life applications it may have the opposite effect or not so significant gains.
Read more…


Single entry point redux

A couple months ago I posted about using a single entry point for JavaScript applications and how it could simplify the HTML logic and also make dependency management easier. A couple people asked if I had some example and the only examples I had were client projects which I couldn’t share the source code…

I’ve just answered a question on the RequireJS mailing list and used a Gist to explain how single entry point works and how it improves the code structure and simplify dependency management.
Read more…


Hasher: deep linking for rich-media applications

Hasher Logo

There are many available polyfills and libraries that provides deep-linking capabilities using the browser location.hash to generate a new history state. Hasher was created to do exactly the same thing but providing a cleaner API and solving a few problems present on some of the other libraries, it was also designed to make use of JS-Signals providing many advanced features like enabling/disabling the event dispatch, adding multiple listeners, etc… and to also be used together with Crossroads.js easily.

Check the README file on the project repository to understand better how does it work, why it was created, some benefits over the other solutions and also when should you favor using the HTML5 history API over location.hash to store application state and when you should avoid it.

Watch the project on Github for future updates and use the issue tracker to report bugs and ask for new features, contributors are welcome!

PS: I’ve been using Hasher for more than 1 year on a few projects but only decided to release it last week (after revising API and refactoring unit tests).

Related Posts:


Crossroads.js: JavaScript Routes

The project isn’t that new anymore and was already featured on a couple places but I think I should also create a post just in case someone missed it and also to register the release.

Crossroads is basically a routing system used to map strings to functions (usually URL fragments), it acts similar to a pub/sub (event listener) but uses Regular Expressions and dynamic string patterns to identify listeners. The main feature is the robust and flexible string validation/match/parsing system.

The greatest advantage of Crossroads when compared to other similar libraries is that it is not directly tied to server requests (in case you are using it on the server-side) or to the window.location (if you are on the browser). Another important advantages are the flexibility and the support for advanced use cases, provided by different kinds of validation rules and multiple listeners to each route. – It gives you flexibility to do any kind of action you want and doesn’t do anything you don’t ask it to do.

Check the project page and examples to know more about it. It can be specially helpful for large websites and single page apps – as I mentioned on my previous post.

I hope you enjoy, contributors are welcome.


Single entry point FTW!

Many programming languages and environments require a Main Class, Main function or Main file as an entry-point to the program, it’s where the execution starts and also usually where you have access to command arguments. JavaScript on the browser isn’t one of those environments tho, and I think it is one of the reasons why many applications become a real maintenance nightmare. I believe that the “Main File/Function/Class” approach can help a lot to increase extensibility/maintainability and favor a good structure even for languages that doesn’t require this practice.

Many back-end frameworks started to adopt this technique over the past years, most of them have some sort of URL redirect that points to a “index” file or a router that decides which actions should be executed and which files should be loaded instead of having a single file for each page or section. This kind of abstraction increases flexibility a lot since you can just keep adding new pages/sections/features without having to care about the code structure, it also reduce code duplication since you don’t need to create a new file for each new page…

Flash projects have a Main Class which is the entry-point for the application and also works as the root node where all the child elements are attached (similar to the body element of an HTML file) and it helps you keep the code flow organized since you are sure that your Main Class constructor is executed before any other code, programs get easier to understand since it follows a logic order.
Read more…