Feeds

Making sense of Ruby

An IntelliSense Cure for Method Madness?

The Power of One Brief: Top reasons to choose HP BladeSystem

Hands on We were six months into the project before we even realised we had a problem. Until that point, we had assumed IntelliSense was a trivial matter that could doubtless be wrapped up in an afternoon’s coding. After all, how hard can it be to program some lists of names that drop down when someone types a dot?

The answer, as we were soon to discover was: very, very hard…

The project in question is called Ruby In Steel and it’s a Visual Studio development environment for the Ruby language. Ruby is a so-called "dynamic" language, which is a polite way of saying that it's hugely unpredictable.

A Ruby program is so dynamic that you can never be sure what it is up to from one moment to the next. To take a simple example, when you write some stand-alone functions into the editor, those functions get bound into the base class of the entire Ruby class hierarchy. That means that every single Ruby class automatically "inherits" them - and the IntelliSense system is expected to know about it!

If we'd been developing an IDE for a more traditional language – C# or Java, say – life would have been so much easier. Those languages go to great lengths to tell you what they are up to. Each variable declares its data-type in advance and when a variable starts life as an integer it’s pretty safe to assume that it’s going to stay an integer until the great garbage collector in the sky finally pops it out of existence.

With Ruby, you can't make any such assumptions. The types of variables are not declared and they are infinitely changeable. A variable called x might be start out as "Hello world", suddenly change into 76.23 and, just for the heck of it, end its days as a small fluffy Teddy bear object called Eric.

Some code-completion systems solve this problem in a cunning way - they cheat. Instead of working out what type of object x is at any given moment, taking into account all the difficult stuff such as its scope, inheritance and context, they work alphabetically. If someone enters a dot followed by the letters ‘my’, they drop down a list of names such as ‘my_method’, ‘my_othermethod’ and ‘my_random_guess’ whether or not those methods have anything to do with the object in question.

Illustrates Ruby in Steel Intellisense.

Creating real IntelliSense (as in Figure 1) is much harder. The only way to do it properly is to analyse the code much as the Ruby interpreter itself does. The big difference is that the interpreter only goes into operation when a program is complete whereas an IntelliSense system has to deal with code that is constantly changing due to editing. After each change, it has to reanalyse the code all the way back up to the root of the entire class hierarchy. This sheer complexity of this analysis explains why IntelliSense systems for dynamic languages are not that thick on the ground.

Programmers often say that one of the defining characteristics of Ruby is that it's so much fun. All I can say is, they obviously haven’t tried programming IntelliSense for it! ®

Securing Web Applications Made Simple and Scalable

More from The Register

next story
Apple fanbois SCREAM as update BRICKS their Macbook Airs
Ragegasm spills over as firmware upgrade kills machines
HIDDEN packet sniffer spy tech in MILLIONS of iPhones, iPads – expert
Don't panic though – Apple's backdoor is not wide open to all, guru tells us
NO MORE ALL CAPS and other pleasures of Visual Studio 14
Unpicking a packed preview that breaks down ASP.NET
Captain Kirk sets phaser to SLAUGHTER after trying new Facebook app
William Shatner less-than-impressed by Zuck's celebrity-only app
Cheer up, Nokia fans. It can start making mobes again in 18 months
The real winner of the Nokia sale is *drumroll* ... Nokia
Mozilla fixes CRITICAL security holes in Firefox, urges v31 upgrade
Misc memory hazards 'could be exploited' - and guess what, one's a Javascript vuln
EU dons gloves, pokes Google's deals with Android mobe makers
El Reg cops a squint at investigatory letters
Chrome browser has been DRAINING PC batteries for YEARS
Google is only now fixing ancient, energy-sapping bug
prev story

Whitepapers

Designing a Defense for Mobile Applications
Learn about the various considerations for defending mobile applications - from the application architecture itself to the myriad testing technologies.
How modern custom applications can spur business growth
Learn how to create, deploy and manage custom applications without consuming or expanding the need for scarce, expensive IT resources.
Reducing security risks from open source software
Follow a few strategies and your organization can gain the full benefits of open source and the cloud without compromising the security of your applications.
Boost IT visibility and business value
How building a great service catalog relieves pressure points and demonstrates the value of IT service management.
Consolidation: the foundation for IT and business transformation
In this whitepaper learn how effective consolidation of IT and business resources can enable multiple, meaningful business benefits.