Live data from Hacker News

Zero one infinity rule

en.wikipedia.org

121–130 of 149 posts

Re: Zero one infinity rule

#121
> In real-world software design, violations of this rule of thumb are common. For example, the FAT16 file system imposes a limit of 65,536 files to a directory.[3]

Isn't it because 2^16 == 65536?

Re: Zero one infinity rule

#122
I believe Cyrillic languages have denominations that are beyond absent, singular and plural, like a large or small plurality.

We may ask for an ideal in software but as long as people exist, exceptions will exist.

Re: Zero one infinity rule

#123
post #62

While 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…

I don't think that goes against the rule. Your code doesn't impose an arbitrary limit on the data, it just internally represents it differently based on size.

Re: Zero one infinity rule

#124

John 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.

If you're using any reasonable language, using data structures without arbitrary limits is just as easy or easier than those with arbitrary limits.

Re: Zero one infinity rule

#125

If 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.

Re: Zero one infinity rule

#126
post #46

Earlier 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…

Dynamic allocation can often use up less memory, since it only reserves as much as it needs, not the maximum for every item.

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…

It is arbitrary. Why can it handle 1000 items, but not 1001 items?

Re: Zero one infinity rule

#128

Am 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…

Usually you wouldn't store these things in a collection, but as separate fields of a record type, so the rule doesn't apply.

Re: Zero one infinity rule

#129

It'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

#130
post #125

If 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.

Which means in a practice “infinity” is a lot lower than 2^64, although exactly how much lower depends on system configuration (how much memory the system has, how much of it this process is permitted to consume)
Post reply on HN