Talk:Text processing/Max licenses in use: Difference between revisions
Content added Content deleted
(document assumptions) |
(removed "file exists" assumption) |
||
Line 5: | Line 5: | ||
The J solution makes assumptions to allow the interesting code to stand out (rather than the drudgery). This obviously comes at the cost of some robustness (and, incidentally, optimizes for speed). |
The J solution makes assumptions to allow the interesting code to stand out (rather than the drudgery). This obviously comes at the cost of some robustness (and, incidentally, optimizes for speed). |
||
* Assumes the file exists in the working directory. Could easily reference another path. Could check for file existence. |
|||
* Assumes the format of the file is fixed (there will always be spaces in columns <tt>7 11 13 33 37 41</tt>). This can be changed easily to find columns of all spaces and cut there; doing so would actually make the program shorter and simpler, but obviously slower. |
* Assumes the format of the file is fixed (there will always be spaces in columns <tt>7 11 13 33 37 41</tt>). This can be changed easily to find columns of all spaces and cut there; doing so would actually make the program shorter and simpler, but obviously slower. |
||
Line 14: | Line 12: | ||
* Assumes a license will be checked out before it's checked in, and checked in before it's checked out, and that initially all licenses are checked in. |
* Assumes a license will be checked out before it's checked in, and checked in before it's checked out, and that initially all licenses are checked in. |
||
* Does *not* assume the file contains any data (i.e. |
* Does *not* assume the file exists or, if it exists, that it contains any data (i.e. it may be zero bytes long). For example, if the file is empty, you get this: |
||
Maximum simultaneous license use is 0 at the following times: |
Maximum simultaneous license use is 0 at the following times: |
||
:Note that I didn't have to do any special checks to get this behavior, it just fell naturally out of the code. (This happens a lot in J.) |
:Note that I didn't have to do any special checks to get this behavior, it just fell naturally out of the code. (This happens a lot in J.) |
Revision as of 02:46, 4 October 2008
Assumptions
We might be better able to compare code if we document our assumptions.
J
The J solution makes assumptions to allow the interesting code to stand out (rather than the drudgery). This obviously comes at the cost of some robustness (and, incidentally, optimizes for speed).
- Assumes the format of the file is fixed (there will always be spaces in columns 7 11 13 33 37 41). This can be changed easily to find columns of all spaces and cut there; doing so would actually make the program shorter and simpler, but obviously slower.
- Assumes columns 3 and 6 are Date and Job ID respectively. Could easily be checked; pattern matching would permit the code to identify the columns heuristically.
- Assumes a license will be checked out before it's checked in, and checked in before it's checked out, and that initially all licenses are checked in.
- Does *not* assume the file exists or, if it exists, that it contains any data (i.e. it may be zero bytes long). For example, if the file is empty, you get this:
Maximum simultaneous license use is 0 at the following times:
- Note that I didn't have to do any special checks to get this behavior, it just fell naturally out of the code. (This happens a lot in J.)