We’ve teased you in the past with promises of code snippets from bona fide Ruby experts — for all you advanced Rubyists, here’s the code, ready for your dissection and possible implementation.
We’ve also got some more general insights from our panel of seven Ruby experts on the strengths and limitations of the Ruby programming language and their favorite Ruby apps and tools.
If you’re just starting out as a new Ruby dev, check out our tips for Ruby novices, which includes introductory-level advice from the same group of experts. And if you’re an intermediate developer looking to improve your skills, also check out tools and advice for mid-level Ruby programmers.
Jacques Crocker: Core Library Substitutes
Jacques Crocker is a Rails Jedi based out of Seattle who loves working on early-stage startup ideas and launching new products. He’s helped launch almost a dozen Rails apps this year including HeroScale.com (automatically scale your Heroku workers and dynos) and WordSquared.com (a massively multiplayer online word game). Next year, he’s planning on using Rails to launch 24 new web apps.
He says the tools in place for sharing code are one of his favorite things about the Ruby ecosystem. “GitHub and especially RubyGems.org make releasing a library to the world trivial. You’ll be able to find an existing gem for just about every API or interface you can imagine.”
When it comes to Ruby’s limitations, Crocker says, “Some of the core libraries have stagnated. Luckily, almost every crusty old Ruby standard library has a decent third-party gem alternative that usually fixes things up… Solid replacements for Ruby’s standard library are coming out every week, and it sounds like there’s some talk about Ruby 2.0 allowing an easier approach for swapping out standard libraries.”
Crocker also recommends therubyracer, a library that wraps Google V8 with Ruby bindings (“I use this currently to execute CoffeeScript natively within Ruby using the coffee-script gem”), and MacRuby, which re-implements the Ruby language in an Objective-C environment for native access to Cocoa objects when building Mac apps in Ruby.
Yehuda Katz: Refactoring Code
Yehuda Katz is a member of the Ruby on Rails core team, and lead developer of the Merb project. He is a member of the jQuery Core Team and a core contributor to DataMapper. He contributes to many open source projects, like Rubinius and Johnson, and works on some he created himself, like Thor.
He says, “Even though most of the Ruby development community is focused around the Rails framework, there are standalone libraries for just about everything, like virtually every new NoSQL database and connectivity with services like Twitter and Facebook.”
Another thing Katz loves about Ruby is “the ability to refactor code from any context (including class bodies) into a method without changes to that code. The two features that make Ruby shine in this respect are executable class bodies and Ruby’s block semantics.”
Here are Katz’s examples:
If we found that we were using that
attr_accessor logic repeatedly, we could extract it out into a method that we could use in multiple classes.
“This is a relatively simple example,” said Katz, “but it demonstrates the refactoring power of Ruby’s single-context approach.”
He continued that blocks have similar power.
“Consider the classic case of synchronization locks, which many languages implement as language features:”
“The problem here is that the return in the function passed to synchronize is returning from the inner function. Moving the unsychronized code into a synchronize block does not work reliably.
“In contrast, Ruby’s blocks can handle this problem:”
“In short,” Katz concludes, “Ruby is designed around making it easy to refactor code into methods, and the single-context principle (class bodies work the same as method bodies), and Ruby’s block semantics deliver on this promise.”
Obie Fernandez: RailsForZombies and the Non-Commercial Aspect
Obie Fernandez is the founder and CEO of Hashrocket, a Florida-based web consultancy and product shop. He’s a well-regarded blogger and speaker, and he’s also a series editor and book author for higher-education publishers Addison-Wesley.
For Ruby development and deployment, he says Heroku is “amazing,” and he also recommends RailsForZombies.org, which has a web-based, interactive Rails sandbox environment. “It gives people a no-setup, no-excuses way to get started on Rails and is based on some pretty cool underlying use of the technology,” he says.
While Fernandez says he loves making money from the “competitive advantages” of the Ruby programming language, he also says one of Ruby’s strengths is its corporate independence.
“There is no big commercial vendor getting all capitalistic on us and causing problems like you see with Oracle and Microsoft and their developer communities. Almost everything that gets done in our space, 99% is done for open-source love and passion and because it is useful to the person doing it. We don’t have any big, ivory-tower producers that I’m aware of.”
Ryan Bates: Blocks and Better Memory Handling
Ryan Bates is the producer and host of Railscasts, a site full of free Ruby on Rails screencasts.
Bates says, “One thing I miss most when using another language is Ruby’s block syntax. It makes simple, everyday tasks, such as remapping an array, convenient and beautiful.”
However, he cites Ruby’s “poor support for concurrency” as one of the language’s flaws. “Being a Rails developer,” he says, “I usually do not run into this problem because it is easy to spin up multiple instances of an app. In that case, memory can be a problem. I would love to see better memory handling and management in Ruby.”
As far as clever hacks go, Bates says, “This little trick for exposing any Ruby object over the web is pretty ingenious (and madly insecure):”
Desi McAdam: Ruby’s Bad Rap for Slowness
Desi McAdam is a Ruby developer at Hashrocket. She also co-founded and regularly contributes to the technical blogging group DevChix.
McAdam says, “I am constantly surprised by the expressiveness of the language. I enjoy coding in Ruby because it allows me to write beautiful code very easily.”
When it comes to Ruby’s downsides, McAdam’s statements lean more toward the language’s reputation than its actual flaws. “I don’t know how many times someone has given me the excuse of ‘Ruby is too slow’ as a reason not to use the language. There are of course some situations where this might be true; but in most cases, it’s just not important and can be handled through other mean.”
Cool Ruby-built apps she recommends checking out are MercuryApp, which lets you track how you feel about certain things over time; DesksNear.Me, a co-working app and Rails Rumble winner; and Commendable Kids, a positive feedback system for reinforcing good behavior in kids.
Raquel Hernández: IRB, RVM, Sinatra and Homebrew
Raquel Hernández is an experienced hacker/mathematician with a background that includes many programming languages and many work environments, from freelance and contract work to startups and larger companies. However, she’s made a particular focus of Ruby and Rails.
While Hernández praises the strength of the ever-growing Ruby community, she says its biggest limitations are “speed and scalability, which are a problem today — but improvements are happening at all times to prevent this. I don’t think this would be a problem in the near future.”
She also says, “I couldn’t survive a single day without IRB. It’s one of Ruby’s most popular features.” She also recommends reading this list of tips and tricks for IRB. She likes RVM for giving her the ability to work with multiple Ruby environments, Sinatra for quickly pushing out Ruby apps, and Homebrew for OSX package management.
José Valim: Objects, Inheritance, and the
José Valim is the founder of Plataforma Tec, a web development shop and consultancy. He’s also an open source developer and a Rails Core Team Member.
Valim also sings the praises of the Ruby community, saying, “We have a community that values software craftsmanship: well-developed, tested and documented code.”
He also shares some code samples that exemplify “what makes Ruby so pleasant to work with.”
“This one shows two Ruby features: everything in Ruby is an object (including numbers!) and classes in Ruby are open for modification. This means we can extend integers in Ruby (that are Fixnum objects) with new methods.
“The example above was extracted and simplified from the Rails framework and allows you to write:
5.minutes.from_now as valid Ruby expressions. Working with time intervals is common in web applications, and such modifications make pleasant and easy to manipulate them.”
“This second example shows inheritance, Ruby blocks (pieces of code that can be passed around and invoked on demand) and method contracts. Most languages implement
switch/case statements (which in Ruby is called
case/when) internally. Ruby, on the other hand, specifies that, in order to pass an object to a
when statement, you just need to implement a method named
===. While the example above is simple and could be implemented using
if/else statements, it shows the flexibility you can achieve with the Ruby language as everything is an object and as the language relies heavily in method contracts.”
“The last example uses a third-party library called
builder that makes XML creation simple. It relies on a feature from Ruby called
method_missing. Every time you invoke a method in a Ruby object and this method is not defined in it, Ruby invokes a method called
method_missing that should handle the scenario accordingly. In this case, the
builder library implements this method in a way that makes XML creation a breeze.”
Specific Questions or Tips?
If you’re a crack Ruby developer and you have a question, feel free to drop it in the comments! Our panelists are likely to stop by with more feedback.
Likewise, if you you feel like answering questions or passing on some great advice of your own, please leave a comment and school us all.
Series supported by Rackspace
The Web Development Series is supported by Rackspace, the better way to do hosting. No more worrying about web hosting uptime. No more spending your time, energy and resources trying to stay on top of things like patching, updating, monitoring, backing up data and the like. Learn why.
More Dev & Design Resources from Mashable:
– The Top 8 Web Development Highlights of 2010
– HOW TO: Get More Out of Your Fonts
– 4 Predictions for Web Design in 2011
– HOW TO: Make the Most of TextMate
– 5 Free Annotation and Collaboration Tools for Web Projects
Image of José Valim courtesy of Flickr, levycarneiro.
For more Dev & Design coverage:
- Follow Mashable Dev & Design on Twitter
- Become a Fan on Facebook
- Subscribe to the Dev & Design channel
- Download our free apps for Android, Mac, iPhone and iPad