<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>angularjs &#8211; CS@Worcester</title>
	<atom:link href="https://cs.worcester.edu/category/angularjs/feed/" rel="self" type="application/rss+xml" />
	<link>https://cs.worcester.edu</link>
	<description>Worcester State University Computer Science Department</description>
	<lastBuildDate>Thu, 08 Aug 2013 15:00:00 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.9</generator>
<site xmlns="com-wordpress:feed-additions:1">236835116</site>	<item>
		<title>AngularJS Post-mortem</title>
		<link>http://dthompson.us/angularjs-post-mortem.html</link>
		
		<dc:creator><![CDATA[David Thompson]]></dc:creator>
		<pubDate>Thu, 08 Aug 2013 15:00:00 +0000</pubDate>
				<category><![CDATA[angularjs]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[web]]></category>
		<category><![CDATA[WSU]]></category>
		<guid isPermaLink="false">http://cs.worcester.edu/blog/?guid=d33b194f78b4eaa078754df7cd8b4bef</guid>

					<description><![CDATA[AngularJS is the new popular client-side Javascript application
framework developed by Google. We have recently adopted it at Vista
Higher Learning for building our latest features that require a lot
client-side logic. Now that I have a few application...]]></description>
										<content:encoded><![CDATA[<p><a class="reference external" href="http://angularjs.org/">AngularJS</a> is the new popular client-side Javascript application<br />
framework developed by Google. We have recently adopted it at Vista<br />
Higher Learning for building our latest features that require a lot<br />
client-side logic. Now that I have a few applications under my belt,<br />
it&#8217;s time to talk about my experience.</p>
<p>If you want a quick TL;DR: I think AngularJS is good, but it has a<br />
steep learning curve and there&#8217;s no well defined set of best<br />
practices.</p>
<p>Note: I will be using plenty of terms that will probably only make<br />
sense for people that have used AngularJS.</p>
<div class="section" id="the-good-stuff">
<h2>The Good Stuff</h2>
<p>These are the things that went well. The things that made me glad that<br />
we chose to use AngularJS.</p>
<div class="section" id="easier-testing">
<h3>Easier Testing</h3>
<p>Our Javascript test suite uses <a class="reference external" href="http://pivotal.github.io/jasmine/">Jasmine</a>. AngularJS is built with test<br />
frameworks like Jasmine in mind. AngularJS could tends to be easily<br />
testable due to dependency injection. When the components of an<br />
application don&#8217;t rely on global state, it is easier to mock services<br />
for unit tests.</p>
</div>
<div class="section" id="separation-of-concerns">
<h3>Separation of Concerns</h3>
<p>AngularJS stresses separating the view from the data structures and<br />
logic behind it. I think everyone that&#8217;s written a somewhat complex<br />
JQuery application can relate to the mess of CSS selectors and click<br />
callbacks that the code quickly degenerates into.</p>
<p>AngularJS allows you to break up the DOM into logical chunks that are<br />
handled by separate controllers. Treating the application as many<br />
small pieces working together rather than one giant DOM blob keeps the<br />
code clean. Message passing via <cite>$emit</cite> and <cite>$broadcast</cite> keeps<br />
controllers loosely coupled to each other.</p>
</div>
<div class="section" id="no-more-jquery-spaghetti">
<h3>No More JQuery Spaghetti</h3>
<p>Directives, the strategy for encapsulating DOM manipulation, are<br />
wonderful. It is an elegant solution to the mess that was JQuery<br />
selectors and event callbacks. AngularJS comes with a lot of<br />
directives out of the box to handle the most common stuff like<br />
showing/hiding elements, handling clicks, dynamically setting CSS<br />
classes.</p>
</div>
<div class="section" id="more-maintainable-code">
<h3>More Maintainable Code</h3>
<p>AngularJS is feature-rich. It does a lot on your behalf, which greatly<br />
reduces the amount of boilerplate code needed to get a prototype up<br />
and running. I had the opportunity to essentially rewrite an existing<br />
JQuery application using AngularJS. The results were clear: The<br />
AngularJS version had fewer lines of code, was more readable, and<br />
was easier to debug.</p>
</div>
</div>
<div class="section" id="bumps-in-the-road">
<h2>Bumps in the Road</h2>
<p>These are the things that didn&#8217;t go smoothly. They boil down to<br />
AngularJS having a steep learning curve and ill-informed software<br />
design decisions on my part.</p>
<div class="section" id="understanding-the-magic">
<h3>Understanding the Magic</h3>
<p>A lot of things seem to happen by magic. For example, it is possible<br />
to make a asynchronous request and get a promise object in<br />
return. When the promise is assigned to a variable on <cite>$scope</cite>,<br />
AngularJS not only knows to ignore it while the request hasn&#8217;t<br />
finished, but it will re-assign to that variable the value of the<br />
asynchronous call when it completes. It is a nice feature, but it<br />
takes some digging to find out what is really going on.</p>
</div>
<div class="section" id="poor-documentation">
<h3>Poor Documentation</h3>
<p>I know I&#8217;m not the only one that hates the official AngularJS<br />
documentation. The documentation is getting more complete, but it&#8217;s<br />
still not very useful. Functions frequently have a blurb describing<br />
what they do, but no explanation of the parameter list. It&#8217;s hard to<br />
use a function that doesn&#8217;t describe what it expects for input.</p>
<p>When the documentation confused us, which it did frequently, we turned<br />
to the AngularJS book from <a class="reference external" href="http://shop.oreilly.com/product/0636920028055.do">O&#8217;Reilly</a> for help. I need to get around<br />
to reading more of it.</p>
</div>
<div class="section" id="restful-resources-and-rails">
<h3>RESTful Resources and Rails</h3>
<p>AngularJS claims to be targeted at CRUD applications, but using the<br />
HTTP backend and the <cite>Resource</cite> abstraction that sits on top of it was<br />
particularly difficult. A good amount of time was spent on trying to<br />
get the HTTP requests from resources to conform to what our Rails<br />
backend expects, like root-wrapping.</p>
</div>
<div class="section" id="bloated-controllers">
<h3>Bloated Controllers</h3>
<p>I frequently made controllers that had too much state and logic that<br />
should have been extracted into services/factories/etc. A controller<br />
would start out slim but would quickly grow to several hundred lines<br />
of code as features were added. Controllers should be the middle man<br />
between the view and the model and that&#8217;s it.</p>
<p>Some tell-tale signs that a controller is becoming bloated:</p>
<ul class="simple">
<li>There are a lot of private functions (not defined on <cite>$scope</cite>)</li>
<li>Functions are defined on <cite>$scope</cite> just so you can unit-test them,<br />
but are never used in the template</li>
</ul>
<p>I attribute controller bloat to a lack of knowing the appropriate uses<br />
for other AngularJS components. It was easy to just keep adding to the<br />
controller.</p>
</div>
</div>
<div class="section" id="conclusion">
<h2>Conclusion</h2>
<p>Overall, I think things went well, but I (and the rest of my team)<br />
made a lot of beginner mistakes. But that&#8217;s the learning process,<br />
isn&#8217;t it?</p>
<p>Now that I know more about AngularJS, it will be easier to make better<br />
design decisions moving forward.</p>
<p>I believe that as AngularJS continues to mature, some concensus in the<br />
community about best practices will emerge that will make things<br />
easier for beginners.</p>
</div>

<p class="syndicated-attribution"><em>From the blog <a href="http://dthompson.us/">dthompson</a> by <a href="https://cs.worcester.edu/author/0/" title="Read other posts by David Thompson">David Thompson</a></em> and used with permission of the author. All other rights reserved by the author.</p>]]></content:encoded>
					
		
		<enclosure url="" length="0" type="" />

		<post-id xmlns="com-wordpress:feed-additions:1">2690</post-id>	</item>
	</channel>
</rss>
