What is meta? ×
Meta Stack Exchange is where users like you discuss bugs, features, and support issues that affect the software powering all 128 Stack Exchange communities.

I recently asked a question that was the programming equivalent of "How can I check if this carton contains only eggs?" It was closed as not a real question after an answer has already been accepted.

There were many who got it right away, but some who asked things like "Do you mean it can also contain apples, oranges, and beef?" I don't get this. I don't get how much clearer I'm supposed to--or can--make this question, how much more I need to emphasize the word 'only', or why it is any of ambiguous, vague, incomplete, overly broad, or rhetorical. It definitely could be easily answered, as proven by eight users with nearly all different approaches.

What sort of extra information should I add to a problem that seemed so simple?

share|improve this question
1  
The comments asking for clarification and the closing of the question don't necessarily have anything to do with each other. The former is totally normal and perfectly okay; whether the question should have been closed is a different matter... I don't know the language so I can't really judge that. –  Pëkka Sep 4 '12 at 22:40
add comment

2 Answers 2

up vote 5 down vote accepted

The question is not well written but it's also definitely a "real question", so I've voted to reopen.

But to avoid this sort of thing in the future, here's a better way to write that question:

I have a list of values stored in some variables (say, foo, bar, baz, and qux). I want to create a function that takes a list of things and checks that the list only contains one of the values stored in these variables

For example, say I have:

foo = "spam"
bar = "eggs"
baz = "parrot"
qux = "fjords"

bad_list = ["pining", "fjords", "parrot"]
good_list = ["spam", "spam", "spam", "spam", "spam", "eggs"]

I want a function that would pass for good_list with the variables I have but fail for bad_list (since "pining" is not in one of the variables I have).

What could I use to create such a function?

In this case, what I've added is examples of expected behavior given a theoretical set of inputs and outputs which helps clarify the question. It also helps to explain what types you're using in general. In Python it's not as big of a deal usually but it can be confusing if you don't specify so if nothing else say "of any type" if that truly is the case.

share|improve this answer
    
I find this borderline difficult to read, actually. –  Dave Newton Sep 4 '12 at 23:02
    
@DaveNewton because...? –  Daniel DiPaolo Sep 4 '12 at 23:09
    
Too many words not directly related, middle paragraph too dense, too many Monty Python and meta-syntactic references, redundant last sentence (or portion of first). I'll see if I can come up with anything better, though. –  Dave Newton Sep 4 '12 at 23:13
    
That helps significantly. –  Dave Newton Sep 4 '12 at 23:16
    
@DaveNewton the Monty Python stuff is "classical" for examples with Python, and I've reformatted to use more code and less words - I agree it was too dense, but didn't want to do the nested blockquote and code formatting. You convinced me to be less lazy :) –  Daniel DiPaolo Sep 4 '12 at 23:16
    
If only I could convince myself to be less lazy. Dammit. –  Dave Newton Sep 4 '12 at 23:17
    
I took a stab at it. I cover an additional facet from the OP, and made up a couple of other possible scenarios. –  Dave Newton Sep 4 '12 at 23:30
add comment

The "best" answers may use tricks not available when the boundary conditions are not well-defined.

In your example you say that "w, x, y, and z can be in list A", which does not specifically exclude a, b, or c. Whether or not this is important depends on context.

The question regarding whether the items are single values or lists may also have an impact.

Devs like to have fairly explicit requirements. The way to make it clearer is to make it clearer. Define boundary conditions explicitly. Provide typing information. Provide good/not-good examples. Etc.

Here's my spin, covering some edge cases, etc. with some followup afterwards.

How can I write a function that indicates if a list of values contains only allowable values?

Allowable values:

  • Are "simple", e.g., no nested objects, tuples, etc.
  • May be duplicated
  • May appear in any order
  • Are stored in a number of variables

allowable0 = "w"
allowable1 = "x"
allowable2 = "y"
allowable3 = "z"

# Should pass, contains only allowable values.
A = ["x", "y", "z"]

# Should pass, contains duplicate and repeated allowable values.
A = ["x", "x", "w", "z", "y"]

# Should fail, contains a value not in the allowable values.
A = ["a", "x", "z"]

The list does not need to contain all allowable values, it just needs to only contain allowable values.

Compared with Daniel's, mine takes up significantly more vertical space. It covers a bit more ground with regards to specification, including some not asked for in the original–that was more an experiment in requirement density vs. readability.

[~DB/tech/communication]$ wc *
      16     111     638 q1.txt
      25     120     717 q2.txt

That was interesting; I enjoyed it.

share|improve this answer
add comment

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .