Write Ruby code faster with ED for Windows

Ruby is the most expressive and interesting language I’ve come across in all these years of developing our programmer’s editor/ide ED for Windows. It takes Object Oriented programming and Dynamic language support to new levels, at least in my eyes.

Ruby enables you to do more than other languages in less lines of code and still be reasonably readable, and important asset for any language. The library that is included with Ruby is the most comprehensive I’ve seen, which means there is less searching out other libraries or having to write your own code. The bottom line is simply that you should be more productive writing in Ruby than other languages, which is pretty important in todays fast paced world. And if you can do more with less code, there should be fewer bugs, right!

There are however a few things that concern me with the Ruby language. First up whitespace is relevant, which is pretty unusual in a programming language. For example: id = “%x” % (ab * 2) is completely different to: id = “%x” %(ab * 2). In the second fragment there is no space between %(.

My next concern is that you can’t declare variables, you just use them when and wherever. The problem here is that if you make a simple typing mistake you’ll have two (or more) variables instead of the one and probably won’t know until you (hopefully) discover the code isn’t working as expected. For example:

if thelight == 1
  tehlight = 0  # typo
end

The Ruby interpreter won’t complain about this and thelight will never get set to 0. Other dynamic languages also work this way, so Ruby isn’t alone, but PHP for example provides an option where you are forced to declare variables before use. Ruby would really benefit from this.

Ruby + ED for Windows

Developing ED4W language support for Ruby was difficult. Ruby code can be ambiguous when looked at in isolation and this poses many challenges for editor writers. In fact, I spent some time looking at the other editors which support Ruby and was quite surprised at how poorly they faired. Syntax highlighting was often wrong and this is the area which is so important in helping you quickly see mistakes as you are writing, instead of waiting for the Ruby interpreter to point them out and getting wound up waisting time with unnecessary edit-compile cycles.

Aside from extensible syntax highlighting ED4W delivers a range of capabilities to help you write code faster, and not just in Ruby but in a wide range of programming languages. I’ll quickly run through some of these.

Smart indenting and Auto-completion

This short code fragment was written without pressing the space bar or tab key and without typing and end’s. EDs smart indenting took care of all of the indenting and its code templates filled in the ‘end’ statements.

Another way to automatically complete blocks of code is using code completion. If the example above was:

Then pressing Enter followed by Escape would give you:

And pressing Enter and Escape once more will give you:

Code completion works out what text needs to be added to close the current block of code. It works with simple text such as brackets [ { and ( to add ) } or ] and more complex elements as shown above.

Another important ED feature is shown in these two screen shots and that is the matching if-end and def-end statements are highlighted. I assume all editors these days highlight matching brackets and let you jump to and from the opening and closing brackets, but ED takes this further and enables you to jump between any statements that form blocks of code as shown here.

 

 

 

 

 

You can right click on any statement to jump to its matching statement and as this example shows nested blocks are of course handled correctly. ED uses right click on code to do a variety of clever things, but if you prefer the keyboard you’ll be right at home.    

 

Statement matching and code completion are two more ways ED helps you code faster. Smartype, Autocorrection and Parameter assistance also come to the party.

Code templates write complete blocks of code for you. You simply type the templates abbreviation or pick it from the Skeleton window and ED does the rest as shown here.

 

 

 

 

 

Templates can be as simple as ‘if .. end’, to complete slabs of code and they can include other templates, allowing a building block construction approach. Templates are created using plain easy to edit text in a text file.    

 

I’ll end this section by touching on some of the other ways ED will help you write code faster. Macros automate text manipulation operations, full Regular Expression search and replace both within and across files and projects, Filter searches to exclude syntax elements such as comments and strings, Difference Analysis highlights changes in files and enables them to be resolved, Persistent bookmarks keep your place across editing sessions, Comment/uncomment blocks of code, Select text by character, column and line, Spell check and correct, Run compilers and navigate through errors in the source, Open include files and Configure and extend ED to work the way you want to.

To finish I want to show you how ED can help navigate around your code and enable you to work directly with modules, classes and methods so that you no longer have to remember which source file they are in or where that file is located. To accomplish this ED has a built-in Source Database Engine (SDB) which parses your source code in the background to build a database of all methods, classes etc., which you can then access in an instant. Lets see how easy this is.

 

 

 

 

 

This is just one way to find methods, classes and modules. You can query the SDB including using regular expressions. For example to find all methods starting with “sock” you would search for “sock.*” using Goto|Find in Source Database.    

Class View displays a tree of all modules, classes and methods for all of the Projects which are currently open.

 

Class View Tree

 

Double click on any item to open its source file and jump to it. Class View is opened using View|Workspace then click on the Class View tab. To locate a method etc. in the current source file in the class view, right click on whitespace inside the method and choose “Select current item in Class View”.

ED also makes it easy to move around by method, class or module within the current file, by selecting from the drop-down combobox on the Navigate Toolbar. And Goto|Next Function and Goto|Previous Function do what they say.

 

Function List

 

To use the Source Database you need to create a Project and add your source files to it. All files in the project are included in the database. The SDB is updated in real time as you edit code, so it always truly reflects the code.

A sample project for the Ruby library source code is included in the ED Download and is placed in C:\Program Files\SAIG\ED4W\Sample Projects. Copy Ruby Source.edp to a working directory and then use Project|Add Project to Workspace to add this to your own project. This will give you instant access to all Ruby modules, methods and classes.

To run Ruby on the current source file, click on the this button Run Ruby Toolbar button on the Build Toolbar. Use View|Toolbars|Build to open it if necessary. Any errors are shown in the Output window and Goto|Next/Previous Error navigate through the errors in the relevant source files.

There is a lot more to ED that I could tell you about, but would you keep reading! Probably not, so let me wrap this up.

EDs combination of powerful cross language editing capabilities plus source code navigation and browsing will surely help you code faster and not just in Ruby, but in most mainstream programming languages.

PS. Try Ruby! lets you give Ruby a quick 15 minute workout in your Web Browser. Highly recommended.

This entry was posted in ED for Windows. Bookmark the permalink.

5 Responses to Write Ruby code faster with ED for Windows

  1. Pingback: Write Ruby code faster with ED for Windows - Learning Ruby Blog

  2. David Bagnara says:

    Oh well, ANOTHER language to learn. At least I can stay with the SAME editor. I have been using ED for the last 10 years and really do appreciated you supporting new languages as they appear.

  3. Pingback: ED for Windows: Another established IDE adds Ruby support

  4. Hey,
    I love what you’e doing!
    Don’t ever change and best of luck.

    Raymon W.

  5. Pingback: A Fresh Cup » Blog Archive » Double Shot #11