Online coverage from the Sun Developer Network staff 2008 JavaOne Conference

Thursday May 08, 2008

by Ed Ort, Sun Microsystems Staff Writer

One of the powerful features added to the NetBeans IDE 6 was support for Ruby, JRuby, and Ruby on Rails. The Ruby programming language has become popular with a growing number of developers because of its simplicity and its productivity features. As is the case for the Java programming language, Ruby is object-oriented, although in Ruby everything is an object -- even what are called primitives in the Java language. Ruby is also open-source and has a large and active community. Ruby's creator, Yukihiro Matsumoto, known to the Ruby world as "Matz", intended the language not only to be easy to use and highly productive, but also fun.

JRuby is an open-source pure Java implementation of the Ruby programming language. Because of its tight integration with the Java platform, JRuby allows Java applications to call into Ruby code. It also allows Ruby applications to call into Java code. This Ruby-Java integration is a very handy feature for developers.

Ruby on Rails, often shortened to Rails, is a web application framework written in the Ruby programming language. The framework is designed to make web application development faster, simpler, and more efficient. Web applications built with Rails are based on the model-view-controller (MVC) architecture. Devotees claim (rightfully so) that using Rails enables them to create a working web application in minutes. Like Ruby, Rails has become very popular. It's also open source and has a large community of contributors.

With this added support for Ruby, JRuby, and Rails, developers can take advantage of the NetBeans IDE's sophisticated project management, editing, and debugging features in building their Rails applications.

Tor Norbye and Brian Leonard

In the technical session titled "The NetBeans Ruby IDE: You Thought Rails Development Was Fun Before," Sun Principal Engineer Tor Norbye and Sun senior engineer Brian Leonard, both NetBeans experts, used the NetBeans IDE to quickly build a Ruby on Rails application -- a simple web application that tallies votes for presidential candidates. In the process, they demonstrated many of the features in the IDE that make it an attractive tool for Rails development.

Norbye and Leonard presented far too many features during the session for me to cover in this short article, so I'll highlight just a few of them.

  • Project management. NetBeans allows developers to create a Rails project from existing files or to create a project "from scratch." In addition, developers can specify a specific Ruby interprter when they create a project, for example, the native Ruby interpreter or the JRuby interpreter. The interpreter can also be changed during the development process.

  • Code generators. One of the productivity features in Rails is the use of code generators, saving developers from doing a lot of boilerplate coding. NetBeans provides all the standard code generators that come with Rails such as scaffolds, which construct most of the models and views for a basic MVC-based Rails application, models, controllers, database migrations, and integration tests. Additional generators can be easily installed into NetBeans.

  • Code Completion. Code completion is available in the NetBeans editor for all Rails APIs. It's also available for database parameter completion in ActiveRecord calls, as well as for hash keys and hash values.

  • Editing in Erb Files. Erb files are the Rails version of JavaServer Pages (JSP) technology files, allowing developers to embed executable Ruby code within the HTML code on the page. An embedded block of Ruby code is called a scriptlet. All the NetBeans editing features available to Ruby are also available to scriptlets. In addition, the editing features extend to other code in an Erb file such as HTML, JavaScript, or CSS.

  • Enhanced Documentation. RDoc is the Ruby equivalent to JavaDoc, that is, formal documentation of the language. The NetBeans editor does custom RDoc rendering. A nice aspect of this is that the editor preformats code fragments and highlights syntax in examples within RDoc entries. The editor also does this for Erb files.

  • Quickfixes. The editor checks for many common programming mistakes, providing hints for fixes. It also identifies deprecated Rails constructs and suggests replacements.

  • Source navigation. NetBeans has some nice shortcuts for Rails application editing. For example, press Ctrl-click on a class, method, field, or variable to jump to its declaration. Press Ctrl-Shift-T to jump between a file and its test. Press Ctrl-Shift-A to jump between a controller and its view.

  • Context-sensitive execution. Selecting Run File (Shift-F6) performs a context-sensitive action for the current file. For example, if the context is a controller, view, or helper, selecting Run File opens the browser and shows or reloads the URL corresponding to the controller or view (starting the Rails server if necessary). By comparison, if the context is a test, selecting Run File runs the test.

  • Advanced debugging. NetBeans supports a comprehensive set of debugging tasks for Rails developers such as stepping through code, setting breakpoints, inspecting local variables, navigating call stacks, and running tests. It also enables debugging of both template files as well as Ruby files.

  • Java integration. NetBeans provides code templates that makes it easy to include Java modules into a Rails application. In addition, Java classes can be used just like Ruby classes. Leonard mentioned that the JRuby engineers in Sun went to great lengths to make working with Java code in Ruby more Ruby like.

  • Flexible deployment. NetBeans supports deploying a Rails application to any Java servlet container such as Tomcat or GlassFish. Leonard pointed out that most deployment environments do not include Ruby containers. So this feature enables developers to deploy their Rails applications in their existing infrastructure.

Unfortunately, Leonard could not get the voting application to run. It's likely that during the talk, Norbye or Leonard added some errant code to the working code that was originally folded into the project. However, this gave Leonard a chance to show more debugging features.

I was impressed with the comprehensive set of Rails development features already in NetBeans, but enhancements are coming. Norbye said that future plans include more extensive type inference, enhanced test support, better console integration, more refactorings and quickfixes, improved Java integration, and support for additional Ruby frameworks.

Despite the application execution problems, this was an impressive display of Rails support in NetBeans.

Comments:

Post a Comment:
  • HTML Syntax: NOT allowed