I've got an application that has to return 100s of user-creatable documents in a user-configurable, deterministic and consistent order. What is the best way to acheive this?
I was hoping to use an enum (eg High, Medium and Low priority) as this keeps things simple and closed, but the ordering actually needs to be quite finely grained.
So, the next obvious choice is an integer...but there is the problem of lazy users giving very low or high priority documents increasingly huge values and hoping that the value they chose is the highest. Also, I need to be able to add a new document X between document A and document B without having to change the priorty of A or B (once a document has a priority, it cant change!) It's a bit like the line numbering problem in BASIC...should this priority go up in steps of 10, so I can add document X at 15? But what if I run out of space between numbers? Maybe steps of 100? 1000? Its getting ugly! And then you have a convention people have to follow, and our users might not be great at that. And what if I want something to happen before the document with ID 0, do I go into negative numbers? Maybe I could use floating point so it is unlikely I'd ever run out of space to 'insert' new documents? Getting even uglier!
Is there a nice solution to this problem, or is it basically just a case of using numbers and encouraging a sensible convention?
Some additional points, as I'm not sure I explained very clearly:
- The documents are in a database and need to be sent to another serivce in a particular order, defined by a property on the document itself, that cannot change once it has been set
- The priority value on each doc does not need to be unique