One of the good things about Backbone.js is it doesn’t tell us how to do things. It leaves it for us to decide what are the best practices for writing views (or any components).
This is also one of the worst things about Backbone. it makes it almost too easy to take the wrong path, and write views that will be hard to maintain.
The principle we should follow when writing a view is to keep it encapsulated, and keep it as “dumb” as possible – a view should know only the bare minimum it needs to know in order to do it’s job, and do bare minimum it has to do.
Here are 3 simple tips that can help us achieve this:
I ran into an old post by Philipp Lenssen on how good programmers are lazy and dumb.
I totally agree with the title and most of the content. However, I believe that the lazy and dumb engineers are the better ones for a different reason:
Because code is liability, and by writing a lot of code, you are taking upon yourself (or your team) liability to test, maintain, document and improve it.
A lazy developer will first look for an existing solution that already has all the above and which is qualified to solve the aimed problem.
Because a dumb developer writes code that is simple enough, for dumb engineers, just as he is, to be able to understand and work with.
“Smart” engineers tend to write sophisticated programs that nobody but them or the like of them can understand. I guess it makes them feel smart.
Dumb engineers look for simple, encapsulated, loosely coupled solutions that anybody can understand.