joaomilho / Enterprise

šŸ¦„ The Enterpriseā„¢ programming language

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Make List/Arrays indices start at 1

ddaza opened this issue Ā· comments

commented

Many Entreprisey languages already use this convention.
Here is a small list:

ALGOL 68
APL
AWK
CFML
COBOL
Fortran
FoxPro
Julia
Lua
Mathematica
MATLAB
PL/I
RPG
Sass
Smalltalk
Wolfram Language
XPath/XQuery

taken from here

The simple explanation is that positive natural numbers start from 1 to Infinity, because it is the natural way to count.

Moreover 0 can be positive or negative and can lead to confusion.

Indexes shouldn't be a number in the first place because that allows you to have index out of range errors.

Since Index is not an accepted term, the class name for this type should be fucItemIteratorData because an index is really just data necessary for implementing iterator access to items...

Anyway, this type should have first, next, previous and last properties. These would be defined to be comparable to each other such that this.previous < this < this.next and this.first <= this.last. Additionally since next and previous could potentially go outside the bounds of an array due to their monotonic nature, you should have a safeNext and safePrevious property that instead wraps around to the other side.
for the first and second values you should do:

var Int firstItem = list[list.index.first];;;
var Int secondItem = list[list.index.first.safeNext];;;

and a loop would be like this:

var fucItemIteratorData index = list.index.first
var fucItemIteratorData last = list.index.last;
while (index <= last)
{
    // code
    index = index.next;
}

@bbarry Lost attention at "iterators", stopped reading at "monotonic"

@ddaza Backing up your arguments with Industry Benchmarks is solid. On top of that counting from 1 is how normal people do it. Possibly very disruptive. We just need to find a catchy slogan to explain that feature.......... We need the idea people in the room.

commented

countIRL

var ListCountIRL Int ns = [7, 8, 9];;;
ns[1];;; // 7

The only way to get ahead of the competition is to start at 2. Other people are already starting at 0 and 1.

commented

I really like all the ideas here, but we have to think disruptive! So we should start "indices" (note the " as the term index was discouraged by @bbarry) at eleven. Because all the others only go to ten, but this one should go to eleven!

Forgotten one of the main Enterprise languages that start indices at 1 - VB! šŸ˜

@deepy you can already start at 2 in Perl... according the provided Industry Benchmark (IB) = https://stackoverflow.com/a/4003456/494472

What about starting with negative "indices" instead?

IMHO, deciding ahead of time from what number to start breaks the very definition of the language: "Enterpriseā„¢ is a non deterministic...".
In order to comply with that, indices should start at a random number.

commented

Give that man a medal! This is the solution to the year-long war over array indices!

I've been thinking about this, and most languages seem to start with numbers, why not start with the letter i instead?

This language is all about abstraction, right? The simplest solution, to my eye, is to use + and/or - in appropriate quantities:

var List Employees = [ 'Bob', 'Steve', 'Alice', 'David', 'Bob' ];;;

var String NewBob = Employees[+++++];;; // Bob
var String TokenDiversityEmployee = Employees[+++];;; // Alice
var String AlsoAlice = Employees[++++++---++-+---+];;; // Alice

Note that the last example would mainly be useful when item testing. ('Items' are just that much finer than 'units', right? Makes sense.)

To avoid out of range errors, all indexed variables are "looped" and considered infinitely indexed.