News

Rails 2.0 Finally Released - What's New

Ruby on Rails is one of the most used frameworks for new web 2.0 startups. This 2.0 release is the second recent present that we web developers have recieved this Christmas (the first was OpenID 2.0). Since Rails 2.0 was recently released I wanted to write about the recent changes.

Below is a rundown of the changes write from the Ruby on Rails blog.

Action Pack: Resources

This is where the bulk of the action for 2.0 has gone. We’ve got a slew of improvements to the RESTful lifestyle. First, we’ve dropped the semicolon for custom methods instead of the regular slash. So /people/1;edit is now /people/1/edit. We’ve also added the namespace feature to routing resources that makes it really easy to confine things like admin interfaces:

map.namespace(:admin) do |admin|
  admin.resources :products,
    :collection => { :inventory => :get },
    :member     => { :duplicate => :post },
    :has_many   => [ :tags, :images, :variants ]
end

Which will give you named routes like inventory_admin_products_url and admin_product_tags_url. To keep track of this named routes proliferation, we’ve added the “rake routes” task, which will list all the named routes created by routes.rb.

We’ve also instigated a new convention that all resource-based controllers will be plural by default. This allows a single resource to be mapped in multiple contexts and still refer to the same controller. Example:


  # /avatars/45 => AvatarsController#show
  map.resources :avatars

  # /people/5/avatar => AvatarsController#show 
  map.resources :people, :has_one => :avatar

Action Pack: Multiview

Alongside the improvements for resources come improvements for multiview. We already have #respond_to, but we’ve taken it a step further and made it dig into the templates. We’ve separated the format of the template from its rendering engine. So show.rhtml now becomes show.html.erb, which is the template that’ll be rendered by default for a show action that has declared format.html in its respond_to. And you can now have something like show.csv.erb, which targets text/csv, but also uses the default ERB renderer.

So the new format for templates is action.format.renderer. A few examples:

  • show.erb: same show template for all formats
  • index.atom.builder: uses the Builder format, previously known as rxml, to render an index action for the application/atom+xml mime type
  • edit.iphone.haml: uses the custom HAML template engine (not included by default) to render an edit action for the custom Mime::IPHONE format

Speaking of the iPhone, we’ve made it easier to declare “fake” types that are only used for internal routing. Like when you want a special HTML interface just for an iPhone. All it takes is something like this:

# should go in config/initializers/mime_types.rb Mime.register_alias "text/html", :iphone class ApplicationController < ActionController::Base before_filter :adjust_format_for_iphone private def adjust_format_for_iphone if request.env["HTTP_USER_AGENT"] && request.env["HTTP_USER_AGENT"][/(iPhone|iPod)/] request.format = :iphone end end end class PostsController < ApplicationController def index respond_to do |format| format.html # renders index.html.erb format.iphone # renders index.iphone.erb end end end

You’re encouraged to declare your own mime-type aliases in the config/initializers/mime_types.rb file. This file is included by default in all new applications.

Action Pack: Record identification

Piggy-backing off the new drive for resources are a number of simplifications for controller and view methods that deal with URLs. We’ve added a number of conventions for turning model classes into resource routes on the fly. Examples:


  # person is a Person object, which by convention will 
  # be mapped to person_url for lookup
  redirect_to(person)
  link_to(person.name, person)
  form_for(person)

Action Pack: HTTP Loving

As you might have gathered, Action Pack in Rails 2.0 is all about getting closer with HTTP and all its glory. Resources, multiple representations, but there’s more. We’ve added a new module to work with HTTP Basic Authentication, which turns out to be a great way to do API authentication over SSL. It’s terribly simple to use. Here’s an example (there are more in ActionController::HttpAuthentication):

class PostsController < ApplicationController USER_NAME, PASSWORD = "dhh", "secret" before_filter :authenticate, :except => [ :index ] def index render :text => "Everyone can see me!" end def edit render :text => "I'm only accessible if you know the password" end private def authenticate authenticate_or_request_with_http_basic do |user_name, password| user_name == USER_NAME && password == PASSWORD end end end

We’ve also made it much easier to structure your JavaScript and stylesheet files in logical units without getting clobbered by the HTTP overhead of requesting a bazillion files. Using javascript_include_tag(:all, :cache => true) will turn public/javascripts/.js into a single public/javascripts/all.js file in production, while still keeping the files separate in development, so you can work iteratively without clearing the cache.

Along the same lines, we’ve added the option to cheat browsers who don’t feel like pipelining requests on their own. If you set ActionController::Base.asset_host = “assets%d.example.com”, we’ll automatically distribute your asset calls (like image_tag) to asset1 through asset4. That allows the browser to open many more connections at a time and increases the perceived speed of your application.

Action Pack: Security

Making it even easier to create secure applications out of the box is always a pleasure and with Rails 2.0 we’re doing it from a number of fronts. Most importantly, we now ship we a built-in mechanism for dealing with CRSF attacks. By including a special token in all forms and Ajax requests, you can guard from having requests made from outside of your application. All this is turned on by default in new Rails 2.0 applications and you can very easily turn it on in your existing applications using ActionController::Base.protect_from_forgery (see ActionController::RequestForgeryProtection for more).

We’ve also made it easier to deal with XSS attacks while still allowing users to embed HTML in your pages. The old TextHelper#sanitize method has gone from a black list (very hard to keep secure) approach to a white list approach. If you’re already using sanitize, you’ll automatically be granted better protection. You can tweak the tags that are allowed by default with sanitize as well. See TextHelper#sanitize for details.

Finally, we’ve added support for HTTP only cookies. They are not yet supported by all browsers, but you can use them where they are.

Action Pack: Exception handling

Lots of common exceptions would do better to be rescued at a shared level rather than per action. This has always been possible by overwriting rescue_action_in_public, but then you had to roll out your own case statement and call super. Bah. So now we have a class level macro called rescue_from, which you can use to declaratively point certain exceptions to a given action. Example:


  class PostsController < ApplicationController
    rescue_from User::NotAuthorized, :with => :deny_access

    protected
      def deny_access
        ...
      end
  end

Action Pack: Cookie store sessions

The default session store in Rails 2.0 is now a cookie-based one. That means sessions are no longer stored on the file system or in the database, but kept by the client in a hashed form that can’t be forged. This makes it not only a lot faster than traditional session stores, but also makes it zero maintenance. There’s no cron job needed to clear out the sessions and your server won’t crash because you forgot and suddenly had 500K files in tmp/session.

This setup works great if you follow best practices and keep session usage to a minimum, such as the common case of just storing a user_id and a the flash. If, however, you are planning on storing the nuclear launch codes in the session, the default cookie store is a bad deal. While they can’t be forged (so is_admin = true is fine), their content can be seen. If that’s a problem for your application, you can always just switch back to one of the traditional session stores (but first investigate that requirement as a code smell).

Action Pack: New request profiler

Figuring out where your bottlenecks are with real usage can be tough, but we just made it a whole lot easier with the new request profiler that can follow an entire usage script and report on the aggregate findings. You use it like this:

$ cat login_session.rb get_with_redirect '/' say "GET / => #{path}" post_with_redirect '/sessions', :username => 'john', :password => 'doe' say "POST /sessions => #{path}" $ ./script/performance/request -n 10 login_session.rb

And you get a thorough breakdown in HTML and text on where time was spent and you’ll have a good idea on where to look for speeding up the application.

Action Pack: Miscellaneous

Also of note is AtomFeedHelper, which makes it even simpler to create Atom feeds using an enhanced Builder syntax. Simple example:


  # index.atom.builder:
  atom_feed do |feed|
    feed.title("My great blog!")
    feed.updated((@posts.first.created_at))

    for post in @posts
      feed.entry(post) do |entry|
        entry.title(post.title)
        entry.content(post.body, :type => 'html')

        entry.author do |author|
          author.name("DHH")
        end
      end
    end
  end

We’ve made a number of performance improvements, so asset tag calls are now much cheaper and we’re caching simple named routes, making them much faster too.

Finally, we’ve kicked out in_place_editor and autocomplete_for into plugins that live on the official Rails SVN.

Active Record: Performance

Active Record has seen a gazillion fixes and small tweaks, but it’s somewhat light on big new features. Something new that we have added, though, is a very simple Query Cache, which will recognize similar SQL calls from within the same request and return the cached result. This is especially nice for N+1 situations that might be hard to handle with :include or other mechanisms. We’ve also drastically improved the performance of fixtures, which makes most test suites based on normal fixture use be 50-100% faster.

Active Record: Sexy migrations

There’s a new alternative format for declaring migrations in a slightly more efficient format. Before you’d write:

create_table :people do |t|
  t.column, "account_id",  :integer
  t.column, "first_name",  :string, :null => false
  t.column, "last_name",   :string, :null => false
  t.column, "description", :text
  t.column, "created_at",  :datetime
  t.column, "updated_at",  :datetime
end

Now you can write:

create_table :people do |t|
  t.integer :account_id
  t.string  :first_name, :last_name, :null => false
  t.text    :description
  t.timestamps
end

Active Record: Foxy fixtures

The fixtures in Active Record has taken a fair amount of flak lately. One of the key points in that criticism has been the work with declaring dependencies between fixtures. Having to relate fixtures through the ids of their primary keys is no fun. That’s been addressed now and you can write fixtures like this:


  # sellers.yml
  shopify:
    name: Shopify

  # products.yml
  pimp_cup:
    seller: shopify
    name: Pimp cup

As you can see, it’s no longer necessary to declare the ids of the fixtures and instead of using seller_id to refer to the relationship, you just use seller and the name of the fixture.

Active Record: XML in, JSON out

Active Record has supported serialization to XML for a while. In 2.0 we’ve added deserialization too, so you can say Person.new.from_xml(“
David“) and get what you’d expect. We’ve also added serialization to JSON, which supports the same syntax as XML serialization (including nested associations). Just do person.to_json and you’re ready to roll.

Active Record: Shedding some weight

To make Active Record a little leaner and meaner, we’ve removed the acts_as_XYZ features and put them into individual plugins on the Rails SVN repository. So say you’re using acts_as_list, you just need to do ./script/plugin install acts_as_list and everything will move along like nothing ever happened.

A little more drastic, we’ve also pushed all the commercial database adapters into their own gems. So Rails now only ships with adapters for MySQL, SQLite, and PostgreSQL. These are the databases that we have easy and willing access to test on. But that doesn’t mean the commercial databases are left out in the cold. Rather, they’ve now been set free to have an independent release schedule from the main Rails distribution. And that’s probably a good thing as the commercial databases tend to require a lot more exceptions and hoop jumping on a regular basis to work well.

The commercial database adapters now live in gems that all follow the same naming convention: activerecord-XYZ-adapter. So if you gem install activerecord-oracle-adapter, you’ll instantly have Oracle available as an adapter choice in all the Rails applications on that machine. You won’t have to change a single line in your applications to take use of it.

That also means it’ll be easier for new database adapters to gain traction in the Rails world. As long as you package your adapter according to the published conventions, users just have to install the gem and they’re ready to roll.

Active Record: with_scope with a dash of syntactic vinegar

ActiveRecord::Base.with_scope has gone protected to discourage people from misusing it in controllers (especially in filters). Instead, it’s now encouraged that you only use it within the model itself. That’s what it was designed for and where it logically remains a good fit. But of course, this is all about encouraging and discouraging. If you’ve weighed the pros and the cons and still want to use with_scope outside of the model, you can always call it through .send(:with_scope).

ActionWebService out, ActiveResource in

It’ll probably come as no surprise that Rails has picked a side in the SOAP vs REST debate. Unless you absolutely have to use SOAP for integration purposes, we strongly discourage you from doing so. As a naturally extension of that, we’ve pulled ActionWebService from the default bundle. It’s only a gem install actionwebservice away, but it sends an important message none the less.

At the same time, we’ve pulled the new ActiveResource framework out of beta and into the default bundle. ActiveResource is like ActiveRecord, but for resources. It follows a similar API and is configured to Just Work with Rails applications using the resource-driven approach. For example, a vanilla scaffold will be accessible by ActiveResource.

ActiveSupport

There’s not all that much new in ActiveSupport. We’ve a host of new methods like Array#rand for getting a random element from an array, Hash#except to filter down a hash from undesired keys and lots of extensions for Date. We also made testing a little nicer with assert_difference. Short of that, it’s pretty much just fixes and tweaks.

Action Mailer

This is a very modest update for Action Mailer. Besides a handful of bug fixes, we’ve added the option to register alternative template engines and assert_emails to the testing suite, which works like this:

  1. Assert number of emails delivered within a block:
    assert_emails 1 do
    post :signup, :name => ‘Jonathan’

    end

Rails: The debugger is back

To tie it all together, we have a stream of improvements for Rails in general. My favorite amongst these is the return of the breakpoint in form of the debugger. It’s a real debugger too, not just an IRB dump. You can step back and forth, list your current position, and much more. It’s all coming from the gracious note of the ruby-debug gem. So you’ll have to install that for the new debugger to work.

To use the debugger, you just install the gem, put “debugger” somewhere in your application, and then start the server with—debugger or -u. When the code executes the debugger command, you’ll have it available straight in the terminal running the server. No need for script/breakpointer or anything else. You can use the debugger in your tests too.

Rails: Clean up your environment

Before Rails 2.0, config/environment.rb files every where would be clogged with all sorts of one-off configuration details. Now you can gather those elements in self-contained files and put them under config/initializers and they’ll automatically be loaded. New Rails 2.0 applications ship with two examples in form of inflections.rb (for your own pluralization rules) and mime_types.rb (for your own mime types). This should ensure that you need to keep nothing but the default in config/environment.rb.

Rails: Easier plugin order

Now that we’ve yanked out a fair amount of stuff from Rails and into plugins, you might well have other plugins that depend on this functionality. This can require that you load, say, acts_as_list before your own acts_as_extra_cool_list plugin in order for the latter to extend the former.

Before, this required that you named all your plugins in config.plugins. Major hassle when all you wanted to say was “I only care about acts_as_list being loaded before everything else”. Now you can do exactly that with config.plugins = [ :acts_as_list, :all ].

And hundreds upon hundreds of other improvements

What I’ve talked about above is but a tiny sliver of the full 2.0 package. We’ve got literally hundreds of bug fixes, tweaks, and feature enhancements crammed into Rails 2.0. All this coming off the work of tons of eager contributors working tirelessly to improve the framework in small, but important ways.

I encourage you to scourger the CHANGELOGs and learn more about all that changed.

Click here to read the full post on the Ruby on Rails blog.

There are a lot of big changes here that should be useful when developing using Rails. One of my personal favorites is the ability to change XML into JSON, which being someone that likes JSON could come in handy (especially if you are getting data from a web service that is using XML and your application needs to use JSON). I look forward to seeing what new applications will be built on Rails 2.0.

Special thanks to thegreatone who submitted the Rails 2.0 post from the Ruby on Rails blog on Social Ajaxonomy.
Click here to see the post on Social Ajaxonomy

If you would like to submit a post for chance to have us blog about it click here to go to Social Ajaxonomy or click on the "Social" link located at the top link navigation of Ajaxonomy.

rails.png

Ajaxonomy.com Launches Social Network

Tagged:  

Ajaxonomy.com is proud to present it's latest addition, Social Ajaxonomy, a social network for developers to share links in a digg-style environment.

This is where the community can submit links to articles, sites, posts, and whatever else it finds pertaining to Ajax and other interesting web technologies and further provides users with an opportunity to vote on which links they find useful and valuable. Top articles have a chance to appear in the main blog. So, we hope that you would register an account, build a profile, and start submitting and voting for links! We look forward to growing in this community with you.

Please post your comments!

JavaScript Array Remove Method

Tagged:  

John Resig just published a handy little JavaScript method to remove elements from an array.

Here's his method:

   1. // Array Remove - By John Resig (MIT Licensed)
   2. Array.prototype.remove = function(from, to) {
   3.   var rest = this.slice((to || from) + 1 || this.length);
   4.   this.length = from < 0 ? this.length + from : from;
   5.   return this.push.apply(this, rest);
   6. };

And here are some examples of its use:


   1. // Remove the second item from the array
   2. array.remove(1);
   3. // Remove the second-to-last item from the array
   4. array.remove(-2);
   5. // Remove the second and third items from the array
   6. array.remove(1,2);
   7. // Remove the last and second-to-last items from the array
   8. array.remove(-2,-1);

Here are the goals he had for the method:

  • It had to add an extra method to an array object that would allow me to remove an item by index (e.g. array.remove(1) to remove the second item).
  • It had to be able to remove items by negative index (e.g. array.remove(-1) to remove the last item in the array).
  • It had to be able to remove a group of items by index, and negative index (e.g. array.remove(0,2) to remove the first three items and array.remove(-2,-1) to remove the last two items).
  • It had to be destructive (modifying the original array).
  • It had to behave like other destructive array methods (returning the new array length - like how push and unshift work).

To get more information about this method, click here to visit John's blog.

Ext 2.0 Final Released

If you haven't heard of Ext before, click here to learn all about it.

Here's the annoucement right from the Ext JS Blog:

The Ext team is proud to announce that the official release of Ext v2.0 is available for download. This new version of the Ext framework is the culmination of many long hours of work and dedication by the Ext Core team as well as our community of testers and supporters. Ext 2.0 is a dramatic step forward from all previous versions of Ext, providing increased performance, ease of configurations, flexibility and UI capabilities.

We’ve also made learning how to use Ext much easier with a completely revamped document center and expanded & better organized samples. All of this without a significant library size increase in this new version.

New features include:

  • Grouping & Group Summary
  • Ext 2.0 introduces highly configurable single-level column grouping capabilities as well as summary rollups at the group level.

  • Scrolling Tabs
  • The new Ext 2.0 scrolling tabs are truly amazing and provide for a much more flexible UI then traditional static-based tabs.

  • Anchor Layout
  • The team extended the FormPanel component to allow form controls (and other components) to be anchored to a specific size within a specific container.

  • Column Tree
  • The Ext tree panel can be customized to add support for columns in the nodes.

There's also a New API Documentation Center, including:

Click here to download Ext 2.0

NetBeans IDE 6.0 Released - Includes Ruby Support

Tagged:  

NetBeans has released version 6.0 of their development IDE. Here's the announcement on their site:

NetBeans.org is proud to announce the availability of NetBeans IDE 6.0! Download now.

The focus of NetBeans IDE 6.0 is superior developer productivity with a smarter, faster editor, and the integration of all NetBeans products into one IDE. NetBeans IDE 6.0 features Ruby/JRuby/Ruby on Rails support, enhancements for improved Swing development, a new Visual Game Designer, updated Data Binding support, integrated Profiling, and more. The new installer lets you customize your download preferences--use it to choose the features and runtimes you need.

The NetBeans IDE is a modular, standards-based, integrated development environment (IDE) written in the Java programming language. The NetBeans project consists of an open source IDE and an application platform, which can be used as a generic framework to build any kind of application.

Among the many new features and enhancements, the IDE now supports Ruby/JRuby/Ruby on Rails.


  • Project Support. Quickly create Ruby projects with logical structure, run Ruby files, configure other Ruby interpreters (such as JRuby or native Ruby), locate and install Ruby Gems through a graphical wizard, create and execute unit tests, run RSpec specification files, jump between a Ruby file and its corresponding unit test or spec file, and so on. View Demo.
  • Advanced Ruby Editing. Advanced code editing for Ruby, using semantic information about the program to offer code completion, showing available classes and methods for the current expression, along with the associated RDoc documentation. The syntax highlighting is enhanced with semantic information, such that unused local variables and parameters are shown in gray. There are many other editing features, including Goto Declaration for jumping to the declaration point of a class or method reference. View Demo.
  • Ruby Debugger. Single-step or run through Ruby code, set breakpoints, look at local variables, navigate the call stack, switch threads, and evaluate expressions by just hovering the mouse over the variable in the Editor. There is also support for the "fast debug" extension.
  • Ruby on Rails Support. Generate Rails projects, or generate code through the Rails code generator graphical wizard, which offers documentation on the plugins within the wizard itself. Third party generators are also supported. Furthermore, there are actions for jumping quickly between a Rails action and its corresponding View, or warping to the browser for the URL most relevant to the file you are editing. Database migrations and Rake targets are supported as well. Finally, RHTML files are highlighted (along with improved NetBeans 6.0 support for related files, such as JavaScript and CSS). View Demo.

Other features include:

  • Editor Improvements
  • Easier Installation and Upgrading
  • Swing GUI Development
  • Profiling
  • Web and Java EE
  • Mobility
  • SOA
  • UML
  • C/C++
  • NetBeans Platform API Improvements



Click here to read more about these features or to download the new IDE.


Building Interactive Prototypes with jQuery

Tagged:  

John Resig, creator and lead developer of jQuery, recently gave a talk at @Media Ajax on jQuery and has posted his presentation on his blog. As he puts it - the talk ranges from the absolute basics to building and using plugins - it's definitely worth checking out.



Click Here to Download the PDF

John also posted example links mentioned in his talk (w/source code) including the source code to a completed Ajax social networking site example.

To read more about this presentation, check out John's blog.

JavaFX: The Second Coming of Swing

Tagged:  

At JavaOne 2007, Sun announced with much fanfare its JavaFX platform including two major components: Mobile and Scripting. This article will focus on the most interesting aspect of this new platform (for Swing old-timers, at least), the Java FX Script component. For interested parties, all of the relevant files can be found in the OpenJFX project hosted on java.net. The distribution is currently just a dump of the Subversion tree, but contains plenty of goodies to get started with the language. For those who are merely interested in sampling what Java FX can do, there are plenty of JNLP-based demos which can be launched from the main page (a 1.5+ JRE is required to be installed on the client).

The First Coming of Swing

Some of us may remember the first time Sun introduced AWT (later to evolve into Swing) to an excited world in 1995. It wasn't long before many developers were eagerly creating Applets in their web browsers, marvelling at the prospect of code being streamed over the network and executed in their browser. Applets were cool. Applets were hot. Applets were...well, ugly. Back then, though, Windows 95 defined computer aesthetics, and Applets didn't suffer too much in comparison.

Fast forward several years, and the picture has changed rapidly. Swing is no longer the disruptive technology that it once seemed to be. After Microsoft began neglecting its Java implementation for Windows/IE (coincidentally after a long battle with Sun over its embrace-and-extend tactics) and Netscape lost the browser wars, Swing had become less important as a technology. Most web developers moved on to using Flash, Java moved into its server-side stronghold (having failed to really take off on the desktop), and Swing was left to stagnate. Swing continued to improve over the years, but Sun's--and most of the world's--attention had moved elsewhere.

Enter JavaFX

In 2005 Sun acquired SeeBeyond Technology Corporation, an employee by the name of Chris Oliver, and a little creation of his called F3 (Form Follows Function), later dubbed JavaFX Script. Sun saw its opportunity to position itself in the Rich Internet Application (RIA) market, and set its sights on competitors, Microsoft's Silverlight and Adobe's AIR (Flex). It's too early to tell what the success of JavaFX Script will be, but Swing has come a long way since the heady early days of the Internet and JavaFX may be just the trick in smoothing some of the pain points in developing with Swing.

Introduction to JavaFX Script

To veteran Java developers, JavaFX Script will seem both familiar and strange at the same time. Depending on which style of the language you develop in, it can look either like JavaScript or like "CSS with scripting". What follows is an example, written in both styles, with the obligatory "Hello World":

Frame {
title: "Hello World Frame"
width: 250
content: Label {
text: "Hello World"
}
visible: true
}

Figure 1a: Hello World in "CSS with Scripting" style

Or

var f = new Frame();
f.title = "Hello World Frame";
f.width = 250;
var label = new Label();
label.text = "Hello World";
f.content = label;
f.visible = true;

Figure 1b: Hello World in JavaScript style

Run either of these examples in the JavaFXPad application (provided in the distribution or via JNLP on the web site), and you will see the familiar Swing frame with its content as a single label containing the text "Hello World". It isn't hard to see that JavaFX is much more compact than the equivalent Java code. That in itself addresses one of the major difficulties in developing in Swing, but JavaFX Script is more than that. The language contains "shortcuts" that make more sophisticated development in Java 2D and 3D as easy as doing it in a declarative language such as SVG or Flex. The default code displayed when JavaFXPad launches demonstrates this convincingly, showing how easy it is to do scaling, transforms, or create a shadow filter.

Core Language

JavaFX Script contains a lot of syntactic similarities to both Java and JavaScript, so many constructs will already be familiar to an experienced developer. This section will highlight some of the important differences and unique features of JFX Script.

Primitives Values

JFX Script has four primitives: String, Boolean, Number, and Integer (all whole number values, i.e., byte, int, long, etc.).

Operators

JFX Script replaces the more C++-like !, &&, and || with not, and, and or.

For Loops

JFX Script has a version of the "foreach" constructs that allows iteration over an interval, like so

for(i in [0..5]) {
//do something
}

Operations and Functions

JFX Script has two different keywords to declare methods: operation and function. Funcions in JFX Script are forbidden to have loops or conditional operands in order to minimize potential side-effects. Why is this needed? Because a function re-evaluates its return value every time one of its input parameters or referenced variables is changed. This turns out to be very handy when you want to bind some output to values that frequently change. Operations are more like normal Java methods.

IDE Support

Obviously, the JavaFXPad application is insufficient for real-world development, so early versions of plugins for using JFX Script with Netbeans and Eclipse are available. Of the two, the Netbeans plugin seems further along in its development (it is a Sun technology, of course ;) ), but expect this to change as the project nears release. See the OpenJFX site for downloads and instructions.

Conclusion

JavaFX Script is still very much in pre-release stage, but is already looking like an extremely promising technology. Currently, it runs in interpreted mode but a compiler is being developed for the language that will compile scripts straight into Java bytecode, giving the same performance as the equivalent Swing code with a fraction of the effort. It definitely has an uphill battle in the race for the RIA market, but for existing developers that use Swing it is already a winner.

Syndicate content