
When Rails Fails - nreece
http://zef.me/2308/when-rails-fails
======
patio11
Not to put too fine a point on it, but this is what Rails does when the
programmer fails. If you type in invalid identifiers, no programming language
or web framework is going to be very happy with you. After that, it is a
matter of taste and technical feasibility how the framework handles it. If
you're lucky and using Java, you typed in an invalid identifier in such a way
that the project fails to compile, and Eclipse will give you little red
squiggles. (If you're not lucky, you get an undescriptive error message thrown
up from a 700 line stack trace and have to guess what caused it then spend 30
seconds redeploying to see if you guessed right. For example, if you have a
genetic predisposition against typing things correctly the first time,
botching values in your XML configurations in such a manner than the XML is
still valid is going to cause you a _lot_ of pain.)

Ruby is an interpreted language and can't feasibly do the red squiggle
thingee, but the common errors are trivially debuggable after a few hours
experience with the framework. If you see an error message talking about
HommeController, you search for homme globally, find the one instance of it,
fix the spelling and reload the page you were just seeing. Bam, that took you
three seconds.

~~~
smanek
﻿As a non-ruby dev, it isn't obvious to me that I should grep 'Homme' instead
of 'HommeController' ...

A statically typed language with a good IDE (yes, like Java) will find almost
all these errors for you as you type (excepting config files, like you said).

~~~
patio11
I do Java at the day job. If we hired you as a new employee, and in the course
of cutting your teeth on our Java framework you made those errors, I think
Eclipse would have caught exactly one of them.

Routes.rb errors 1 and 2: sorry, this is either handled in a configuration
file or the database, which is loaded from an XLS file in our framework. None
of this is checked.

Linking to non-existent pages: we don't actually have a URL generation helper,
but if we did, it would be in the JSP and thus not subject to fast checking.
Since in Java you'd be passing a string as a parameter rather than an
automatically generated method, you'd get nothing useful here prior to
actually clicking on the link and finding it didn't go anywhere.

Misspelling confirm: This would be caught in your JSP compile step prior to
deploying the server, although you'd still waste a minute.

Mistyped property names: OH GOD do I hate this one. You'll get as far as any
page done by that action without error. Then the action gets loaded and the
fun begins. Typically you'll get an error telling you that a form is not
defined , which is your cue that says "Check the contents of the annotations
for this action, something is borked", but if you don't know that symptom or
(worse) if you borked something in one of the fields where the page can still
load, you'd either waste a lot of time or miss the bug entirely. (For example,
in our system, one way of causing this bug would leave "name" totally
unchecked but let the form submission succeed for good input. Since many of
our outsourcers don't bother testing with bad input...)

Misspelled formats: We don't even have this feature. (P.S. I don't know why
Rails books and tutorials always emphasize this so much, since most people
_don't need it_. I always just delete that code from my own Rails methods.)

Botching the key to a parameters access: Since the key is a string and there
is no way to tell whether Map#contains("arbitrary string") at compile time,
you'll get as far as execution before seeing any error here. It will probably
be a NullPointerException.

~~~
tptacek
It's a religious thing. Writing actions that make sense both with XML output
and with HTML output tends to force you to write REST-y web-service-y
interfaces. I delete the code too, but I feel guilty for doing it.

------
heycarsten
Poor attention to detail is going to bite you in the ass as a programmer no
matter what technology you're using.

~~~
vegai
The difference is how early you get bitten. With a stronger language, your ass
would be full of bitemarks weeks before you went to production.

------
param
Good article that raises interesting points. I would also be interested in
knowing what happens to experienced programmers using Rails - do they simply
become used to the poor error messages (so this is just a ramp-up problem) or
are you always stuck with making sure everything is without typos etc?

~~~
tptacek
Without conceding that these _are_ poor error messages --- most of them are
pretty direct, and the one that confused him the most actually gave him a
step-by-step for diagnosing the problem --- I do think that addressing this
post point-by-point would be another opportunity for Rails to charm web
developers.

Note that very, very few software development frameworks "gracefully" handle
the typo problem.

~~~
jbellis
It's worse in Ruby though, because the "use maps for optional parameters"
approach means you have to manually check for invalid keys in the map, whereas
the same approach in a language that supports native named parameters would
throw an exception about the invalid parameter. Several of the errors in this
article would be caught by this.

~~~
grandalf
True, but Ruby also allows for the Rails DSL to be fairly concise. If you
assume a constant number of typos per typed word, the author would have made
more errors in a more verbose language even if it had named params :)

------
dasil003
I don't think it was a good idea to write this article. Some of these messages
could reasonably be improved, and some couldn't, but regardless of the merit
of each individual complaint when I read someone listing out the result of a
half dozen common typos along with a description of how bad these extremely
common error messages are, I can't help but immediately judge the author to be
one of those NNPP's who spends days tripping over ridiculously simple issues
because they never really grokked how to debug in the general sense. I'm not
claiming the author is an NNPP, I'm just saying when you get hung up on the
basics like this that's the impression that is conveyed.

------
swombat
Summary: Rails has a learning curve. If you're a newbie, you will get
confused.

None of these errors are confusing once you've been using Rails for a couple
of weeks.

~~~
jamesbritt
Maybe. I found routing errors to be massively useless until I spent way too
much time finding out just what was expected to make things work.

Rails seems to favor the approach of first reading many docs and tutorials,
then working your way through a series of examples, and always doing things
Just So. It's not so friendly if you decide to wing it and try things because
your gut says it might just work.

The funny thing is, one of the things I like about Ruby is that it works just
the opposite; it's quite easy to jump in and guess at what to before reading
much documentation. You'll often be right, or you'll (mostly) figure it out
pretty fast.

------
kellishaver
Those all look like perfectly legitimate, thorough error messages to me, far
moreso than many languages would give you. Would it be confusing to a newbie?
Maybe, but they're called newbies for a reason. Pay attention to details +
write tests + take the time to learn the framework = problem solved.

~~~
grandalf
Uh, not really. Anyone new to a framework should just stop learning at the
first sign of frustration and write a blog post criticizing the framework.

------
terrellm
I recently began working with Ruby on Rails after years in ASP.Net and I still
have to refer to the API, Guides, and documentation so I consider myself an
amateur. I'm having to get used to programming "better" since I no longer have
the assistance of a compiler to catch these type of errors.

As you probably know, Rails is about convention over configuration. This
increases the initial learning curve but speeds up development once you
understand the conventions. I read Agile Web Development with Rails and was
able to make it over the initial hump of "what..why is this capitalized and
this plural and the singular" stage.

~~~
johnbender
The bigger problem you're facing is that ASP.NET has been forcing you to use
the, shotgun-in-mouth worthy, event driven model (I've done .net web dev).

The rest of the universe has been using MVC for five or 6 years to do web
development. Praise be to Microsoft for figuring it out.

------
kalendae
as a beginner, things like scaffolds and other generated code pretty much
completely eliminate these typo driven mistakes, they also make great starting
points for understanding the framework. so that mitigates the problems
mentioned for beginners, and by the time you are not a beginner hopefully
those error messages make more sense. Personally, i found most of those error
messages pretty good. im currently using spring/hibernate as well as RoR very
heavily, and trust me i pull my hair out way more on the spring/hibernate side
than the RoR side, come to think of it, i pull my hair out exclusively on the
java side =)

------
swerling
The Rails backlash sometimes seems bigger then the hype ever was, and is
cloying (so savvy, so de riguer). But this article is not one of those (you
might think so from its title). The error messages really could use some TLC.

~~~
futuremint
The error messages could use some love, but the article is crap. He didn't
break Rails in any predictable ways. Who breaks stuff accidentally by
misspelling things? Spellcheck can be turned on just about everywhere in any
modern IDE or Editor.

~~~
silentbicycle
> Who breaks stuff accidentally by misspelling things?

Wasn't there just another thread about '=' vs. '==' last week?

------
gills
Friend, what you need is a compiled imperative language with verbose type
declarations. Java comes to mind.

Rails works by following conventions that feed metaprogramming and
method_missing magic, and the kind of safety net which the author seems to
imply is missing will just never be available in that sort of system.

I find little errors like these totally worth it because of the time I save by
using rails, and after the first couple of weeks (as many have already posted)
most of these are non-issues.

------
wgj
Rails uses Ruby's metaprogramming capabilities extensively, and those
capabilities are one of the reasons people choose Ruby, as well as the very
thing that makes it possible for Rails to work the way that it does. This is,
at least in part, why your code doesn't seem to be on the call stack. My
question is, do other language environments do better at exception analysis
when metaprogramming is used in this way?

------
Zef
My response to your criticism: <http://zef.me/2355/a-when-rails-fails-follow-
up>

------
jcapote
gem install ruby-debug

------
gsiener
He's right, rails doesn't improve speling.

