BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage Articles NetBeans: Ruby Developer's New Best Friend (Part 2)

NetBeans: Ruby Developer's New Best Friend (Part 2)

This item in japanese

Bookmarks

This article is a second part in series of articles about NetBeans & Ruby. You can read the first part of the article which is an introduction to the NetBeans Ruby support here.

In this part I am going to focus on Ruby on Rails tooling and various additional functionality that help you being productive inside the editor and outside of it. An IDE stands for Integrated Development Environment so you'll see that by using NetBeans you don't need to switch to the command line anymore to work with Ruby and Rails.

Ruby on Rails support

When creating a new Ruby application in NetBeans you can choose from different templates -- you can either create a regular Ruby application or a Ruby on Rails application.

When creating a Rails project the IDE lets you choose whether you want to use native Ruby or JRuby, which of the database drivers you want to use (including JDBC in case of JRuby) and you can also update to the most recent version of Rails easily. Once you confirm the New Project dialog, the project is created with default directory structure. This is a great advantage of Rails because all applications look familiar, so you can get easily get started when you come to an application that somebody else created. You get a nice logical overview of the files in NetBeans' project explorer and you can navigate to different files easily:

You can also use all Rails generators right in the IDE - when you right click on the project you can choose which of the generators to use, fill in the parameters and run it. Then you see the output of the generator in the output window.

You can leverage code completion, refactoring, quick fixes and other features in the editor while developing the application (see part one of this article to learn more about some of the editing features). When you are ready to run the application you can just hit the Run button without any necessary configuration - NetBeans bundles the Webrick server you can use to run your application. A web browser window is opened automatically and the IDE will run the Webrick server in debug mode in case you choose to debug your application. You can of course switch your server to Mongrel easily, too.

Rake is integrated into the IDE as well, so you can run Rake targets on your project:

You can also debug rake targets easily, run migration scripts and work with the Rails console right from the IDE. You can also install different Rails plugins using a special dialog. There are other features for Rails development available, but hopefully you got the idea of how you can develop Rails applications using NetBeans.

Editing Features

I already discussed some of the editing features in part one of this article (code completion and refactoring). The editor is what I think most Ruby developers will like about NetBeans - there are many different little things that help all the time. For example, when you create a new method an end statement is filled in automatically and your cursor is placed on the line in between. You can see all occurrences of different elements such as variables in the file:

When I want to rename the variable I can simply press Ctrl-R and all occurrences in the file get renamed at once:

Easy orientation in code is enabled thanks to nice syntax coloring even in RubyDocs. Errors get underlined in the editor as you type and NetBeans shows you which of the variables are not used, so you can remove them.

When you hold the CTRL key and move the mouse cursor over any class, method or variable you can go to it's declaration. You even get a small hit about what the selected element does.

You can also use code templates. Many code templates are pre-defined for you but you can also create your own templates easily. In the template you can specify position of the cursor after expansion and you can pre-fill various variables as well. So the templates are very useful when you use some API repetitively.

There are many other editing features available so check out the Ruby editing wiki page to find out more: http://wiki.netbeans.org/wiki/view/RubyEditing.

Gem Manager

The Gem manager (Tools | Ruby Gems) lets you install new versions of gems, browse already installed gems, update them and so on, as seen on the screenshot below. The user interface is very similar to the NetBeans Plugin manager and Rails Plugin manager, so you'll get used to it easily. There are many gems available in the Ruby repository, and so fulltext search becomes very useful when you want to get some library.

Ruby Options

As I mentioned earlier you can switch between native Ruby and JRuby. The IDE uses JRuby by default because it comes bundled but you can simply point the IDE to your existing Ruby installation directory and it will pick it up, no matter which operating system you use.

You can also switch between classic debugger and fast debugger using the Options dialog. In case of JRuby you can only use the classic debugger, which is slower but works in all the cases. With native Ruby you can use the fast debugger (you can install it easily, it gets downloaded in the IDE) which is the recommended debugger for Ruby. There are two more Option tabs available: "formatting" which lets you control formatting settings in the editor and "hints" that control appearance of the light bulb in the editor.

Unit Testing

Unit testing support is very well integrated, too. For example when you create a new model a unit test is automatically created for you. This is a feature of Ruby on Rails, the philosophy is that testing is so important that it cannot be omitted. You can run tests right from the editor and navigate to test classes, too.

If you are really into testing you can install the "ZenTest" Ruby Gem (use Tools | Ruby Gems), and then your projects will have an "AutoTest" menu item in their context menu. When you invoke it, it will launch AutoTest on your project, which will run unit tests automatically whenever you modify a file. AutoTest can in many cases figure out which unit tests need to be run - this is especially true for Rails projects. If not, it will run all unit tests.

Using the console

Even though we tried to integrate as much of functionality as possible into the IDE, you may still want to access the console. This can be useful for example when you want to try out some of the ruby APIs interactively. The Ruby shell can be opened using Window | Other | Ruby Shell (IRB). The console is opened in the bottom of the IDE and you can take advantage of the full power of Ruby's interactive language.

More information

You can find additional information about Ruby support in NetBeans on its wiki page: http://wiki.netbeans.info/wiki/view/Ruby.

Various demos and tutorials are available from the main Ruby documentation page: http://www.netbeans.org/kb/60/ruby/index.html.

Finally you can download the NetBeans IDE for free from the following URL: http://www.netbeans.org/community/releases/60/index.html. You can either choose to install a small version of the Ruby-only IDE (a special bundle is provided) or full-blown Java IDE with Ruby support. It is also possible to add Ruby support to the Java-only IDE using Tools | Plugins.

In the last part of the series, we will discuss extra features you can get by installing various experimental plugins and community-related topics, such as how to get involved in the project and its future plans. In the meantime, make sure to try out Ruby support in NetBeans. If you develop in Ruby a lot, you may find that NetBeans is the IDE you have been looking for!

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Dynamic Languages - yes, but why Ruby?

    by Zeev B,

    • Dynamic Languages - yes, but why Ruby?

      by Zeev B,

      Your message is awaiting moderation. Thank you for participating in the discussion.

      I guess that Sun decided to invest in Ruby because of the big RoR hype in the past couple of years. I think that there is a more suitable dynamic language that has a JVM implementation and a very dedicated community. It is used a lot throughout the industry for example, Google uses it a lot (and it is even used inside Sun).This language arrives with a lot of useful built-in libraries and there are a lot of other open source libraries and frameworks to choose from. It is used to build big web sites such as YouTube and it is also used a lot by system adminitrators that want an easy and productive way to create scripts. You probably guessed by now that I am talking about the Python programming language.
      Although very different from Java I find Python is in tune with the Java culture :
      1. Readability and explicitness - both Java and Python endorse clean readable code that explicitly states what is being done.
      2. Matureness- Python and Java are of almost the same age. They are mature languages that proved themselves again and again in production systems.
      3. Vibrant community - both platforms have a devoted community and community process.
      4. Open source libraries - both platforms have a lot of libraries and frameworks available (a result of points 2 and 3).
      As a Java developer using a lot of Python/Jython nowadays, I am dissapointed that Sun chose not to invest in supporting this popular and productive programming language. I think that NetBeans is loosing an opportiunity to hook up with this wonderful community which is missing a high quality IDE such as NetBeans.

    • Re: Dynamic Languages - yes, but why Ruby?

      by Clinton Begin,

      Your message is awaiting moderation. Thank you for participating in the discussion.

      >> 1. Readability and explicitness

      Somewhat a matter of taste, but one thing is for certain: Ruby is more easily embedded in HTML and other arbitrary text formats. Python's dependency on whitespace makes it somewhat less suitable for this, which is important to consider due to the popularity of ASP/JSP/RHTML/ERB style templates. Ruby doesn't need an intermediate language.

      >> 2. Matureness- Python and Java are of almost the same age.

      The first versions of Ruby and Java were both released in 1995.

      >> 3. Vibrant community

      I think Java beats both Python and Ruby, possibly combined. That said, both Python and Ruby have decent communities that I would describe as "more than adequate".

      >> Open source libraries - both platforms have a lot of libraries and frameworks available (a result of points 2 and 3).

      rubyforge.org/

      >> I think that NetBeans is loosing an opportiunity to hook up with this wonderful community which is missing a high quality IDE such as NetBeans.

      Yes, they are, unfortunately.

    • Re: Dynamic Languages - yes, but why Ruby?

      by Zeev B,

      Your message is awaiting moderation. Thank you for participating in the discussion.

      >> >> 1. Readability and explicitness
      >> Somewhat a matter of taste, but one thing is for certain: Ruby is more easily embedded in HTML and other arbitrary text formats.

      I don't think that having complex logic in my view (HTML) is desirable both in terms of readability and separation of concerns.

      >> >> 2. Matureness- Python and Java are of almost the same age.
      >> The first versions of Ruby and Java were both released in 1995.

      Matureness is not only related to release date but to how widely the language is used in production systems.

      >> >> 3. Vibrant community
      >> I think Java beats both Python and Ruby, possibly combined. That said, both Python and Ruby have decent communities that I would describe as "more than adequate".

      Both Java and Python have a community process in addition to a big community.

    • Re: Dynamic Languages - yes, but why Ruby?

      by Stefan Frank,

      Your message is awaiting moderation. Thank you for participating in the discussion.

      >> I don't think that having complex logic in my view (HTML) is desirable both in terms of readability and separation of concerns.

      It's not so much about "complex logic" - it's about the simple things like displaying a value and formatting it, displaying links conditionally, etc. Lots of tiny little things which I am so happy not having to switch to another language to make them possible. In the attempt to build "clean" architectures, especially java has built an overly complex stack of technologies: And I hear this argument over and over again, that this separation into different approaches and languages automatically leads to better architectures. This, unfortunately, is not the case, as everyone knows how has ever looked into a jee-production system. So, definetely, no: Having the ability to use one language only for everything from configuration to producing output does not automatically lead to unseparated and unreadable applications. And although xml, velocity, java, spring, ejb3, jpa... have more or less clear separation of concerns, this does not guarantee that you get an app you can maintain or even understand in half a year from now.

    • Re: Dynamic Languages - yes, but why Ruby?

      by Zeev B,

      Your message is awaiting moderation. Thank you for participating in the discussion.

      >> And although xml, velocity, java, spring, ejb3, jpa... have more or less clear separation of concerns, this does not guarantee that you get an app you can maintain or even understand in half a year from now.

      It all boils down to simplicity - if it is simple and explicit you'll be able to more easily maintain it in the future. I don't consider putting Ruby or Java code in my view as a simple move. I prefer using a simple template language such as Velocity because then I can have the designer in my company work with it without having to know those programming languages.

    • Re: Dynamic Languages - yes, but why Ruby?

      by Brandon Zylstra,

      Your message is awaiting moderation. Thank you for participating in the discussion.

      You're arguing based on some false assumptions.

      If you want things to be simple in the view, and you want your designer to be able to edit the html without munging code, that is easy to do--in fact that's normally how it's done. Most people that I'm aware of don't put complex code in their views. You'll mostly see variable names. If you have more than that, then you need to move some of your code into the controller. That would be your responsibility, not the responsibility of the language.

      Furthermore any designer who knows HTML is able to recognize things embedded in the html that AREN'T HTML. (If not, you need a new designer who's not an idiot.)

      And on top of all that, if you want to use a templating language, you're free to do so. Liquid is a popular and excellent choice.


      I don't know Python, or you, so I might be wrong on this point, but it sounds like this is what's happening:
      1. Python is awesome,
      2. consequently you love Python,
      3. consequently you've invested lots of time and emotional energy into Python
      4. consequently you're blinded to its limitations
      5. consequently you're arguing against Ruby's approach simply because you don't want to think that it could be better than Python in any way.

      Perhaps I'm wrong, but I can't see any other reason to be arguing that the limitations caused by Python's handling of white space are a GOOD thing. Guido made design decisions, and it turns out they seem to have limitations (or at least make it awkward) when it comes to embedding Python in HTML. How can anyone see this as anything but a limitation?

      Just because Python is awesome (and I don't doubt that it is) doesn't mean everything else sucks.

    • Re: Dynamic Languages - yes, but why Ruby?

      by Zeev B,

      Your message is awaiting moderation. Thank you for participating in the discussion.

      > You're arguing based on some false assumptions.
      Wow - please read your posting again and see how many assumptions you are doing...
      I still think that the embedding a fully fledged programming language into the view is not an advantage.
      Read you comment again, in your 1-5 list replace Python with Ruby (and vice versa) - maybe that is happening to you... (this process is called projection in psychology)

      > Just because Python is awesome (and I don't doubt that it is) doesn't mean everything else sucks.

      Yes, Python is great and No I didn't say that "everything else sucks". Going back to my original comment - I think that Sun could have made a better choice at supporting Jython instead of JRuby. I think that although Java and Python are two very different programming languages, their underlying principals of code explicitness and community process are much in tune.

    • Re: Dynamic Languages - yes, but why Ruby?

      by Jeff Schwartz,

      Your message is awaiting moderation. Thank you for participating in the discussion.

      In my opinion, Ruby/ROR support in Netbeans doesn't exclude support for any other dynamic language in Netbeans. If you are interested then why don't you begin the process by creating an open source project and see if there really is enough momentum for it in the developer community. If there isn't then that should indicate that Python doesn't have the momentum to support the development effort even though some developers might benefit by it.

      By the way, I like Ruby/ROR very much but I also use python on Linux/Ubuntu and think it is a very good platform.

    • Re: Dynamic Languages - yes, but why Ruby?

      by Zeev B,

      Your message is awaiting moderation. Thank you for participating in the discussion.

      >In my opinion, Ruby/ROR support in Netbeans doesn't exclude support for any other dynamic language in Netbeans.

      You are correct, but that was not my point. Of course, since NetBeans is an Open Source project anyone can enhance it. My argument was about Sun and their decision to invest in Ruby.

      >If you are interested then why don't you begin the process by creating an open source project and see if there really is enough momentum for it in the developer community.

      I've started looking at projects that existed for NetBeans 5 that added support for Python and other dynamic languages. From what I read, even if these projects where ported to Netbeans 6 they will be able to support a much inferior experience in comparison to what was developed for Ruby.
      I wonder if the development done for Ruby support can be leveraged to support Python as well.

    • Re: Dynamic Languages - yes, but why Ruby?

      by John Liang,

      Your message is awaiting moderation. Thank you for participating in the discussion.

      Zeev,

      I believe if you strongly think that Python should be in NetBeans, then I think you should start an open source project on that so that later on, Sun Microsystems may hire you to work on the development on Python IDE framework.

    • Unaccepptable comment formatting

      by Stefan Wenig,

      Your message is awaiting moderation. Thank you for participating in the discussion.

      It's a shame that these fine comments are all but incomprehensible due to lost formatting. This problem is old enough, and well-known enough, for us to expect a solution. Please.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT