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

Re: Writing code for master: paradigms that work



Hi, Erik,

Great stuff, love to hear you're tackling these issues head-on. I'm totally in favor of everything I've read from your 3 mails of today... and will add comments from my perspective...

On 06/21/2015 01:04 PM, Erik Huelsmann wrote:
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

It's great to organize CSS/JS to work per screen/page. However, it's not that useful to load it per page. For the most part, I think it's best to simply aggregate all the JS/CSS and send out as a single file to the browser, and allow that to get cached.

With Dojo, we can define multiple layers in the build, so it might be good to exclude seldom-used scripts to their own layer, or exclude them from the build entirely -- as long as we're using AMD Dojo should handle loading them if necessary if they're not in the build. But aggregating everything should work well for us.

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

Pub/Sub I've found to be extremely powerful for a single-page app, and is exactly what I've used in the past. +1

 * Create widgets which - as much as possible - can be reused on other pages

+1

 * 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'

Break this out into the SASS discussion -- I'm partial to partials ...

 * 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

I don't see any benefit to not loading all CSS for the app one time, in a single file. Organize all the CSS into separate Sass files per page, but in the end they all end up in a single CSS file.

And yes, a class attribute attached to the body tag can be a great way to provide per-page css, make it easy to target.


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).

+1

Yes. Absolutely.


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.

Ok. If that's the architecture we're using, I agree it certainly needs improvement.

What I've done in the past is something much like this -- providing a Request and a Response object that gets passed through the controller.

E.g. at the start of the request handling, the parameters/body is extracted and had a single controller function to figure out who handles this request. Before handing off, it gets a generic response object, with a class that is selected based on what the requestor asked for -- HTML, JSON, XML, CSV. These all are different response classes that inherit from a base response class with common methods for populating data.

Drupal 8 has moved to Symfony at its core, and the heart of Symfony is a router system and a service container. The service container basically registers a bunch of objects to handle any service. The router determines which controller to invoke. Any code along the way can request a service from the container, and at the point it's requested, that's when it's instantiated.

So... the patterns we're discussing I'm seeing put in widespread use. I'd say those 3 things are crucial for us to define/decide how we're going to implement (and perhaps find some Perl framework to assist if those we're currently using are insufficient):

* Request routing
* Service container to make it easy to register and load services
* Response object (which needs to include the definition of how to return exceptions).

Will respond to the other two posts, too...

Cheers,
John
http://freelock.com

------------------------------------------------------------------------------
Monitor 25 network devices or servers for free with OpManager!
OpManager is web-based network management software that monitors 
network devices and physical & virtual servers, alerts via email & sms 
for fault. Monitor 25 devices for free with no restriction. Download now
http://ad.doubleclick.net/ddm/clk/292181274;119417398;o
_______________________________________________
Ledger-smb-devel mailing list
..hidden..
https://lists.sourceforge.net/lists/listinfo/ledger-smb-devel