Tag Archives: Ruby

Ruby coding conventions, standards and best practices

Since Rails is  the most popular framework based on the Ruby language today, I appreciate what the Rails developer site has to say about “source style”:

  • Two spaces, no tabs
  • Don’t use “and” and “or” for boolean tests, instead always use “&&” and “| |”
  • MyClass.my_method(my_arg) — not my_method( my_arg ) or my_method my_arg
  • Follow the conventions you see used in the source already

Tabs in code are cancerous to me (e.g. display versus printing fidelity woes), but I prefer three or four spaces to two, depending on the prevailing code base–three spaces if setting precedent (e.g. start of indented line following conditional such as “if (” lines up with the condition itself).

Digging a little deeper, I found the following pages worthwhile:

What do you use on your Ruby-related projects?

Ruby IDE

One of the concerns I had approaching Ruby was the apparent lack of an IDE. I see that Tim Bray expects there to be an IDE, too–among other things.

There appear to be several takes on the state of Ruby development environments. For example:

  • Languages like Java and C# have a class of developers that depend on their tools such as IDEs (e.g. Bruce Tates’ assessment in From Java to Ruby: “C# programmers tend to lean on their tools a little harder than others”). Could it be that said developers depend on their tools to make themselves more productive? Answers from this camp tend to argue that the question is moot since Ruby is inherently more productive–why tax the developer’s mind with IDE semantics? (Tim Bray offers several excellent counter-points above to such a response.)
  • Ruby as a dynamic language poses challenges for IDEs that prefer a static typing foundation (e.g. read the comments here)–again, this IDE thing is so over-rated. :-)
  • If you’re willing to marry Ruby with a JVM (JRuby) or marry Ruby with a CLR (e.g. this article references RubyCLR, Ruby.NET, IronRuby), then you may find your Java IDE or Visual Studio more palatable.
  • Text editors like TextMate (MacOS) and Notepad++ (Windows) are good enough for Rubyists, especially when combined with tools like Rake. There is also ActiveState Komodo, or you can give RadRails a spin.

When I develop in Java, I leverage JetBrains IntelliJ IDEA. It looks like the next major release of IntelliJ (6.0) may feature an open source Ruby on Rails plug-in (ref.).

When I develop in C#, I leverage Microsoft Visual Studio. This is the IDE I’m most productive using currently probably due to the fact that I’ve used a version of Visual Studio more than any other IDE in my career thus far.

Since I’m embarking on this Ruby learning first on Windows, I will see how far I can get with Notepad++ initially. On my G5, I’ll probably leverage TextMate for starters.

Update: Later today I stumbled across the Simple Syntax Highlighting plugin for IntelliJ via Jay Fields’ blog and Daniel Lukic’s (plugin author) blog. I’m going to give this plugin a spin first since I have IntelliJ for both Windows and MacOS (i.e. leverage one familiar environment than two new ones). 

Ruby, Rails and Unicode

As a software architect for EMC, I’m concerned with the global reach of what I build–employed technologies must support internationalization and subsequent localization in multi-byte locales (i.e. just supporting single-byte strings or Latin-1 locales is unacceptable). Per “How To Use Unicode Strings in Rails“: Rails currently defers its Unicode support to Ruby, which currently only supports single-byte strings.

EMC’s content management and archiving software fully supports Unicode from top (presentation) to bottom (storage). It must continue to do so per customer demand and requirements.

So why even dip a toe into the Ruby/Rails pool?

First, Rails-based applications exist that support UTF-8. That isn’t to say that native support in Rails or Ruby is where it needs to be–it is not, yet–but rather to counter some of the hype you’ll find on the Web (i.e. there is none whatsoever). I appreciate Obie Fernandez’s InfoQ article on this important concern. As long as Unicode support isn’t robust and native, I have to give Ruby et al a ding in the non-essential complexity column. C# and Java fully support Unicode; Ruby needs to as well–the sooner the better.

Second, my focus on Ruby et al is to improve my software “thinking” in general. By complementing my C# and Java knowledge with Ruby, I hope to improve how I approach architecture, how I implement design, etc. Certainly this cuts both ways–C# and Java have things that Ruby could potentially benefit from adopting–but I believe that Ruby has concepts to offer me uniquely at present.

I’m reminded of Ajax as I approach Ruby, too. When I posted on “scrubbing bubbles,” I pointed out a set of concerns to combat Ajax-as-panacea hype. Some of those concerns have been or are being properly addressed by the community, while others still remain. I’m optimistic that Ruby’s issues like proper I18N support will be addressed by its community, too.

I’m starting to see red

While I may cumulatively spend a majority time and passion developing on Windows in .NET et al during my career, I also work with a significant Java code base at work. IMHO, both of these platforms overshoot the needs of classes of solutions with burdensome (not pervasive) runtimes, prolific APIs, and layer upon layer of functionality with sometimes questionable value (e.g. does this layer justify another part of the underlying platform, framework or toolset, or does this layer yield clear business value?). For example, my previous post about WS-* pain relief is as much about Java’s WS-* implementation as WS-* itself. (FWIW, I prefer Microsoft’s approach in Windows Communication Foundation, which just went Release Candidate, by the way.)

Fortunately, both of these platforms are still well-suited to many of the enterprise applications I architect and implement for EMC, its partners and its customers. In some cases, meaningful work is being done to simplify development and to allow focus to return to business problems. In the case of smart client development–the reorganization of the MSDN Smart Client Development Center underscores by point herein–I’ve even contributed to this effort, and I say this simply to make it clear that I’m not down on .NET or on Java. Rather, like Rocky and others, I find myself increasingly questioning how much closer (or not) these platforms have brought me toward solving my business concerns.

As a Solutions Architect (MVP), I take pride in helping my internal and external customers navigate technology to decrease the amount of time they focus on plumbing while increasing their effectiveness in building solutions. But just how much technology is required to deliver “forms-over-data” applications? (And much of content management is about forms-over-data, where data may include content and content metadata.)

From its Language INtegrated Query (LINQ) effort, Microsoft is working to provide some relief for ASP.NET developers building “forms-over-data” applications via its Blinq prototype.

And then there is this thing called Ruby on Rails. :-)

I recently finished From Java to Ruby by Bruce Tate–more on my read in a separate post. Those familiar with Bruce’s books of late understand that he has been a leading voice for matching purpose and technology (i.e. leveraging purpose-built technology) and has questioned the appropriateness of Java when other technologies may be better suited for the task at hand. Bruce’s work has provided significant incentive for me to dive into Ruby and Rails, and I’m currently preparing some of my diving gear. :-)

Stay tuned…