Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

This question is being asked for the purposes of evaluating whether or not attempting to use things I picked up in college was a good idea, or even remotely defensible.

Last year I wrote a 'formula creator' for figuring out what to do with fields or how to populate fields of HL7 data. The fact that it's HL7 data is almost unimportant, except for the fact that it's not always known whether or not an HL7 field is going to exist or if it's going to repeat.

Therefore, I thought, if I need to get a list of these fields I can return myself a set of them. If I don't find them at all, I can add an undefined, fuzzy value, to the set. Then I can evaluate certain things on the set, (i.e. do all of them exists, do more than 6 match some regular expression, do the ascend from greatest to least).

Everything works OK, except what to do with 'All Of' and empty set.

For the interest of making a program easy to use, should 'all of []' return true or false? I tried to make a case that "In set theory, the existential operator yadda yadda deaf ears".

I'd like an answer to the first question, because it may require going back to the drawing board, but I'll fast forward a to a few months ago we got around that problem by never having an empty set. If we encountered 0 fields in the HL7 message, we'll just ploink undefined in the set.

The way I wanted to use undefined was as some sort of catalyst for, "I have no idea". So True or Undefined = Undefined, False and Undefined = Undefined and Not Undefined = Undefined. I made it a point to be very consistent in my programming with this, but everything that ailed the program could have been alleviated by making "Not Undefined" = True.

I told the two guys who actually use my program to 'always make his formulas to expect the true case', cuz that's how Don Knuth does it.

In summary, my program works. The problem is that it is encumbered by my adherence to principles, clearly outside the domain of the problem, that if I slackened would make the program flow better and function without requiring me to consult the source code.

My question is, should abstractions match the domain?

Can I legitimately argue to a nurses, bosses and (more military minded) programmers that "all of an empty sack is true" or "the opposite of unknown is still unknown"?

share|improve this question

1 Answer 1

up vote 4 down vote accepted

Given the structure of HL7, wouldn't a tree be more natural than sets? I guess even if you use a tree, the collection of child segments (or child segments of a given segment type, if that's what you are referring to) would be a set (though I would call it a collection, since sets imply not being ordered and not having duplicates, and HL7 segments might care about the order and the notion of equality of segments doesn't really exist).

I don't think it's going to work out as well to represent a collection of zero elements as a collection of one undefined element. It will probably give you more edge cases (simple example - a count operator to determine how many segments exist). Plus it forces you into a three valued logic, which is a pain, for no apparent benefit.

There is no reason operators that act on collections can't act on empty collections. Again, the behavior should be what gives you the fewest surprises and fewest edge cases. Generally this will match up with what makes sense mathematically.

Is AllOf something that checks if a property is true for every element of the collection? If so, I assume your current implementation returns undefined for a collection of 1 undefined element? Or did you define it such that in that case in returns true or false? If so, you haven't gained anything versus just returning that value for an empty collection. If it does return undefined, do you then write code that treats it as true or as false? Either way, there's your answer to what AllOf should return for an empty set.

I personally would have AllOf return true for an empty collection (or set). I would toss the 3 value logic unless it's proved valuable for some reason. I would allow empty collections. I would probably use the Composite pattern to represent HL7 nodes. I would not use sets, but lists. I would try to leverage the collection implementations of whatever platform I was using. For example, in C# I would make sure I could use the generic collection extension methods and LINQ with my segments.

Yes, abstractions should match the domain, and I think the abstractions you are using could match a little better.

You could argue to nurses, bosses, and programmers about your abstractions, but really only the programmers should really need to care. And I don't think you probably need unknowns at all, so that would cut down the amount of arguing.

share|improve this answer
    
Yeah AllOf[Undefined] = Undefined, but AllOf[empty] = true (but I coded that possibility out of existence). If undefined escapes the factor part of the formula yeah, it's treated as false. The only problem is, I still treat (not undefined) as undefined and yes, it remains false. I think removing the unknowns (or keeping the ability to handle them, but not to generate them) is probably the road I'm going to go down. The problem is that, AllOf[empty] = true, I'm going to have to make AllOf[empty] = false. –  Peter Turner Nov 10 '11 at 19:12
1  
Could you just make a function called (and yes, it's hard to think of a good name) AllOfSomething which returns false for an empty set and otherwise acts like AllOf? (AllOfAndExists, AllAndExists, Every, AllWeGots...)? –  psr Nov 10 '11 at 19:22
    
Yeah, I can add all the functions I want. I think I'm just going to call it AnyOf (I already had MoreThan0, but that was too confusing). Thanks for reminding me about Exists. That would have been sufficient! I should just assign a value of 1 to strings returned from HL7 messages and let the formula add'em up, if the result = 0 then no existen. –  Peter Turner Nov 10 '11 at 19:30
    
also, thanks for taking this question seriously and offering up a well thought out response! –  Peter Turner Nov 10 '11 at 19:32
    
@PeterTurner - You're welcome. I wrote something fairly similar several years ago, so, well, plenty of opinions... –  psr Nov 10 '11 at 19:41

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.