Regarding 1), I should note that the same is true of "isShearable" and a couple other "is<Something>" functions nearby. It doesn't make a difference in vanilla because all castes of the shearable animals are actually shearable, unlike milking or egg laying. But a sufficiently
determined demented modder could break it.
I wonder if the original intention was to find breeding pairs of certain types, say for autobutcher or some trading script? That's the only explanation I have for performing a caste tag check at the race level.
In my local copy I've snuck in "and uu.isFemale(u)" for counting milk orders but this is something again that a modder could break.
Regarding 2)
repeat -time 14 -timeUnits days -command [ workorder MilkCreature ] -name autoMilkCreature
What will happen with that code is that every 14 days workorder does its thing: checks for creatures that need milking, reduces its count by any existing order(s), and then creates a new order for the remainder if any. So far this is exactly what I'm looking for.
By the current default, however, the form of the created order in the job manager will have the frequency to restart "Daily" if none of the nonexistent conditions are false. So for example, once my 3 cows and 4 pigs have been milked, the very next day the
manager, not the script, will activate 7 milking jobs again. Unless it is an incredibly long walk between my pasture and my milking station, none of those animals will be ready for milking yet. Job cancellation ensues, and will happen every day until I manually erase the order from the manager's queue or it is time for milking again.
Even though workorder can cancel creating a new order when unneeded, I don't see any functionality that would remove or alter quantity on existing orders if they are too high. I'm not sure if this is a true bug or a difference in design philosophy that considers some other use-cases. For milking I believe it is less than ideal. When keeping a sufficiently large number of animals it could be true that a different set of 7 is ready for milking the next day, but not for small populations. Heaven help me on shearing with a 300 day regrowth interval. I understand and at least partially agree with the above rationale against checking for buckets: a bucket-related cancellation tells the overseer it's time to pay attention to fortress supplies. But a no animal available cancellation can be solved only with time and doesn't help the overseer one bit.
My practice: the way I have personally set up milking and shearing is to
repeat <some-other-stuff> workorder MilkCreature ; workorder ShearCreature <more-other-stuff>
on a regular basis (1200 ticks, piggybacking on an pre-existing repeat for other purposes).
After changing the default frequency in my local copy this generates "RunOnce" orders to milk/shear the number of creatures ready at the time of the check and once completed that order disappears from the manager's list. The next time the repeat executes workorder will perform the appropriate checks once again and order the correct number once again. Instead of the manager thinking we need to do that same number every day. With this absurdly frequent interval I'm surely checking more often than necessary, yet the auto-decrement ensures that jobs are never over-counted even if an earlier run is not completed before the current execution.
At least I think it works, I haven't gotten a chance to advance time very far yet.