voodoorai2000 said the following on 05/01/08 11:59 AM:
Another advantage, you have to think harder about your design to make
it restful, you can't just be adding methods left to right like
crazy. As soon as your controller goes over 20 methods, you have to
stop and think. Think about a better way to structure/design you
application. As you say Anton, not all applications are suited for
this design, but most of them are,
I seem to have an uncanny knack of picking the maverick ones then!
When I think back, the only completely CRUD system I ever did was an
accounting package in DB 4GL called Progress.
I'm old enough and scared enough that I wok out alternatives before
implementing. I've been known to run many test examples to find out hwo
compilers 'work'.
Perhaps that's why I'm comfortable with 'constrained' approaches (you
call it 'convention over configuration' but its had other names in
history) rather than an 'infinitely rich colour pallet' for my artists
brush. If you'll pardon the analogy. I've found hat constraints means
focus.
So I get a lot of "yes, so what?" to that's being said about structuring
for REST. The slicing and dicing of command and control and
responsibility isn't new; I was taught it over 30 years ago.
it's just that we haven't done it
before and not sure how to tackle it.
LOL!
Maybe this helps, think about
the objects of you application, any object/noun can have its own
controller-model-view, which in most cases will lead to more
controllers but very simple controllers that you can understand in no
time.
You grew up speaking English, I guess. Not all languages work that way
and some languages you have to match up the cases, declinations and
conjurations as well as temporallities. There there's languages like
Navaho which are so radically different you can't really comapre them
with the Indo-European ones.
English, the subject - verb - object, way is either terribly sloppy or
terribly tollerant depending on how you look at it. Native speakers can
gloss and use idioms that are unintelligble to ESL, and non native
speakers can produce terribly fractured English with cases and tenses
all wrong but still be understood. Few other languages are that
'tollerant'.
My point here is that even with the CMV, 'there's more than one way to
do things'. I can make my controllers skinny in number of ways; by
offloading code into the models, into the views, into the helpers or
into libraries. I can build a controller around no methods except
'method_missing'. I can build it with lots of exception handlers and
few "if" statements that do checking
(http://blog.codefront.net/2007/12/10/declarative-exception-handling-in-your-controllers-rails-20-a-feature-a-day-2/
http://railsforum.com/viewtopic.php?pid=49600
http://nullstyle.com/exceptional/
and others)
So, instead of facing a 100 method controller you have 10
controllers with 10 methods, and 7 of them are the same in all
controllers. Isn't that beatiful and easy to understand?
You remind me of the English language teachers or possibly the "Business
Communication" who advocate short sentences with strong verbs and
concrete nouns. They are asking you to ruin the language. Here's a
pointer to a parody of one of the great works of our language with that
applied: The Gettysburg Powerpoint Presentation
John Kenneth Galbraith is one of the most clear, fluent writers of
technical and business English. In one of his books I encountered a
sentence that ran on for one and a half pages. I did a double take when
I realised it and went back and wrote the sentence out by hand,
decomposed it, and tried reformulating it a a number of shorter
sentences, with, alas, no success in preserving the clarity and impact
the original, and I do not believe that was due to any shortcoming in my
ability to handle the language. It was beautiful. It was graceful. It
was easy to understnad. But short it was not! (Now re-read this last
paragraph.)
One "traditional" way of judging code quality comes from the days of
"goto-ful" programming. With "GOTO" you needed to remember where you
came from as you flipped back and forth though the lsitings. So if you
needed more than a places where you had your finger stuck in the fanfold
as a placemaker it was called a 'more than five finger program'. On can
make the case that a single file is easier to scan that having ten
different controllers and having to grep to find which one has the
method, its all in one and your pinky finger just has to hit the '/'.
YMMV.
Okay another advantage. Once you have 10 controllers instead of 1
huge one, you can test it much better. Let me refrase that, spec
it cause we like BDD, don't we? So, you can write simple specs to
make sure each of those controllers does its job right, and that they
all comunicate with each other correctly, using for example, the all
might rspec Stories, which are freaking awesome So, your
application will become easier to spec and thus to maintain and extend
with confidence.
You're arguing in a circle.
Another advantage. Information and continuous improvement of the
site. In my opinion an app, is never complete, it can always be
enhanced with new features, re-factored, made more robust and become
more useful by deleting features that are of no important use.
And eventually become obsolecent ...
Thus,
if we all use REST we will be able to share information with other
sites and enhance our own site with more information. This
information needs to be readily available and easy to access and
update.
That's a non sequitor. It may or may not be true; it may or may not be
an advantage, but it certainly doens't follow on from the previous sentence.
One can, for example, add a RSS feed, or an RSS input, to a site with
little difficulty, without needing REST. One might even think of RSS as
'just another "skin"' defined by different template.
REST lays down the guidelines for everyone to have a common
language. If I know you have a site about car rentals with all the
rates in xml form at the url yousite.com I don't need to
know anything else to access your data and add it to my site.
I'm sorry: are you saying you need REST to output (or input) XML?
I don't think that's the case.
As you can hopefully see, there is no one advantage about REST, its
more of a synergy of small things that make the development of REST
applications a happy and beautiful process, we like happy and
beautiful right?
Actually no.
"The reasonable man adapts himself to the world; the unreasonable one
persists to adapt the world to himself. Therefore all progress
depends on the unreasonable man."
--George Bernard Shaw
Discontent presents a challenge.
Hope that helps
____ ___ ____ _ _
__/\__/ ___|_ _/ ___| | | |_/\__
\ /\___ \| | | _| |_| \ /
/_ _\ ___) | | |_| | _ /_ _\
\/ |____/___\____|_| |_| \/