[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

>want to get first element in an array >array[0] >programmingfags

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 135
Thread images: 6

File: facebook_zuck.jpg (23KB, 384x384px) Image search: [Google]
facebook_zuck.jpg
23KB, 384x384px
>want to get first element in an array
>array[0]
>programmingfags will defend this
>>
it makes perfect sense for C arrays
>>
>>55683927
go back to lua pleb.
>>
>>55683956
This. Learn C and it will make sense.
>>
File: epoll_is_god.png (206KB, 1029x570px) Image search: [Google]
epoll_is_god.png
206KB, 1029x570px
>>55683965
Or use the lua[1] model and write C modules for it. Openresty has power boi.
>>
>>55683965
>be a normal human
>want to get the first element
>have to do the complicated mental arithmetic of adding 1
yeah I might go back to lua sempai
>>
>>55683927
of all the things to bitch about
>>
array+0
>>
>>55683927
Do you even know what the subscript "[ ]" does?
>>
>>55684212
pointers and shit sempai, I'm just wondering why I have to put up with this bullshit when the compiler or interpreter could take care of it instead.
>>
>>55684225

learn assembly
>>
>>55684029
>complicated mental arithmetic
I guess programming just isn't for you
>>
>>55683927
2^0
is why. any questions?
>>
>>55684262
yes
>>
>>55684274
like what dad. ask away.
>>
>>55684278
I'm not going to tell you what the question is, I'm just letting you know that I have one.
>>
>>55684291
i think you mean you have [0] question.
>>
>1 is the first ordinal
>this is what non-math-literate brainlets actually believe
>>
>>55684356
New Document 1
>>
>>55684393
>copy file 49 times
>50 files
>last one is called Document(49)
>mathematicians will defend this
>>
File: 1467932540613.gif (2MB, 250x320px) Image search: [Google]
1467932540613.gif
2MB, 250x320px
>>55683927
>want to make first post on 4chan
>PHHHBBBPHBPHV *PLOP* *SQUIRT* PHHHTTPHHTTssssssssss
>summerfags will defend this
>>
>>55684356
>this is what non-math-literate brainlets actually believe
this.
>>
0,1
1,2

Which is best?
>>
>>55684445
the 0th one.
>>
Pascal is baby tier language and uses 1-indexed arrays. So go use that
>>
nofap = high test = beard growth?
>>
>>55683927
>using numbers to index location
>there are 10 decimal numbers 0-9
>wants to start with second number
Why would you skip one number, are you retarded?
>Oh lets index this using letters, lets start with B
>>
>>55684625
except A is the FIRST letter in the alphabet, 0 is the 0th.
>>
>>55684539
actually in Pascal you can index from whatever you want, be it 0, 1, 555 or even 'a' or 'k'
>>
>>55684654
Nope. 0 is literally the first number. "0th" doesn't mean anything its like saying Ath
>>
>>55684654
0 is the 1st, 0 is a number.
>>
>>55684696
then explain why we count things starting at 1? wow it's almost like 0 is a number that shows there is no value or something.
>>
>>55684654
Wtf, mate? Then A has to be Ath character im alphabet, right?
>>
>>55684712
counting is adding 1 to the previous number, so technically you start at 0.
>>
>>55684764
Well said
>>
>>55684740
listen man I know counting is a complicated thing, but think REALLY hard for a moment. A is the FIRST letter of the alphabet. B is the second. when we get all the way to Z, that's the TWENTY SIXTH. now if I ask you how many letters are in the alphabet what do you say? THAT'S RIGHT ANON, THERE ARE 26! BECAUSE HUMANS COUNT NUMBERS STARTING AT 1!
>>
>>55684712
Zero is a value.
>>
>>55684805
I'm not denying that, but counting from 0 literally goes against all human logic.
>>
>>55684818
Refer to >>55684764
>>
>>55684712
Just give it up idiot.

0 is a number
0 or 1 index, are both the same just take it for granite or use a babby-tier 1-index language if you insist.
>>
>>55684784
Look ass hat, itso not about the logic, it's about using the most bang for your buck on a computer, back when computers were old and shitty. You map 0 because the Arabic numerals are 0-9 and it would be wasteful as fuck to only use 1-9. 10 adds an extra digit, aka more memory.

Why do you think hex was invented? So that we can use more info per digit. Learn some computer architecture before you start spewing utter bullshit. These gpu threads are cancerous enough without you spreading retard. At least I can understand the shills getting paid to shill, but you're just retarded.
>>
>>55684784
Ok so if you can't count 0 as a number, then what do you do when you have 10 things?
>oy, that ends in a 0, m8. Cant have that, its not a number! Must be 11 things there then.
What is this, ancient times where zero was avoided and feared?
>>
>>55683927
matlab is nice
>>
>>55684838
Hmm I wonder if you sperg out whenever you read 00:00 on a clock

Also, angle 0 == angle 360 in a circle. MIND BLOWN.
>>
>>55684856
>~=
>>
>>55684654
>>55684689
> when you typed 0th as a sarcastic joke to prove op's idiocy, op defends it and anon gets its.
> shit tier to the 0th
> grats to the 1st
>>
>>55684862
not you, I meant
>>55684842
>>55684712
>>
>>55684862
Why is this addressed to me? None of it is relevant to my post.
>>
>not 0[array]

Were you dropped on your head as a kid?
>>
>>55684879
apologies
>>55684877
>>
>>55684842
are you dumb?

>>55684838
so your response to me asking "if it's 2016 and we don't care about file size so why do we count from 0" is "because history"
That's not a valid reason sempai
>>
>>55683927
The worst part is that programmingfags will defend this for arrays whose type don't guarantee at least one item.

C will rape you for it, and even Haskell fucks it up.
>>
>>55683927
how should it be done anon?
>>
>>55684893
Clearly not as dumb as the one who can't even add or subract a 1 from his indecies every now and again. Pretty sad, fampie.
>>
>>55684893
>> because adding one is hard...
Is not a valid reason to change every programming language and thereby every program ever written to add one to every array, senpai.
>>
>>55684929
>>55684947
high level programming languages should take care of it when being compiled / interpreted. simple as that. it's all pointers and shit so 0 based makes sense for computers, but why not make it simpler when writing code?
>>
How else would you do it, faggot?
>>
>>55684893
>$CURRENT_YEAR
>we don't care about file size
Well-crafted; have a (You).
>>
>>55684966
It makes looping through the entire array simple as fuck though.
for (i=0; i < length; i++)
>>
>>55684862
>angle 0 == angle 360 in a circle.
Yeah, same with the time though. 0:00 is the same as 24:00, if that existed.
The idea is that you can use the modulo operation, so the angle modulo 360 would give you 0 if it's 360, 1 if 361, etc. Or if you say "Yeah I've been awake for 72 hours" that's exactly the same as saying "I've been awake for 0 hours" because 72 modulo 24 is 0.

>>55683927
When you go jogging, do you start counting at 1? No. You count 0.25 miles, 0.5 miles, ..., 1 mile, ..., 2 miles.
>>
>>55684966
Well, have fun building the compiler. Just make sure ithat can read 0 based arrays as a legacy setting. Otherwise big companies like IBM can't use it.
>>
>>55684999
nice low level language kid, that's not what I'm talking about.

>>55684972
literally look one post above yours.

>>55685007
fair point, but when humans count something they generally start at 1.

>>55684980
literally doesn't change file size if the compiler takes care of it
>>
>>55685007
Yeah i learned all of this in Grade 2

but started applying and getting in touch with it writing watchface apps for Android Wear
>>
>Java ODBC
>>
>>55683927
Array points to the start of the memory, and array[0] is an alias to array+0.
>>
>>55685007
but distance is a continuous system. you haven't ran until you've taken your first (1) step, but you can still have a nonempty list with element 0
>>
>>55684908
&array[0]

kek
>>
>>55684260
this
/thread
>>
>>55685035
I'M AWARE SEMPAI, THE COMPILER CAN JUST TAKE CARE OF IT.

>>55685037
was just about to say this, an empty list would have length of 0. a list with 1 element would have length of 1 so why would it be element 0?
>>
Starting from 0 or 1 is a religious question
>>
>>55685052
What do you mean? That the compiler should translate array[1] to array+1-1? That would be way to confusing.
>>
>>55685052
because *(array + 0)
>>
>>55683927
Array name is a reference to the memory location in which the first element of the array is stored. Array[0] means that exact memory location. Array[1] is the memory address of the array + space that an item of the array will take, meaning the address of the second item.
>>
>>55685052
http://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html
>>
>>55685023
>nice low level language kid, that's not what I'm talking about.
Oh ok, this is just a thread for script kiddies to complain then. Well, I'm out. Got more important things to do that babysit highschool level "coders."
>>
>>55684966

Because then it doesn't make sense when you actually want to do something the way it is being interpreted. Like if you were to access the actual memory, it wouldn't be what you wrote in.
>>
>>55685023
Write some code for me right now fuckface

You have an array, you need the first element only, not to loop over the whole thing or anything like that. What do you do?
>>
>>55685052
Then write the compiler fampai!! Or else stop bitching for someone to move mountains so that you can avoid a "problem" that is just your personal preference
>>
>>55684764
you start at 0. The first element that comes is one more from the empty state, 1.
>>
mfw some people will actually defend lua style array indexing when not even lua thinks its right anymore.
>>
>>55685075
do you know how complicated compilers are? it makes no difference.
>>55685090
is this a joke? do you mean with 0 based or 1 based? either way it's literally just array[0] or array[1]
>>
>>55684999
for(int i =1;i<=length;i++)

isnt that far off either
>>
>>55685110
Then what the fuck is the point of this thread? You fucking retard
>>
>>55685122
I'm wondering why you people are so autistic that you refuse to make a change that will do nothing but make programming easier.
>>
>>55685110
I'm not saying it would be complicated to the compiler, it would be complicated in my mind, because when programming, I am always imagining what is happening memory-wise.
Also, imagine you want to access the array and you want values that excede the array length to be wrapped around, in C, you just say array[ index % length ] while if it started in 1, you would have to do array[ (index - 1) % length + 1]
>>
>>55683927
sometimes it makes the mathematics easier, and i like that
>>
>>55685136
Please stop trolling. It's been explained why 0 is the correct number to start from in C and you're just ignoring it.
>>
>>55685143
finally someone has a proper argument, if you're thinking about it memory-wise then you probably use a low level language which isn't what I'm talking about. regarding the modulo thing idk desu, will have to think about that.

>>55685144
in what situations?
>>
>>55685136
It's because of who writes compilers. People don't write compilers for students, they write them for enterprise so they can make money. If IBM buys 100,000 copies of a compiler, then that company just made a million dollars. But compilers must support legacy ie. 0 based, because that is 100% of IBMs code. IBM isn't going to rewrite 1million lines of code just to use 1 based indexing later. Therefore no one will bother to write it.

But if you want to, go the fuck ahead and stop complaining.
>>
>>55685136
I've been writing code for years you wanna-be faggot

I'm still waiting for you to write code, go on you "genius"
>>
>>55685224
Quick, write a function that averages two integers.
>>
>>55685177
I think you should really make a table with all the situations in which it is easier to program with index 1, then index 0, then shove it up your ass. The only people who complain about this shit is people who are just learning programming and feel it's counter intuitive, YOU AREN'T BORN KNOWING EVERYThiNG, GET OVER IT.
>>
>>55685233
No, shut the fuck up

You made fun of doing array[0] like you can't believe people do this, so you better write me some code that's "better" right now or else shut your fucking mouth
>>
>>55685234
>>55685224
and the autists come out, like clockwork.
>>
>> ITT: freshman cs student vs. A lot of fish who can't resist the most obvious bait
>>
>>55685233
[CODE]
int average(int a, int b)
{
return ((long)a+b)/2;
}
[/CODE]
>>
File: csgrad.png (272KB, 3000x2584px) Image search: [Google]
csgrad.png
272KB, 3000x2584px
>>55685233
>averaging ints meme
Quick, takes yours.
>>
>>55685262
u fucked up hard son.
>>
>>55683967
As with 99% of common programming concepts. C is a tad more complex, but everything will make more sense if you know it.
>>
>>55685233
def average(a, b):
return int((a+b)/2)
>>
Or you could just do
hd(array)

or
[first | _] = array
>>
>>55685233
void averageints(int* a, int* b) {
*a = *a / 2 + *b / 2;
*b = *b / 2 + *a / 2;
}


Both integers are now averaged.
>>
Why are you complaining about 0-indexed arrays in HIGH LEVEL languages? If abstraction and readability is what you need, why are you using arrays?

You shouldn't be using arrays in a high level language for whatever silly shit you're doing. Most high level langauges have lists, queues, stacks, and other data structures as part of the standard library. Arrays are not lists, you're mistaken if you thought they ever were.

head xs, list.first(), and list.head(). This is what you want
>>
>>55685356
That is terrible for so many reasons.
>>
>>55685405
lists are the same as arrays in python, sempai.
>>
>>55685406
It does exactly what the guy asked. Don't blame me because he can't express himself properly.
>>
>>55685483
No it doesn't, because a will contain an average when you go to the second line...
At most you should do: *a = *b = *a / 2 + *b / 2;
And this is still retarded...
>>
>>55685508
No you are retarded.
>>
>>55685421
Actually they aren't, you're mistaken. Lists in python are a basic data structure, but they are not an array. Arrays aren't even a basic data structure in python

There's a seperate array module which should be used when you're working with lower level concepts like making your own networking lib.

Lists are not arrays and they never were
>>
>>55685519
Isn't the average of the two numbers the same? What is retarded about my correction?
>>
>>55683927
Why is it even a problem? What, you can't change your number system at will? Naturals can start with 0 or 1, there's nothing wrong with either.
>>
>>55684547
Nope

It just makes your existing fetishes stronger
>>
>>55683927
Ha ha, Tom.
>>
I've tried VBA once.
It uses '1' to refer to the first element.

End up writing "+1" a whole lot.
>>
>>55683927
Summer kid doesn't have enough math to know why arrays are indexed beginning at 0
kys
>>
>>55684416
1 original, and 49 copies
It must hurt to be that stupid
>>
>>55684740
summer
>>
Maybe because the first number is 0 not one??
>>
>>55685052
God forbid that you do some actual thinking and not just depend on the compiler/interpreter to do everything. Is this what pajeets are taught?
>>
File: kek.webm (58KB, 2048x1152px) Image search: [Google]
kek.webm
58KB, 2048x1152px
>>55683927
>doesn't just use a pointer
>>
https://www.cs.utexas.edu/users/EWD/transcriptions/EWD08xx/EWD831.html
>>
>>55685751
too many big words, summarise it using only words in the 100 most popular children's books please
>>
>>55683927
just do
for (var i = 0; i < array.length + 1; i++) {
array.pop();
}
var get = array.join('')
>>
>>55684712
You actually start counting from 0. You just don't say it.
Otherwise, you would not have a result if there was nothing to count.
>>
>>55687170
you start counting at 0.
As soon as there is one thing, you're at 1. There is no "0-th" thing.
>>
>>55687188
There is no 0th thing, but there are zero things if you never count to 1.
That's why you HAVE to implicitly start counting from 0.
>>
It saves at least one instruction, doesn't it?
If you want the nth byte of an array, you now only have to calculate startAdress + 5 to get its address.
With 1 based arrays, you'd have to subtract 1 as well. And if some other instructions later on want to access that same value, you'll have to either save it to a different register or even memory and reload it or add an inc somewhere.
This could only be optimized out for constant compile time values. But usually, if you have an array with constant values stored at certain indexes, you're better off just using a struct / class anyway.
>>
>>55683927
array.First();
>>
0 comes before 1
>>
File: unnamed.jpg (22KB, 315x468px) Image search: [Google]
unnamed.jpg
22KB, 315x468px
https://en.m.wikipedia.org/wiki/Radix

Educate yourself before you wreck yourself. Read pic related.
>>
>>55683927
>got 10 perfectly good digits
>retards want to throw one away because it's "counter-intuitive" AKA "i'm retarded"
>>
>array[0]
>Not *array
>>
ada lets you define the index bounds for your sequences.

I like the way it works, shame there arent may jobs out there for one writing ada.
>>
>>55690054
doesn't ada let you define pretty much everything?
>>
>>55685356
Erm... Have you actually tried this code?
                                                                                                                         it won't work dummy
Thread posts: 135
Thread images: 6


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.