* Kent Dahl (kentda / stud.ntnu.no) wrote:

> Thomas Hurst wrote:
>
> > * Dave Thomas (Dave / PragmaticProgrammer.com) wrote:
> > > I have to say that Iowa was a joy to work with.
> >
> > I'll have to get my barge pole out and see if it can be persuaded to
> > use cookies.. and then, only if it really needs to save state :)
>
> One thing I found really neat about IOWA, is that I don't have to
> follow a linear usage of the web application developed. So I can log
> in, and open several links in different windows and shuffle my work
> between them, without losing any state in either.

Provided you have identifiable start and end points to transactions,
that's fairly trivial to achieve.

Basically, when you hit "Edit" or whatever, you get allocate a unique ID
for that form task, which is encoded in a hidden form variable, or the
URL; you then edit to your heart's content.  When you're done, you hit
Finish, the data in the transaction is committed, and the ID is deleted.

Hit edit in another browser window, you get a different ID and a
completely different transaction, while the first works completely
independently.

Different user accounts are a little more tricky, since your start and
end points are through the entire application; the basic premise is the
same, though; all you need to do is track the start (login) and end
(logout/expire), and encode enough information in the request that you
can tell them apart.

One way you might do this without impacting the URL too badly would be
to allocate one cookie per login, ala:

  User[0] - user's first logon
  User[1] - user's second logon

Each time you hit logon, it checks the cookies you've already got, and
picks the next one up, or reuses an old one; it sets the cookie, saves
the ID to the database linked to your state information, then makes all
the links on that page (or gives forms a hidden field) identify that
index.

You end up with /article/foo/bar/baz/?sid=1 or so, and a totally clean
URL if you only have one login to track.

Actual sessions are a little more tricky, since the start and end points
are less well defined.  You're probably not terribly interested in
saving much state for them, though.

Of course, people with cookies disabled don't get tracking at all, which
is kind of the entire point of disabling cookies, so bully for them :)

> I'm not too knowledgable on cookies, but I thought cookies was "per
> computer" as opposed to "per session", and would make the above unlinear
> usage rather difficult to achieve?

Not really.  Don't forget you don't often really need much state
information; it's mostly for when you're interacting with the system,
rather than fetching data.

GET's aren't even supposed to have side-effects, and POST's can encode
as much crap as you like without messing up with the user interface:
things like editing where you get a form to fill in to change stuff can
be concurrent easily.

The thing with Iowa is it is basically creating a whole OO application
per session; links are method calls, and the state is saved each request
so the objects can track them.  Although this is a nice approach in the
editing phase, for the majority of GET's it is major overkill; you're
not likely to be changing much state, you're more likely just to be
pumping out mostly static resources to the user based on the object they
requested and quietly forgetting about it.

Er, anyway, </babble>

>   /iowa/myapp/username/ or /iowa/myapp?username=username

<points out that if you ever want to migrate myapp from iowa, that URL
will at worst break, at best look pretty silly>.

Ideally, I'd like to see the Ruby FAQ URL's look something like:

    /faq/1/2

For faq section 1, answer 2.  Imagine if you found yourself learning the
numbers for specific questions which are asked a lot; it'd be trivial to
construct the above URL for a user.  Plus the user can look at the URL
and quickly see they can remove the /2 and get a list for that section,
etc.

URI == UI :)

-- 
Thomas 'Freaky' Hurst  -  freaky / aagh.net  -  http://www.aagh.net/
-
If you pick up a starving dog and make him prosperous, he will not bite
you.  This is the principal difference between a dog and a man.
		-- Mark Twain