Why Numbering Should Start At One

Counter arguments to WhyNumberingShouldStartAtZero


Dual-use Result

In string and array "find" functions which return a position number, 1-based can return zero (0) if the item was not found in the array or string. This won't work for zero based because zero is a real position. Some zero-based languages return something equivalent to nil or null, but I've found such awkward (ThreeValuedLogic) and non-intuitive. Null/nil flags are hard to debug and non-WYSIWYG. Zero-based can also return say "-1", but that's awkward.

How is -1 "awkward" as an 'item not found' indicator but 0 isn't?

It just strikes me as unnatural. Another reason is that if the language uses/interprets zero for FALSE, then it can more easily be part of a conditional:

 if (! find("foo", myThing)) {
   print("Not found.");
 }

Versus:

 if (find("foo", myThing) == -1) {
   print("Not found.");
 }

Better is...

 if (find("foo", myThing) == NOT_FOUND) {
   print("Not found.");
 }
...which works with NOT_FOUND defined as -1.

Still longer, and more dependencies.

More readable; one dependency.

{PhpLanguage has the === and !== operators that test type in addition to value, so FALSE == 0 but FALSE !== 0}

A risky visual and conceptual hack in my opinion. (I'm partial to systems and conventions that don't rely on a "hidden" "type tag", at least for dynamic languages. I prefer "WYSIWYG typing" or "tag free". [Insert topic link when found].)

So-called "dynamic" languages are frequently rife with abominations. Few popular languages are as muddled as PhpLanguage.

Agreed. I consider flag-free to be a LiberatingConstraint to simplify dynamic typing model. I'll live with the few drawbacks.

What's a "flag-free"?

Sorry, I meant "tag-free". I used to use "flag", but others here preferred "tag" and I concurred.

Rest of discussion moved to TypeTagDiscussion.

Of course, if you have a language with sum types, then you return "nat option" and don't have this confusion...


Closer to End-User

The end-user will almost always want any displayed counting or itemizing starting at "1". If the internals match this, then less conversion is required between the internals and the end-user side, reducing the code size and conceptual translation steps to inspect, verify, and debug.


When you numbering, you go 1-2-3, not 0-1-2! To use the second you are in effect saying you are not here, you are the first, then you are the second!

-- AnonymousDonor


CategoryMath


SeptemberTwelve


EditText of this page (last edited November 26, 2014) or FindPage with title or text search