1

Topic: length == 0 vs length <= 0

Whether often in a method it is necessary to check there is something in an array. Whether there is a sense to write length <= 0 when an array empty?

2

Re: length == 0 vs length <= 0

Hello, e.thrash, you wrote: whether ET> Often in a method it is necessary to check there is something in an array. Whether ET> there is a sense to write length <= 0 when an array empty? Depends on language. It can only pretends to be an array, and transferred any {length:-1}

3

Re: length == 0 vs length <= 0

Hello, e.thrash, you wrote: whether ET> Often in a method it is necessary to check there is something in an array. Whether ET> there is a sense to write length <= 0 when an array empty? We assume that length it is a fair method of obtaining of length. If it returns  any modern enough compiler will consider that this same that! = 0, also can freely replace one check with another. More often and becomes, because in CISC (and adjoined it ARM and Sparc) the command test is cheaper cmp with a zero constant. In RISC (a pure line, without flags of conditions), similarly, slt and sltu with the empty register are identical. If length sign (as in Java or Fortran where  whole is not present), not clearly, whether there can be a reset of the negative value and that with it to do. Basically, it means that the execution environment is destroyed and it is better to take off at once (completely, or on level of recovery after heavy failure). Accordingly, it is necessary to put such check that its consequences at <0 were minimum destructive for the data, but it is maximum - for an execution context. If language of type Javascript or Python, it is possible where to redefine everything - if this redefinition here is inadmissible the variant 2 and if it is admissible it is necessary to look see that such length means. Perhaps somewhere it means "could not receive length, thus, that X is object-proxy", and, can, it is a signal to read an array upside-down

4

Re: length == 0 vs length <= 0

is_empty ()

5

Re: length == 0 vs length <= 0

Hello, e.thrash, you wrote: whether ET> Often in a method it is necessary to check there is something in an array. Whether ET> there is a sense to write length <= 0 when an array empty? The sense is not present. If write length == 0, to the reader it is clear that check on emptiness. And if length <= 0, is at once thoughts, it that for such, it when length can be less zero? And better it is valid isEmpty if there is such method.

6

Re: length == 0 vs length <= 0

Hello, e.thrash, you wrote: I somehow had a similar question on check on upper bound: for (size_t i = 0; i! = count; i ++) or for (size_t i = 0; i <count; i ++)? For iterators (With ++) use only (1), and for integer that is more preferable?

7

Re: length == 0 vs length <= 0

Hello, flt, you wrote: F> I somehow had a similar question on check on upper bound: for (size_t i = 0; i! = count; i ++) or for (size_t i = 0; i <count; i ++)? F> For iterators (With ++) use only (1), and for integer that is more preferable? That you want. It seems to me that <reflects sense is better. . And still the increment can differ from 1