[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Writing code for master: paradigms that work



Hi,

Today, Chris and I worked on merging my 'master-fixup' branch to master, followed by the actual merge. While working on 'master-fixup', I learned a few things that I'm summarizing here because they're really important to know when you're developing for our 1.5+ releases. I'm thinking of creating a page documenting these items on ledgersmb.org as well.

What I learned while coding on current master, i.e. after the 'frame-less' and 'PGObject' changes, is that, due to the 'frame-less' change:
 * The HTML HEAD tag is now completely useless, except for the pages returned by 'login.pl'
 * Any JS linked in the head tag as well as any JS included in SCRIPT tags is completely ignored
 * Any CSS linked in the head tag is completely ignored
 * Any JS or CSS directly included in the head tag is completely ignored

What *does* work is:
 * Put all behaviours for all elements in Dojo widgets
 * Put nothing in the response HTML other than widget references (data-dojo-type) and widget configuration (data-dojo-props); everything else should be in the widget
 * In case widgets on a page need to communicate their state changes, etc, use 'dojo.topic' and the publish/subscribe paradigm -- this creates a loosely coupled UI and reduces chances for exceptions
 * Create widgets which - as much as possible - can be reused on other pages
 * Make sure the HTML structure is valid; the Dojo AMD parser can be seriously confused by incorrectly nested elements
 * All CSS for any and all pages must be included in 'css/global.css'
 * CSS can be made page-specific by wrapping the entire body of an HTML response's BODY tag in a DIV with a page-specific (and globally unique) ID attribute; that attribute can be used to attach the page's CSS to

As part of the frame-less change, I've addressed a long standing irritation of mine: the handling of errors. Before, every time you entered a form's data incorrectly, you'd be shown an ERROR page, but not be given back the data you entered. Now, if the server reports an error, it's shown as a popup dialog. Because of this handling, the entered values now don't get lost. If processing fails, the scripts should therefore make sure to return an http error to the client (with a meaningful description in the (HTML) body).


Due to the PGObject change, it has become clear - if that wasn't already the case - that our current handling of the $request variable is far from ideal. Problems that we have:

 * $request is manipulated into a response by replacing values in the hash as processing proceeds (leading to a point that code can't be sure what values it's receiving!)
 * some parts of the code instantiate new hashes, expecting constructors to copy *everything* of $request which they are not providing themselves

Even though dojo-ifying the entire code base (by which I mean that we will be transforming everything to dojo UI and service requests from there) -- and thus we'll be moving away from the template based processing structure -- I think it's important to lay out how this should work as the move to PGObject caused problems in this respect.

The problems with PGObject and the $request object being mutilated into a response object (or being replaced by another object) are most apparent in relation to the template processing engine when values aren't copied from $request to its replacement.

Basically, my view on things is that there shouldn't be a replacement at all. Instead, $request should hold all the values as passed in by the request. $request should *always* be passed into the template engine in the { request => $request } variable, so templates can refer to the original values. These values include - most importantly - the name of the script from which the template is being called: request.script (this is required for correct form submission, most of the time).

In addition to the $request object, one or more objects can be and should be passed in from which the template engine should generate the response. This is a lot like the handling of the contact screen already takes place (but in many places in the code it doesn't).

Why write it down if we're going to move away from it anyway? Well, because if smaller problems need to get fixed in those areas, rewriting to this paradigm might actually already fix the issues encountered.


Comments very welcome! I'll see how to make sections in a "coding standards" document/page for publication on ledgersmb.org.



--
Bye,

Erik.

http://efficito.com -- Hosted accounting and ERP.
Robust and Flexible. No vendor lock-in.
------------------------------------------------------------------------------
_______________________________________________
Ledger-smb-devel mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-devel