Isn't it because 2^16 == 65536?
Zero one infinity rule
121–130 of 149 posts
Re: Zero one infinity rule
#122We may ask for an ideal in software but as long as people exist, exceptions will exist.
Re: Zero one infinity rule
#123While this has some theoretical merit, IME, limits are quite useful to catch bugs (or prevent degenerate cases). For example I was recently working on a permissions system wherein there can be members of groups. I set a reasonable limit on the size of a group based on a maximum of actual usage and what I could foresee being reasonable. A few days later, this limit was triggered, and I got a bug report. But it turned…
Yeah; expected limits are also fantastically useful in performance engineering. It’s very common your code needs to handle an arbitrarily sized input, but 99% of the time the input will be bounded. (Or generally simpler). Special casing the common code path can make a lot of code run much faster. For example, in some code I’m writing at the moment I have lists of integers all over the place. I call them lists - usual…
Re: Zero one infinity rule
#124John Carmack argued the opposite. He said he would hardcore limits into his data structures. Limits that would never be hit under normal operating circumstances. He argued that when you design software you should have an idea under what circumstances it will run and optimize for those. The fact that people normally don't do this, is why software often lags - that algo you implemented worked worked just fine when it's…
Ive come to agree with this. Say you have a struct that contains a name. If you limit the name size to say 64 bytes, then you can store it in the struct, otherwise you need to have a separate allocation and an indirection. This makes the code slower, more error prone and more complex to use. So think hard of when “infinite” is justified.
Re: Zero one infinity rule
#125If you took this rule literally though, you’d have to support bigints everywhere. Yet, in practice, setting the limit as INT64_MAX is seen as sufficient to count as “infinity”. In computing, “infinite” is almost never meant literally. When people say “infinite”, they really mean “finite but really really big”
Re: Zero one infinity rule
#126Earlier quoted context omitted.
Lots of examples (e.g. maximum number of nesting levels), see for example: http://www.tendra.org/tdfc2-config/chapter2 https://www.ibm.com/docs/en/epfz/5.3?topic=reference-limits One aim of finite implementation limits is to define which programs are guaranteed to compile successfully, so that you don’t run into the situation that a program compiles on one implementation but not on another implementation, which would…
In the embedded world you're always mindful of memory consumption. Static allocation of a fixed size array has advantages over the same data in a linked list by simple virtue of eliminating node pointers and bookkeeping overhead associated with dynamic objects. Regardless of concerns about algorithmic complexity. Sometimes you really do need to set fixed limits for the sake of economy. Minicomputers of the 70s and PC…
Re: Zero one infinity rule
#127> It argues that arbitrary limits on the number of instances of a particular type of data or structure should not be allowed. Either this is a misuse of "arbitrary" or it's not really arguing for no limits beyond 1. In the Carmack example from another comment, if you know your solution isn't going to scale well beyond 1000 items, that's not an arbitrary limit, and it's not 0 or 1 either. When we choose not to allow u…
Re: Zero one infinity rule
#128Am I the only person who sometimes makes an exception for "two" ?
I'd say that 2 is indeed quite common in Computer science. In graphs, for example, each edge has 2 ends. In an abstract syntax tree, a binary operator has 2 children. All raster images are based on 2 dimensions. A "for each" loop often involves 2 variables: the iterator object and an index. In all such cases it makes sense that a language/ construct/library special-cases 2 elements without generalizing for an arbitra…
Re: Zero one infinity rule
#129It's my rule of thumb that the only numbers one should find in code are 0 and 1. Anything else is a magic number and needs to be handled accordingly.
def solve_quadratic_equation(a, b, c):
d = b * b - 4 * a * c
if d >= 0:
return [(-b + sqrt(d)) / (2 * a), (-b - sqrt(d)) / (2 * a)]
else:
return []
How would you deal with the “magic numbers” here?Re: Zero one infinity rule
#130If you took this rule literally though, you’d have to support bigints everywhere. Yet, in practice, setting the limit as INT64_MAX is seen as sufficient to count as “infinity”. In computing, “infinite” is almost never meant literally. When people say “infinite”, they really mean “finite but really really big”
You'll run out of memory long before your array can reach 2^64 items.