How does Angular JS relate to Google Closure? - client-side

Now that AngularJS 1.0 is released I am wondering how this project fits together with the other general-purpose JavaScript framework / tool from Google, Closure.
I have only seen basic description of those two technologies (and read about a half of the book on Closure) so I have no direct experience but this is how it looks to me:
Closure is a set of technologies that can be used separately. What I find probably the most appealing is:
Closure Compiler which seems to "fix JavaScript" in a sense that it warns against typical issues, provides some compile-time checks (not all people like this but probably most Google developers do, and I do too). And of course it's nice that the resulting code is smaller and more efficient.
Then there are some parts of Closure Library that I like, e.g. abstractions over built-in types (ArrayLike etc.), class-based system, eventing mechanism, DOM abstractions etc. I'm not sure yet if I like the GUI library or not (seems to be quite complex and I didn't really have time to study it yet).
Then there are some features that I don't think I would find that useful, e.g. Templates.
AngularJS, which I've only read briefly about, seems to be much higher-level than Closure. It seems to be an application framework providing features like data binding, reusable components, MVC structure etc.
So these two technologies seem to be aimed at quite a different level of abstraction so my first thought was, can they be used together? Closure providing low-level compiler and browser abstractions while Angular providing application-level services and structure? Would it make sense and would it work well together?

The only Google project I'm aware of that uses AngularJS is the DoubleClick team. (presentation) Essentially, they still use Google Closure Library for everything but the UI building. Also note that they use Google Closure Compiler, but that's almost a given, "nobody" uses only the Library without the Compiler.
Google Closure Library comes with a UI framework in its goog.ui namespace. This framework compares in almost every way to non-web UI frameworks like Android, iOS, Swing and QT. They have a thing I like to call DOM elements on steroids, goog.ui.Component, which has lots of great life cycle mechanisms for garbage collection and event listening and more. You have things like goog.ui.Control, which is a subclass of goog.ui.Component, and handles user interaction in a very interesting way. It lets you plug renderers, for example, so you can change a <button> to an <a> without changing any of your other logic except the actual rendering.
Speaking of classes and subclasses, Google Closure Library also has this. You don't have to use the built-in one, the important part is that you somehow call the prototype of the "superclass" in your methods. You can for example use the class system in CoffeeScript, Google Closure Library doesn't care.
The reason the DoubleClick team chose AngularJS was apparently largely because of the data binding features AngularJS provides. There's nothing built-in in Google Closure Library to automatically update the UI when data changes.
So to summarize, Google Closure is a huuuuge beast, and AngularJS can replace the goog.ui part of the Google Closure Library.

I think AngularJS is more like a solid MVC/MVVM framework and Closure Library is a set of loose components, although both AngularJS Templates and Closure Templates have much in common.

Related

JavaFx vs TornadoFx

I have started working on javafx . I wanted to know the difference between javafx and Tornadofx . How they are inter-related and different from each other.
Also when to use what.
Are there any cases where javafx is more useful/advised to use than Tornadofx or vice-versa?
JavaFX is more like a toolkit (it has all the foundation needed for building a GUI). It is a feature-complete "toolkit", but it is very verbose, and the syntax contains boilerplate code, which makes it hard to maintain. That's where TornadoFX comes in. TornadoFX is like a framework based on that toolkit, which does away with all the boilerplate code, and makes the GUI building declarative, to the point that it resembles HTML.
Also, even though TornadoFX can be used from Java, it is meant to be used from Kotlin (JavaFX can be used from Kotlin also, without any issues).
TornadoFX simplifies and streamlines the GUI building process (makes the code cleaner), but it uses JavaFX "under the hood", and as such, is interoperable with JavaFX.
For example, you can create a widget in pure JavaFX code, and then use it within TornadoFX, or, for example, create a whole window in TornadoFX, and then call it from JavaFX.
The main takeaway here is that TornadoFX doesn't restrict JavaFX in any way, and you can still reach low-level JavaFX stuff from TornadoFX.
Besides just the GUI builders, TornadoFX also contains useful tools like the ViewModel classes, which separate the GUI and logic (which is available, but not mandatory in any way), and some other useful tools.
Personally, I'd always use TornadoFX, because it makes the code very concise and easily-maintainable, while, at the same time, no features of JavaFX are lost.
Currently accepted answer didn't answer this part
Are there any cases where javafx is more useful/advised to use than
Tornadofx
The point of the accepted answer is that for standard simple GUIs Kotlin combined with TornadoFX will get you up an running quick. This is true.
Some examples where straight JavaFX is better:
JavaFX 3D subscenes
interops with Swing (I'm not sure how you would even use Kotlin here, but maybe TornadoFX by itself would work)
Canvas based renders
High Performance custom Event processing
Clearly these are scenarios that do not represent the majority of GUI apps, rather high performance and custom render type applications. So generally speaking if you are starting from scratch... ie... you aren't already well versed in JavaFX, then using TornadoFX is a good starting point.
On that note opting to use Kotlin as a starting point is interesting as well. I personally don't find it that advantageous over just writing in JavaFX, but I have a lot of experience with JavaFX so I might be biased. Also while you are not forced to do so... it is painful to develop in kotlin without intelliJ which is all part of that company's plan for making Kotlin in the first place.
All that said:
and the syntax contains boilerplate code
This is true to an extent and Tornado does reduce the boilerplate a bit by forcing you to go through a standardized set of APIs.
But...
which makes it hard to maintain.
I disagree. It is not "hard" to maintain. It's code you copy/paste one time and likely never changed again. We should not be rushing so fast to obscure and encapsulate every last ASCII character from our code bases in the name of "maintainability" while shooting a torpedo into the side of our performance.

ASP.NET AJAX Framework vs jQuery

What is the difference between AJAX and jQuery. Does both of them do the same thing.If they do what are the pros and cons of each. I'm trying to learn ASP.NET AJAX but not sure if jQuery offers the same features??
Thanks.
MS AJAX library and jQuery are both decent JavaScript libraries that are equally capable of fulfilling the UI needs for an ASP.NET application. The way that each is organised and the approach taken is quite different between the two -
jQuery is based largely around the $ function - it is the constructor for objects that wrap elements matching a given selector, plugins are provided by extending the function prototype and utility functions are provided as properties on the function object.
The Microsoft AJAX library on the other hand takes the approach of extending the prototype of some of JavaScript's native objects and providing useful functions organised within namespaces that should feel familiar to .NET developers. Many of the idioms of programming in your favourite .NET language have been graphed into a JavaScript library.
Having used both considerably, I personally prefer jQuery. For me, it feels more intuitive to use and get things done. The development of jQuery is much more active (in fact I believe that the MS Ajax library will have no more development put into it by Microsoft, with their focus being more on jQuery now as the preferred client side solution) and is more lightweight than MS Ajax. I'm comfortable with the fact that JavaScript is a completely different beast to C# .NET programming and I like to embrace that difference and follow the idioms and conventions that are established for the language.

Automated Flex testing without static AutomationIDs

Has anyone had any luck testing a Flex app without static Automation IDs attached to components? All of the elements in the apps are generated .....
We've investigated FlexMonkey but it appears to be incompatible with any app that utilizes the ExternalInterface. RIATest's scripting language leaves much to be desired...
Thanks-
Jonathan
Unfortunately I don't know much about this kind of stuff, but I went to a talk that presented these tools for TDD:
- Hudson
- Flex Unit 4
I guess there are tutorials online, don't know if it helps with ExternalInterface testing.
Is there anything that prevents you from generating appropriate automationNames for your generated components? This way you should be able to refer to them properly in automation tools.
Are there any other non-changing properties that your generated components have, like maybe 'id'? If so you can use these properties to address the components. This is definitely possible in RIATest.
FunFX is a Flex automation tool that allows you to access components via ID, "automation name", "automation value" or index. While using something like the component index might be less than ideal for robust tests, if that's all that's stable, it might be worth a try. And it's written in Ruby, so that should satisfy any "real programming language" related requirements. :)
We added an "automationPrefix" property to many of our custom controls (particularly those that are reused many times on a single screen), and wrote code to append the beginning of the automationName property on any child controls. Setting the automationName was the most important parting of enabling automation testing on our Flex apps. There are several ways you could modify the automationName to be unique without making it completely static at the level that most test automation packages need it. We are currently using QTP as the test automation tool of choice.

Why use a Flex framework like Cairngorm or Mate?

From what I understand a framework reduces complexity in areas that are common, like a log-in system. I use ASP.NET MVC at work and have done some work in Zend Framework but do not get how a framework helps with client side development. The reason ASP.NET MVC is used at work is for Unit Testing - does a Flex framework help with this too?
Please let me know why I should or should not use a framework with Flex?
The short answer is: it depends on the framework. :) My thoughts below:
Flex is itself a framework, and you can write reasonable applications without the need for any additional framework. Flash has a built-in event model that allows for bubbling events, so you can dispatch an event in a deeply-nested user interface component and have a listener higher up in the hierarchy that handles the event. The event handler can delegate to your model, which retrieves data from the server, and Flex's binding support can ensure that your views are appropriately updated from the model. I think it's important to understand that Flex applications can and should be written more or less according to that approach, and that any additional framework should help facilitate that approach, rather than providing its own way of doing things that ends up coupling you to the framework.
That being said, an extra framework that helps facilitate this approach can absolutely provide value. I would recommend Mate or Swiz because I think they achieve this goal. They don't try to reinvent the wheel or replace parts of the Flash / Flex APIs; instead they complement them. The dependency injection features make it much easier to provide data to your views, but without coupling them to any framework. There are a number of utilities available to make it easier to work with remote services. They also have a utils to facilitate testing or even persisting data in shared objects.
I have also worked with Cairngorm in the past and I would not recommend it. CG is notorious for requiring you to create a ton of classes that adhere to CG-specific APIs and requiring you to use many of their Singleton implementations which make your app brittle and hard to test in isolation. It is based on a number of J2EE patterns which fell out of favor in the Java community at least 5 years ago.
I've read a little about PureMVC and while I can't speak to its invasive nature, I think that reinventing the event model (called "notifications") is silly and couples you to their framework. Sure, you can say it "insulates" you from the Flash event model in case it changes, but I'd say the odds of PureMVC changing their notification model is far more likely than Adobe changing the event model. :)
If you've ever tried building a slightly large application, or one at all complex, things can quickly get out of control. I don't know how many projects I bailed on when I was first starting out because I didn't know patterns, or how to make parts of the system communicate without being tied to each other, or dependent on each other.
So, basically a framework is a collection of patterns put together. Theoretically, if you learn to follow the "rules" of a (tried and true) framework, your app will not get out of control to the point where you find yourself fixing one bug and causing two. I've been there and it's not fun.
I also found that by learning to use a framework you initially don't have to know so much about the patterns behind what you're doing. But before long you'll get a good handle on the patterns used and you'll be able to apply them in new situations or find a better pattern. So it's a good learning tool as well.
I'm sure people will have arguments against using frameworks -- this is just my experience. But if you become familiar with a few, you will likely find that one might be suitable for one project but not another.
As far as Flex frameworks, I personally like PureMVC. In all honesty the only other one I've given a good amount of time to is Cairngorm. But I like PureMVC because it feels right to me, but also it's generally not dependent on so much on the built-in Actionscript classes. For example, it uses it's own notification system. So if the notifications change in Flex, they'll still work in your PureMVC app. Also, the creator Cliff is super helpful in his forums, and he's really passionate about it. And the documentation is great.
I recommend coming up with a super basic app, and building it without any frameworks, then again with a couple others. You don't have to finish the app, but just get a feel for what's behind the frameworks.
You may find value in using a framework if:
You work in a team environment and want to be sure everyone uses the same approach
You have a large, sophisticated app and want to communicate effectively between parts of the app
You want to be able to hire additional programmers and have them be productive quickly
You want to ensure your application is built with a proven architecture
You want to leverage the knowledge of design patterns and solutions that are known to work well
You want to simplify a complex application
Here's a great article on Flex frameworks.
Flex Framework Comparison
And, I agree with the conclusion...Mate is a great Flex Framework.
Another interesting framework not mentioned in this article is Spicefactory's Parsley.
I use PureMVC (which is an MVC-framework for Flex) for my larger applications. Like 99miles stated, it depends on the application size.
If you just have to make a (relatively) small tool/application, you can get it going with just Flex. But if you want to create a large, complex application a Framework might come in handy.
The main reason I use PureMVC in Flex is because of the Model-View-Controller architecture. This separates the presentation layer from the business layer and works a lot with events and notifications. This gives you a lot of control in creating reusable classes/controls in Flex in a relatively simple way.
As I said before, for a small tool/app/website I wouldn't recommend using a framework, because in that case it might be to time consuming and complex. But for the larger applications, frameworks are quite handy.
More information on the MVC architecture can be found here.
Hope this helps :)

Can C++.NET and J# be used to make a website?

I didn't see an option to create a web site in the c++ area. Is there a way around this or am I just stuck with C# and VB.NET
A bit of googling turned this up, not sure how applicable it still is:
http://www.codeproject.com/KB/mcpp/helloworldmc.aspx
However, I'd question WHY you'd want to use C++.NET over C#, given that the languages are fairly similar at the basic level. Any perceived "speedups" would probably not be very noticable given that they both compile to the same IL, and as such are both subject to the JIT-compiler.
You can probably make your website work using C++/CLI. There is no tight coupling between a .NET page (aspx or ascx) and the language of implementation. You might even get the intellisense from within the aspx/ascx files but don't quote me on that.
So to set this up you would need to create a C++/CLI project and use managed C++ to extend Page, Control, etc classes, use HttpContext etc.
Another question is whether or not there is any point doing that. You would still be targeting .NET and calling to the same API. There won't be much performance benefit if at all and you will lose the IDE support for creating controls and you wouldn't be able to use WebForms from the designer.
Edit. If you haven't done ASP.NET before you will almost definitely be firing up a normal ASP.NET project and seeing how to implement something, which classes to extend etc. So it kind of defeats the idea of using another language.
You can, in theory, use any .NET language to build ASP.NET pages. F#, for example, is fully supported in VS 2010. Whether all languages are fully supported in the tools is another question -- particularly for a language like J# that has been deprecated beyond VS 2005 and doesn't support the full depth of features of the other languages (such as the ability to create new attributes).
At a minimum, you will need to do things like define an appropriate build provider to get things going.

Resources