Advertisement
yudiwbs

tools for large scale javascript

Jun 4th, 2012
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. http://news.ycombinator.com/item?id=4063595
  2.  
  3. stiff:
  4. The problem with JavaScript is, somewhat paradoxically, too much flexibility. There are no standard language features for very basic things like namespaces and modules, also what it provides for OOP is so confusing that it makes people want to roll their own OO system from scratch. Objects as dictionaries and first-class functions make it possible to implement those features in hundreds of ways and almost every JavaScript program tends at least in some places to use some own, original solution for one of the very basic problems of structuring programs, because it is so easy to built one. It is good that this is possible, it is bad that people _have to_ do this (or choose one of the countless existing solutions) before they can actually write the program they want to write.
  5. A lot of the problems would go away if the following was part of the language and present in every browser:
  6. * namespaces/modules
  7. * a sensible OO system people would actually enjoy using
  8. * the ability to require/import/include a file/module
  9. * the functionality Underscore.js provides
  10. Then, at least the basic structure of the code would be consistent across programs from various people, and I wouldn't have to work out the details of yet another OO system, yet another way of just laying out the code across functions/objects each time I want to read another JavaScript program or yet another way of doing function () {}.bind that works across the browsers (here the problem is also the long time it takes for the majority of people to install a browser new enough to adopt the revised standards). And it's not only about reading code, how do you write an object-oriented refactoring tool if every program realizes OO in its own distinct way?
  11. The situation is probably slightly better with server side JS where you are free to adapt the newest version of the language/runtime and also the server-side frameworks at least to some extend tend to encourage to use a common structure for all the modules.
  12.  
  13. garindra
  14. Your 4 points are exactly why I always use Require.js, Backbone, and Underscore in all my large projects.
  15. Require.js solves point #1 and point #3. Backbone solves point #2. Underscore solves, well, point #4.
  16. In my experience, the other important thing to maintain coherence and sanity while creating large JS apps is to have a system that makes dependencies between modules very, very clear. Require.js basically also does that for me; it requires every module to define their dependency on other modules on top of its file.
  17. I highly recommend people creating large JS apps to at least check it out : http://requirejs.org/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement