>bro fetch me first (1.) and fifth (5.) element from array
arr[0], arr[4]
wtf they were thinking? It's unintuitive.
Only Lua got this right.
>bro fetch me first (1.) and fifth (5.) element from array
arr[0], arr[4]
wtf they were thinking? It's unintuitive.
Only Lua got this right.
>It's unintuitive
only if you're a newfag who can't into pointers
It is intuitive. Number systems start from zero so it is easier to do math operations this way.
Matlab is a good example why you shouldnt start indexing arrays from 1.
seething zerofags wishing they weren't stuck in the numbers-start-from-zero hegemony
tell me, if it's done for efficiency reasons, why can't arrays just be shifted one down at compile time
why would you?
on the contrary, I went in to calculus and was surprised at the number of times in sigma notation etc I had to use "minus 1".
For everyone who complains that CS majors need so much math, this is why: so they don't post stupid shit like this
t. doesn't understand pointers
> cpu counter starts at 0x00000000
> ends at 0x00000004
> 5 addresses
However as op wants it to work
> cpu counter at 0x00000000
> increments to 0x00000001
> then cycles to 0x00000005
Literal waste of clock cycles
>c majors need so much math
i never understood this once honestly. what kind of maths are cs majors studying in the states that makes them complain this much?
here's what we study where i live
>algebra, probability/statistics
gonna need that for data analytics
>graph theory, optimisation
gonna need that for artificial intelligence
>logic
gonna need that for formal algo proofs and AI and so much more
>calculus/analysis , numerical analysis
okay maybe this one's overkill for csfag needs, as most of the calculus you'd need for complexity theory is covered in high school. but still i don't think it's that bad that i'd complain about it, and analysis is pretty cool anyway so there's that
I'm not OP, but thanks for explaining an actual useful information to as why it's done the way it's done.
Basic addition and subtraction is difficult for burgers.
You don't understand the benefits of starting from zero in memory addreses and you will always remain a darkskinned programmer.
>all right all I gotta do is fetch the first and fifth element...
>oh, right, it counts from zero
it just takes an extra mental step.
>i never understood
It's obvious.
Because if you understood anything you'd realise that all of the sciences around computers, biology, chemistry, physics, engineering, require strong knowledge of mathematics.
It's ok. If you can't be a computer scientist, you can always remain a programmer.
except that you can do the incrementing at compile time
Anybody that indexes from 1 should be unceremoniously shot and left in a shallow ditch.
then you'd be loading an immediate which is even slower.
in matlab array index start from 1 by not wasting a cycle or a register but by syntactically sugaring the high level language
no one's this retarded
OP is such a failure that he cannot even into FORTRAN
Proper arrays start at 0
It's just how they work. Anything other than that is bad syntax or a shit implementation.
It really makes understanding the code when you don't stay consistent.
What if you start at 5 and not 0? Why not 762?
Makes it hard to understand*
I had a stroke writing that one out
it's an offset
that's the easiest way to explain it
lua pisses me off a bit, but it doesn't really end up as a problem
matplot's main user base was intended to be data scientists, statisticians and people with non CS background. For them counting starts with 1 not 5 or 762
>Proper arrays start at 0
>Proper
??
> non CS background
My point
Because 0 and 4 are the first and fifth number, you dolt.
Unless you are writting C, arrays on your favourite language have so much cruft in then that 0 vs 1 doesn't make difference.
Specially because, you know, it's not 1970 anymore, having compillers capable converting arbitrary starting address to memory offset at compile time is not only posible, but cheap.
>Only Lua got this right.
R also got it right. It's the shit, I love indexing the first element with 1.
Fortran has 1 based indexing since 1950.
Also matlab, octave, julia, etc
>he doesn't use [-n,+n] arrays with periodic indexes
Not him, but what are the advantages?
>numbers start from zero
Which ones? Naturals start from 1, integers, rationals and reals "start" from -INF.
OP is right, we've all just gotten used to this and accept it, but it is unintuitive that indexes are nth-1.
Well memory starts at 0, so you'd have one byte unaddressable and one addressable byte which would give a segfault. Of course this is solvable by -1'ing your index at compile or execution time, but he's pretending not to know that.
Because if you index from 0, then the index tells you exactly the number of preceding elements.
>but thanks for explaining an actual useful information
Streetshitters need to be rangebanned from 4channel
And?
Naturals start from 0 you absolute fucking pleb
>he doesnt understand pointers
*(a+i) = a[i]
Naturals start from where the fuck you want retard.
Originally it was at 1 (see Peano's original paper for example), but set theorists and logicians like to have them start at 0 (e.g. see Von Neumann's construction of the ordinals).
There is no standard nor is there a right definition.
>pointers
movl %edx(%esx,%ebx,4), %eax
Try memory addressing brainlet
For a location which may vary, it'd have to always get modified. So you'd always have to do subtraction and that's unnecessary overhead
>pajeet doesn't understand that array[n+1] and array[0+1] are basically the same thing
Binary is zero and one. It makes the most sense for the first number in any computer language to be zero. The idea that zero is the first index is not something I ever even considered as confusing or unintuitive.
It also makes it way easier when programming loops.
Consider:
Array X contains 9 elements,
For ( n=0 ; n < x.length ; n++ )
for(auto it = arr.begin() ; it != arr.end() ; it++)
yeah I love writing arr.length-1 everywhere because of zerofags
Do a simple differential equation with Octave (dx/dt=sin(t),x(0)=0). Code looks horrible as the vectors start with one
t=linspace(0,10,1000);
x=zeros(1,1000);
x(1)=0;
for i=1:1000-1
x(i+1)=x(i)+(1/100)*sin(t(i));
endfor
plot(t,x);
Looks a lot like actual math notation, what is the whole point of matlab/octave. Not seeing the problem here.
Because you're an idiot who has no idea how computers, compilers, or programming languages work. That would be a HORRIBLE idea.
What's wrong with people.
But I have to write "x(1)=0" into code. The original statement was x(0)=0
>itt: people who think it isn't trivial for the compiler to adjust from where the he you want to start your indexing
location[offset]
Visual basic does that too. It fucking sucks. I always have to add +1s and -1s fucking everywhere
One-based indexing scales horribly to cases where you need to perform non-trivial index arithmetic. This is true even outside of programming. One-based subscripting often gets in the way beyond high school level math.
You can always have the worst of both worlds and do numerical analysis, the field where people often mix 1 and 0 based indexing in the same pseudocode
ehh broo
arr[0, 4];
whats hard about that, system.out it or println whatever. Makes perfect sense to start at 0, as it is still an integer value it would be inefficient to have a 0 not be used in an array, when in machine language its easier to create.
thats not the logic for why we use zero though, binary is much more then just zero and ones.
0 is easier code base to create and access and represent from console lines then it is to create 0 index and change the representation at higher levels to 1. So it makes more sense to whoever is coding at assembly or machine level, to higher up or if someone in a 3G language wants to look into machine level. Less resources also wasted in creating representation. This is why we do assembly.
Ok, thanks man.
>seething CS newfag
Don't worry, you'll still get your diploma.
One based indexing just uses an abstraction to start from the zeroth index anyway.
Pascal let's you choose your adventure, start at 0, 1, 54, or -234 (whatever) as needed. Example:
mux: array [-5..5] of real;
Let's start binary at 1
arrays can be arbitrarily indexed at compile time. its just that arrays on the cpu are zero-indexed.
Yeah sure, waste performance on inefficient iterators.