Revised Bermuda Islands

Ovid on 2008-02-15T10:05:05

Since hdp and schwern both recommended that I specify elements in Bermuda Island files as a list of key/value pairs, I've gone ahead and tried it out. It much easier to read now. I have this:

---
package: Some::Class
island: dummy
attributes:
  name:
    type: string
  version?:
    type: integer
  some_val?:
    type: integer
    if: $instance->some_val > 1
elements:
  - personal_email:
      type: string
      method: email('personal')
  - work_email:
      type: string
      method: email('work')

Turning into this:

{
   "elements" : [
      {
         "value" : "victoria@example.com",
         "name" : "personal_email"
      },
      {
         "value" : "victoria@some_company.com",
         "name" : "work_email"
      }
   ],
   "name" : "dummy",
   "attributes" : {
      "version" : 3,
      "name" : "Victoria",
      "some_val" : 4
   }
}

Obviously that's just the built-in JSON serialization.

Unless I get radically more free time soon, I likely won't be able to do much more for a couple of weeks.

I also note that if I make attributes an ordered list of k/v pairs, then the attribute and element syntax becomes identical, with the exception that attributes are not allowed to have '*' or '+' quantifiers. This would be very, very handy. However, attributes in XML are, by definition, not ordered, so imposing an order sounds wrong. On the other hand, imposing an order, even as a convenient side-effect, shouldn't hurt consumers of the serialized data structures and might help poorly coded consumers. Also, simply making it easier to write Island files by normalizing the syntax is very appealing.

Update: Yuck. I need to clean up my JSON and YAML even more. That should read:

{
   "elements" : [
      "personal_email" : "victoria@example.com",
      "work_email" : "victoria@some_company.com"
   ],
   "name" : "dummy",
   "attributes" : {
      "version" : 3,
      "name" : "Victoria",
      "some_val" : 4
   }
}