New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Why do Julia arrays use 1-based indexing? #558

Closed
lygstate opened this Issue Mar 10, 2012 · 12 comments

Comments

Projects
None yet
9 participants
@lygstate

lygstate commented Mar 10, 2012

For most language they are start with 0. Why Julia choose zero.
And from mathematical point of view, start with 0 is better.

1 1 Java 17.050% -1.43% A
2 2 C 16.523% +1.54% A
3 6 C# 8.653% +1.84% A
4 3 C++ 7.853% -0.33% A
5 8 Objective-C 7.062% +4.49% A
6 5 PHP 5.641% -1.33% A
7 7 (Visual) Basic 4.315% -0.61% A
8 4 Python 3.148% -3.89% A
9 10 Perl 2.931% +1.02% A
10 9 JavaScript 2.465% -0.09% A

@lgarron

This comment has been minimized.

Show comment
Hide comment
@lgarron

lgarron Mar 10, 2012

Depends. Mathematica uses 1-indexing, and it makes perfect sense mathematically and code-style-wise.

I haven't been able to compile / run julia, though, so I can't give a julia-specific defense. :-/

lgarron commented Mar 10, 2012

Depends. Mathematica uses 1-indexing, and it makes perfect sense mathematically and code-style-wise.

I haven't been able to compile / run julia, though, so I can't give a julia-specific defense. :-/

@JeffBezanson

This comment has been minimized.

Show comment
Hide comment
@JeffBezanson

JeffBezanson Mar 10, 2012

Member

There is a huge discussion about this on the mailing list; please see that. If 0 is mathematically "better", then why does the field of mathematics itself start indexes at 1? We have chosen 1 to be more similar to existing math software.

Member

JeffBezanson commented Mar 10, 2012

There is a huge discussion about this on the mailing list; please see that. If 0 is mathematically "better", then why does the field of mathematics itself start indexes at 1? We have chosen 1 to be more similar to existing math software.

@lygstate

This comment has been minimized.

Show comment
Hide comment
@lygstate

lygstate Mar 10, 2012

Can you give me the URL of the discussion?

lygstate commented Mar 10, 2012

Can you give me the URL of the discussion?

@JeffBezanson

This comment has been minimized.

Show comment
Hide comment
@JeffBezanson

JeffBezanson Mar 10, 2012

Member

http://groups.google.com/group/julia-dev/browse_thread/thread/b4d37bd859d86d84?hl=en

You might have to join the list to be able to view it.

It really isn't that interesting a topic though. We all work with both 0-based and 1-based languages and I don't think it matters that much.

Member

JeffBezanson commented Mar 10, 2012

http://groups.google.com/group/julia-dev/browse_thread/thread/b4d37bd859d86d84?hl=en

You might have to join the list to be able to view it.

It really isn't that interesting a topic though. We all work with both 0-based and 1-based languages and I don't think it matters that much.

@filmackay

This comment has been minimized.

Show comment
Hide comment
@filmackay

filmackay Feb 5, 2014

Sorry about bringing up a painful memory? What about sidestep the issue of 1-ness with a 'begin' just like 'end':

a[begin] = 1 # first item
a[begin+1] = 2 # second

You could leave the integral (non-begin-or-end) as is 1-based, but allow those who want to think in 0-ness to use begin in that style?

filmackay commented Feb 5, 2014

Sorry about bringing up a painful memory? What about sidestep the issue of 1-ness with a 'begin' just like 'end':

a[begin] = 1 # first item
a[begin+1] = 2 # second

You could leave the integral (non-begin-or-end) as is 1-based, but allow those who want to think in 0-ness to use begin in that style?

@johnmyleswhite

This comment has been minimized.

Show comment
Hide comment
@johnmyleswhite

johnmyleswhite Feb 5, 2014

Member

I don't really see how pretending that Julia isn't 1-indexed will help people learn to use Julia, given that Julia is unambiguously 1-indexed and will stay that way. Unlike end, this way of using begin is an exact synonym for 1 in all contexts, which violates the generally desirable design guideline that there should be only standard way to do something.

Member

johnmyleswhite commented Feb 5, 2014

I don't really see how pretending that Julia isn't 1-indexed will help people learn to use Julia, given that Julia is unambiguously 1-indexed and will stay that way. Unlike end, this way of using begin is an exact synonym for 1 in all contexts, which violates the generally desirable design guideline that there should be only standard way to do something.

@simonzack

This comment has been minimized.

Show comment
Hide comment
@simonzack

simonzack Apr 4, 2015

We have chosen 1 to be more similar to existing math software.

From a programmer's perspective, I find 1-based indexing harder to wrap around compared to python (mod operations on indexes, -1), etc.

I also thought julia's goal was to unite the mathematical and general purpose languages. In this regard, 0 based indexing is much more popular. Indexing may seem like a small thing, but you deal with it daily, more often than anything else.

simonzack commented Apr 4, 2015

We have chosen 1 to be more similar to existing math software.

From a programmer's perspective, I find 1-based indexing harder to wrap around compared to python (mod operations on indexes, -1), etc.

I also thought julia's goal was to unite the mathematical and general purpose languages. In this regard, 0 based indexing is much more popular. Indexing may seem like a small thing, but you deal with it daily, more often than anything else.

@johnmyleswhite

This comment has been minimized.

Show comment
Hide comment
@johnmyleswhite

johnmyleswhite Apr 4, 2015

Member

I don't really think this topic is open for discussion anymore.

Member

johnmyleswhite commented Apr 4, 2015

I don't really think this topic is open for discussion anymore.

@pao

This comment has been minimized.

Show comment
Hide comment
@pao

pao Apr 4, 2015

Member

From a programmer's perspective, I find 1-based indexing harder to wrap around compared to python (mod operations on indexes, -1), etc.

See also mod1(), which specifically addresses this need.

Member

pao commented Apr 4, 2015

From a programmer's perspective, I find 1-based indexing harder to wrap around compared to python (mod operations on indexes, -1), etc.

See also mod1(), which specifically addresses this need.

@kmactavish

This comment has been minimized.

Show comment
Hide comment
@kmactavish

kmactavish Aug 22, 2015

Julia recommends pyplot for plotting. Pyplot uses 0-based indexing by default, so plotting plot(1:10) gives you the line y = 1:10, x = 0:9. However, since the x-axis is supposed to just be the indices when left unspecified, you would expect y = 1:10, x = 1:10 from Julia. It is troublesome that Julia would not conform to the standard set by the language that it's borrowing to fill its gaps.

kmactavish commented Aug 22, 2015

Julia recommends pyplot for plotting. Pyplot uses 0-based indexing by default, so plotting plot(1:10) gives you the line y = 1:10, x = 0:9. However, since the x-axis is supposed to just be the indices when left unspecified, you would expect y = 1:10, x = 1:10 from Julia. It is troublesome that Julia would not conform to the standard set by the language that it's borrowing to fill its gaps.

@johnmyleswhite

This comment has been minimized.

Show comment
Hide comment
@johnmyleswhite

johnmyleswhite Aug 22, 2015

Member

I'm locking this issue as there's no real possibility of this being changed.

Member

johnmyleswhite commented Aug 22, 2015

I'm locking this issue as there's no real possibility of this being changed.

@JuliaLang JuliaLang locked and limited conversation to collaborators Aug 22, 2015

@ihnorton

This comment has been minimized.

Show comment
Hide comment
@ihnorton
Member

ihnorton commented Aug 22, 2015

@simonster simonster changed the title from Why julia Array start with 1 not 0? to Why do Julia arrays use 1-based indexing? Aug 22, 2015

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.