Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

Ovid (2709)

Ovid
  (email not shown publicly)
http://publius-ovidius.livejournal.com/
AOL IM: ovidperl (Add Buddy, Send Message)

Stuff with the Perl Foundation. A couple of patches in the Perl core. A few CPAN modules. That about sums it up.

Journal of Ovid (2709)

Friday November 28, 2008
09:12 AM

Tabular Code Formatting and No Editor Support

[ #37965 ]

There are times that I want to format my code in a tabular format. Recently we're struggling with some of our RelaxNG compact schemas for our REST XML because we have something like this:

promo-element = element promo {
    ids-group?,
    promo-body,
    links-element?
  }

Note how everything but the promo-body is optional? The ids are forbidden in a POST, but required for PUT and GET. The links-element, however, is required for GET but forbidden on POST and PUT (actually, we allow them and ignore them).

So really, we want three definitions here.

GET-promo-element = element promo {
    ids-group?,
    promo-body,
    links-element?
}

POST-promo-element = element promo {
    promo-body,
}

PUT-promo-element = element promo {
     ids-group,
     promo-body,
}

This doesn't look too bad, but take a look at our series element:

series-element = element series {
    pid-addressable-attr-group?,
    revision-attributes-group,
    collection-attr-group,
    crid-group?,
    ids-group?,
    relations-group,
    title-description-group,
    master-brand-group?,
    related-element?,
    genres-group?,
    formats-group?,
    stack-element,
    promotions-group?,
    warnings-group?,
    links-element?
}

Imagine taking the above and laying it out vertically in three separate definitions and knowing it's going to grow over time. Seeing what's related to what could get confusing (it would be much worse to have this duplicated information spread across multiple files.

That's why it would be nice to implement this:

GET-promo-element =  -  POST-promo-element = -  PUT-promo-element =
  element promo {    -    element promo {    -    element promo {
    ids-group,       -                       -     ids-group,
    promo-body,      -     promo-body,       -     promo-body,
    links-element    -                       -     links-element?
  }                  - }                     - }

Everything lines up nicely, it's easy to see how things relate, and it's completely invalid RelaxNG -- until you split those three columns. Editing it would be a pain, though. Editors work vertically, not horizontally (vim has some interesting support here, but it's clumsy).

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • Well, some editors can edit tabular data [emacswiki.org] decently.

    Particularly the table editor in org-mode [linuxjournal.com] (find "tables" in the page) is nice. It can be used outside of org buffers as well.

    Not sure it can use arbitrary column separators though, but that might be possible.

  • From looking at that definition it looks like you can split the list in three parts for each method, of which the middle one is identical. You can express this perfectly well in RNG.

    • Of course you can and that's an option we explored. However, look at the larger RNG definition. Many of the required/forbidden/optional elements vary quite a bite for GET/POST/PUT and the split of the three of them, with dependencies, we felt was much easier to read when separate definitions rather than multiple paths on the same definition.