Earlier quoted context omitted.
There's a lot of choices, and that's not a bad thing necessarily. Javascript is in a heavy growth period right now. But I totally get the choice overload thing. There's a lot of people interested in javascript from all different areas of computer land, and they all have different ideas of what "best" is, and they all want to make javascript more like lisp, or more like ruby, or more like java, or more like c# or more…
Backbone may or may not be right for you. Fortunately it's small, and fairly easy to read. The annotated sources [1][2] for BackBone and Underscore are fairly accessible. Also, I would highly recommend adding an AMD loader like require.js to your "basics kit". Code organization gets very important very fast, and it helps to think modular-and-reusable from the beginning. [1] http://underscorejs.org/docs/underscore.htm…
JavaScript: The Right Way
81–90 of 136 posts
Re: JavaScript: The Right Way
#82Earlier quoted context omitted.
And definitely replace jQuery with Zepto (which is more-or-less a drop-in replacement), if you have control of the client (non-IE) or especially are working in mobile.
I've not heard of Zepto. Out of curiosity, why use it over jQuery?
Re: JavaScript: The Right Way
#83Earlier quoted context omitted.
I think that's a naive way of thinking about the problem. Do people write rich server-side web apps in Plain Ol' Python? Of course not. Why reinvent the wheel? For a tiny app, sure, maybe it's not so bad to just use jQuery. But if you're working on something with a very rich front-end architecture, a framework gives you a very necessary...er...framework to use to eliminate boilerplate and organize your work. Not only…
Do people write rich server-side web apps in Plain Ol' Python? Perhaps not, but plenty of us write them using a lightweight framework like Flask rather than heavyweights like Django, and even in a relatively mature field like ORMs, there are downsides to using them that sometimes outweigh the advantages. For a tiny app, sure, maybe it's not so bad to just use jQuery. I've got ~100,000 lines (before minimising etc.) a…
IME any application which grows that large without using a framework ends up inventing its own. If the code's maintainable by people other than its original author you've presumably separated the routing code from the template rendering code (and have a module that's effectively a generic template renderer) from the backend service access (and again, probably have a module that's some kind of generic service access layer). You'll have a set of utility functions that's more or less equivalent to underscore. And so on.
Re: JavaScript: The Right Way
#84The command pattern is featured in the article. Why would you use that pattern in a language that supports first-class functions?
Re: JavaScript: The Right Way
#85Earlier quoted context omitted.
And definitely replace jQuery with Zepto (which is more-or-less a drop-in replacement), if you have control of the client (non-IE) or especially are working in mobile.
I've not heard of Zepto. Out of curiosity, why use it over jQuery?
Re: JavaScript: The Right Way
#86Some additional comprehensive JS resources: http://eloquentjavascript.net/ http://shichuan.github.io/javascript-patterns/ https://github.com/airbnb/javascript
Re: JavaScript: The Right Way
#87I am not too fond of the styling. Looking at it on my desktop PC, the page could use some left/right margin. On my iPhone on the other hand its rather unreadable.
Re: JavaScript: The Right Way
#88Earlier quoted context omitted.
Actually the frameworks don't help in that regard. They are meant for organizing your code, they don't offer any special compatibility. jQuery does that.
and underscore. not for DOM, but for some functional compatibility (map, forEach, etc). Plus, it's convenience methods quickly become indispensable. _(fn).bind(this), anyone?
Re: JavaScript: The Right Way
#89Having recently started getting into Javascript, I have to say it is the most confusing ecosystem ever. Learning the basics of the language is easy enough, but as soon as you start trying to create a non-trivial application, bam, you're hit with information overload - X framework, Y library. It's different from Python, Ruby et all because at least with them, there are good consistent popular choices that you can rely…
There's a lot of choices, and that's not a bad thing necessarily. Javascript is in a heavy growth period right now. But I totally get the choice overload thing. There's a lot of people interested in javascript from all different areas of computer land, and they all have different ideas of what "best" is, and they all want to make javascript more like lisp, or more like ruby, or more like java, or more like c# or more…
Re: JavaScript: The Right Way
#90Earlier quoted context omitted.
Do people write rich server-side web apps in Plain Ol' Python? Perhaps not, but plenty of us write them using a lightweight framework like Flask rather than heavyweights like Django, and even in a relatively mature field like ORMs, there are downsides to using them that sometimes outweigh the advantages. For a tiny app, sure, maybe it's not so bad to just use jQuery. I've got ~100,000 lines (before minimising etc.) a…
How many lines would it be if it used a good framework? IME any application which grows that large without using a framework ends up inventing its own. If the code's maintainable by people other than its original author you've presumably separated the routing code from the template rendering code (and have a module that's effectively a generic template renderer) from the backend service access (and again, probably ha…
I don't know. That project has no direct equivalent to any of the current frameworks, other than approximately following MVC for its overall architecture and using message passing/publish-subscribe in various places to keep things modular and testable.
I imagine you could achieve some of the same behaviour using data binding tools in modern frameworks, but either way you're typically looking at a little boilerplate to connect things up in the first place and then one-liners to connect individual fields from a model to the corresponding parts of the DOM. It's not clear whether there would be any savings at all, but if there were, they wouldn't be significant for any framework I've considered so far. In any case, that represents a tiny fraction of the overall code base for this application.
IME any application which grows that large without using a framework ends up inventing its own.
All software has an architecture, sure. As with any framework vs. library debate, you're trading off the benefits of having some of that architecture predetermined for you and having some of the laborious plumbing work dealt with automatically against the overhead of managing a major external dependency and any extra costs you incur if you need to do something that goes against its natural capabilities. Sometimes using a framework is a win, and sometimes it isn't.
If the code's maintainable by people other than its original author you've presumably ...
You've made some assumptions there about how web apps work, but they aren't necessarily true.
For example, much of the complexity in this particular UI comes from providing many views of the same underlying model. Some of them are graphical rather than text/form based. Some of those rely on intermediate cached data structures for their source data because rerendering an entire view from the raw data in the model can be prohibitively slow. We have an efficient and simple architecture using the same basic principles as MVC for dealing with this kind of caching. We'd derive very little benefit here from the kinds of data-binding and template-rendering functionality found in the major frameworks.
Just to be clear, libraries designed to render interactive graphical page elements efficiently, allowing for portability across browsers and different image/scene formats, are another question entirely. I'm not arguing for reinventing the wheel or arguing against using tried-and-tested code from external sources. I'm just arguing that it should only be done when the benefits outweigh the costs, and that this won't necessarily be the case when considering whether or not to use one of the modern JS frameworks as the foundation for your web app.