views:

265

answers:

12

I'm validating that the integer is zero or greater. To describe the requirement as "zero or greater" feels too verbose. To say "non-negative" introduces negative language, which I try to avoid when I can.

What concise descriptor do you use when describing a value that must be zero or greater?

+7  A: 

positiveValue or unsignedValue

If you're using unsignedValue as a name, you should also make sure you use the matching unsigned data type (if your language supports it). If you use the proper data type, you wouldn't have to validate anything...the type would do it for you.

Justin Niessner
unsigned is quite c++ like, and i like it too ;]
Tomasz Kowalczyk
Good suggestions. "Positive" may or may not include zero (depending on whom you ask), so I don't like the confusion there. "Unsigned" narrows my audience too much. I'd like this name to be consumable by non-programmers/etc types.
lance
unsigned is just as negative as nonnegative
Esben Skov Pedersen
I may be mistaken, but I sounds like the @lance is trying to develop language which will be presented to a user... in which I don't think something like "Total cost must be an unsignedValue" would go over very well. Also, zero is neither positive nor negative so positiveValue is certainly no good.
Stephen Swensen
I did, actually, fail to specify my audience, but @Stephen Swensen is correct. This is language the end user will see. I'm really enjoying the answers which don't assume that, though, as this problem will apply to more audiences in time.
lance
+1  A: 

I would stick with simply Positive. Althought it's not strictly right, most people won't be surprised ou tricked by this naming.

Unsigned is a good choice to, as it is widely associated with positive number in programming languages (Ok, with number only positive or negative. But you get the idea)

cake
"most people [will consider zero included in 'positive']" -- My experiences suggest this might not be so safe an assumption? I've encountered a lot of confusion (in math, in UIs, in lots of places) about whether or not zero is valid when asked for a positive value.
lance
A: 

Positive

And greater zero for exclusive meaning


Note that unsigned integers are naturals ;)

Dario
+3  A: 

natural numbers or simply natural

KARASZI István
Natural numbers are all integers. If fractional values are allowed, natural numbers won't work.
Gabe
Depending on who you ask, natural numbers may or may not include 0.
Thomas Lötzer
Note that the question states the value is (understood to be) an integer.
lance
@Thomas Lötzer: To be sure. The referenced wikipedia page begins with: "(sometimes zero is also included)". That's not the clarity I'm seeking.
lance
I've seen it done differently, too. E.g. `N` for non-negative, and `N \ { 0 }` for positive, or `N` for positive and `No` for non-negative, Usually introduced explicitely as "convention for this course".
peterchen
yes, `Z*` could be the answer, which is called "nonnegative integers", but is excluded by the OP so I think `N` is the closest
KARASZI István
@Gabe the OP wanted integers, so naturals will work :)
KARASZI István
A: 

Unsigned would be incorrect, as that refers to a variable that can only be positive. I believe positive would be the correct name for this.

yorick
what does an unsigned negative number look like ?
NimChimpsky
@NimChipmsky: actually, it can only be positive, but people can do x -unsignedSomething, and use it as an only negative.
yorick
+2  A: 

I'd stick with non-negative. If it's good for maths, it must be good for users ;)

However, if the label is just "Number of X", this additional information isn't really necessary, and a validation result can have negative wording (e.g. "negative values are not allowed").

peterchen
"If it's good for maths, it must be good for users." -- haha!
lance
+2  A: 

I would argue that the answer depends on what audience you are writing for. If this is for other developers (i.e. for variable naming or API docs), then I think "non-negative" would most precisely express what you want. If this is for end-user documentation, then "positive" will be fine.

Always consider your audience, even while programming.

Quartz
It definitely depends on the audience, which isn't clearly stated in the question. Mathamatitions: "whole number" or "natural number", programmers: "non-negative 32-bit signed integer", others: "positive number or zero".
Jeffrey L Whitledge
+8  A: 

I think this link may help you

http://stackoverflow.com/questions/2045018/ieee-754-find-signbit-exponent-frac-normalized-etc

or

http://www.experts-exchange.com/Programming/Languages/Assembly/Q_25282255.html

Ravi shankar
Can someone explain what this answer has to do with the question? I don't think they are related.
NealB
+1  A: 

For validation messages, I normally go for something like:

"The number of widgets cannot be negative"

rather than:

"The number of widgets has to be zero or more"

teedyay
Or "Are you asking for *minus* ten widgets? Really? Really??? Get serious."
Jeffrey L Whitledge
A: 

For a requirements document, I would prefer "zero or greater". Requirements document will be (hopefully) widely read by people including those with a non-technical and a non-mathematics background. The phrase "zero or greater" makes it the border case clear (ie, zero is allowed). "Non-negative" may not be as clear to everyone.

Jim Ecker
+1  A: 

Unsigned Integer

Gary Willoughby
+4  A: 

Stick with non-negative. The meaning is clear, and more importantly, correct.

By analogy, consider the name given to a list of things sorted in ascending order. Calling the list ascending is only correct if you explicitly exclude the possibility of having repeated values. If the list contains two or more items of the same value it cannot be called ascending because two things that are equal cannot be placed in ascending order with respect to each other. In fact, such a list is properly called non-descending.

The negative/zero/positive problem falls into the same sort of trap. There are 3 categories of number: Negative, zero and positive. Describing a set that includes any two of the categories can be done by naming the two or by negating the possibility of the third. Any other type of description would be ambiguous.

NealB
This is the first time I've heard the term non-descending. A Google search reveals much ado about testicles.
P Daddy
I don't think having duplicate values violates the concept of ascending (or descending) order. Given the values [1, 3, 6, 6, 7], subsequent values change by [2, 3, 0, 1]. The moment of change at index 3 is indeterminate (from this one sample, it's impossible to determine if the list is sorted ascending, descending, or not at all), but the overall order is unequivocally ascending. You could better say that the sublist [6, 6] is both in ascending and descending order, rather than neither, defining that ascending order is a non-negative change, instead of only positive change.
P Daddy
@P Daddy: Ascending means increasing order. The definition of increasing implies a non-zero positive difference between elements E[N] and E[N+1] where N varies from 1 to the list size less 1. If any of these differences is zero, the best you can claim is that the list is in non-descending order because any other claim would violate the definition of ascending. Claiming ascending order in the face of duplicate values is not an uncommon and often harmless mistake. Some people consider such a claim good enough for most "government work".
NealB
Nowhere can I find such a definition of ascending or descending order to back up your statements. I truly understand your viewpoint, as you've defined ascending by strict analogy with positive numbers, and applied this analogy to every delta within the list of ordered items. In reality, however, the 0 delta between duplicate items does not disrupt the overall order of the list. For instance this line undeniably ascends: http://www.wolframalpha.com/input/?i=plot+0,+1,+2,+2,+3,+4
P Daddy
@P Daddy: Try searching for the term "nondecreasing" it may be more appropriate. I based my answer on a paragraph from Knuths: The Art of Computer Programming; volume 3 - Searching and Sorting. To paraphrase Knuth: The goal of sorting is to determine a permutation of the records where the keys are in nondecreasing order. On first reading it took me some time to realize the significance of those words. Also, have a look at this [definition of nondecreasing](http://everything2.com/title/nondecreasing). In retrospect, I probably should have said nodecreasing as opposed to non-descending.
NealB
FWIW, mathematicians call a function or series "monotonically increasing" if it never decreases, and "strictly monotonically increasing" if it only increases.
teedyay