Wednesday, January 11, 2012

do NOT create collections in JavaScript by splitting flattened gunk out of a string

Why?

In my undertaking of the work outlined in the first link of the second bullet above, I dove deep into collections in JavaScript which I had not before worked with. I made a sloppy mess. There was want for changes. Firstly, when one selected programs and a sample type, it was desired that all of the potential program plans end up selected outright instead of merely becoming potentially selectable. This change wasn't too hard to accommodate in what I wrote, but, later on, when it was discovered that if one had a period in a program name that it would sabotage my code which split strings on periods, there was the need for a ground-up rewrite. Joel's recommendations guided the course taken:

  1. move collections from C# to JavaScript by way of serialization
  2. keep collections as collections, do not flatten collections to strings
  3. do not recreate collections by way of splitting strings as the character one splits with may end up being needed
  4. use hashes instead of arrays, allowing for key value pairs, escaping using a plain-text name as both a unique key and a value, as there may be significant pain in using a plain string as a key (what if one name contains another as in Arkansas containing Kansas?)
  5. use the Guid keys out of the database for rows of records as the unique keys for collection items (there will never be an Arkansas/Kansas conflict)

 
 

This whiteboarding by Joel shows off his ideas. The erased line touches on "it was desired that all of the potential program plans end up selected outright instead of merely becoming potentially selectable" as suggested above. At the right we see a key/value pair data structure for a collection in which the key is a Guid for a program and the value is another key/value pair data structure. The collections within the collection have a Guid-of-program-plan/plain-text-name-of-program-plan key/value shape. The greater collection structure shows how all of the potential program plans for each program in a collection of programs may be kept in a digestible manner.

No comments:

Post a Comment