Skip to content

Instantly share code, notes, and snippets.

@practicingruby
Created October 25, 2011 00:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save practicingruby/1310883 to your computer and use it in GitHub Desktop.
Save practicingruby/1310883 to your computer and use it in GitHub Desktop.
# Looking to reduces rows of board game data to
# primitives (for eventual JSON output).
# each cell can be either unoccupied, or occupied by N
# armies of a given color. What data format do you prefer,
# and why?
#----------------------------------------------------------
# 1) nil indicates empty territory
[[:white, 2], nil, [:black, 3]]
# 2) :empty indicates empty territory
[[:white, 2], :empty, [:black, 3]]
# 3) somewhat homogenous. nil indicates count being non-applicable
[[:white, 2], [:empty, nil], [:black, 3]]
# 4) fully homogenous. 0 indicates no units of either color present
[[:white, 2], [:empty, 0], [:black, 3]]
# your own representation (leave a note in the comments)
@adkron
Copy link

adkron commented Oct 26, 2011

In that case I would go with number 4. I like constancy in my data and api. If the empty cells are going to take up too much space then I would go with 1 to save space.

@fguillen
Copy link

I go for #4, after all the advantages already said, I'd add the self-documented style.

As you said is a serialization structure what we are defining here, so would be possible to think it is gonna be drunk up by external systems, better then that the info has an implicit way to be understood.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment