views:

247

answers:

3

What are most common Ruby on Rails antipatterns and how to avoid them?

+1  A: 

Alphabet Soup?

(No type declared and meaningless variable naming which leads to nearly un-readable code)

Pattern name comes from variables names as 'a','b','c','d', etc.

Justin Niessner
is this somehow RoR-specific?
SilentGhost
Not in the least. It's something I've noticed a lot more in Ruby than other langauges (and the majority of what I've seen Ruby used for is RoR).
Justin Niessner
of course there is no type declared, it is a dynamic language. and anyone who uses a single letter as a variable as anything but an iterator in any language needs something hard thrown at them
Matt Briggs
+8  A: 

There are two major anti-patterns I've seen in a lot of Rails code:

  1. Lots of "heavy lifting" in views. Anything more complicated than simple iteration over collections or interpolation of strings should be in helpers or model methods. Don't query for model objects, construct big JSON arrays, or update session variables from your ERB templates.

  2. Model objects which aren't usable for scripting or API implementation. Your models define the domain semantics for your application. You should be able to fire up script/console, or write service API wrappers, which reuse existing, functional model methods to manipulate all of the key data in your application. Controller functionality is only available in the HTTP request/response cycle, which is only part of any full-featured site's lifecycle.

rcoder
+1  A: 

Not learning Ruby.

Jörg W Mittag
Heh, I can't believe I got an upvote for this :-)
Jörg W Mittag