Bad design

>first array index is 0

Attached: 1559258019651.png (680x680, 221K)

Other urls found in this thread:

doom.fandom.com/wiki/AASTINKY
twitter.com/SFWRedditGifs

>can't go negative index in an array

Attached: chuks-fuck-n-suck.png (612x408, 132K)

You can in C.

char x[10];
char* y = x;

printf("%d\n", sizeof(x)); // 10
printf("%d\n", sizeof(y)); // 4

>size of different types is different
holy niggers, how can this happen?
>>can't go negative index in an array
you can, in perl. how is a negative index going to help you?
>>first array index is 0
that's the best design,
>array is allocated in address 0xFF00
>first element starts in 0xFF00
or
>first element starts in 0xFF08 if it's an 8 bytes int
>first element starts in 0xFF04 for short
>first element starts in 0xFF01 if it's a char
or
>first element starts at 0xFF00, but the compiler replaces all your indeces with (i-1)
it seems to me that this is a dumb-faggot thread.

>holy niggers, how can this happen?
That happens when people don't realize that different things are different. It sounds obvious, but it ain't for most people

Weak typing
Dynamic typing

It's the only starting index that makes sense unless you're a dumb nigger.
You can, it's just pointless.
>different things have different sizes
Wow, what a horrible design.

That's not bad design, your code is bad design. Don't fucking alias pointers unless you absolutely need to, mongoloid. For all the screaming rust retards do about memory safety, all of rust's safety features basically exist to stop you doing exactly what you just did and for good reason.

Anyways:

y is a pointer at compile time, but x is not a pointer until after compilation has completed. C(++) requires an understanding of how computers store data. sizeof() is not actually a function, but a preprocessing operator that is replaced with static numbers during compilation. Most C compilers do not look at arrays the same as they do pointers. Arrays are (almost always) allocated in the stack segment of memory. Pointers are (in best practice) used exclusively to point to memory in the heap segment.

It's offset, not index.
The first element has 0 offset, because it's the first.
3rd element is offset by 2 to the first element.

Having an array size be a part of type is terrible design.

Interrupts

>array

browser chooses to interpret javascript

list[-1] is valid in python, it will point to the last item

This is unironically one of the best things about python

isn't it list[:-1]?

I am dumb dumb, sorry.
>>> a = [1, 2, 3]
>>> a[-1]
3
>>> a[:-1]
[1, 2]

No, that returns the array minus the last index.

The colon is python's slice operator.

>what is pascal
type a = array[-10..10] of integer;

Anyone who cannot understand why this is desirable shouldn't be let near a computer.

fun fact when making DOOM they had to put a placeholder texture in 0 so everything would line up properly. so there is a texture called AA_STINKY

Why

arrays arent pointers

Doom textures are generated at runtime by blitting together patches.

Probably Romero, considering he's shilled for Lua recently. I can definitely see him as the kind of person to think arrays starting at 1 is a good idea.

doom.fandom.com/wiki/AASTINKY

>Internally, Doom refers to textures by their index in the texture directory. A value of zero is used to represent the empty '-' texture. However, in C, which Doom is written in, array indices start from zero. The result is that the first texture in the WAD directory is equivalent to the empty texture.

I didn't say otherwise.
Arrays, adjustable vectors, matrices, images etc should also start at 0.

offsets should start at 0, indices should start at 1
the only valid argument towards that end is that it's less instructions to deference starting at 0, but typically in assembly these days adding to the offset can be part of the same instruction

How about when arrays automatically decay to pointers as function arguments? That is a completely obvious design flaw. C's safety is built on assumptions of competence and blind promises. Rust safety is built into the compiler.

0 is just easier because it is a lower number than 1.
There is no difference in difficulty for the reader to process whether to start at 0 or 1, that shit is learned when you start to use a computer. Maybe someone at some point spent 10 seconds and then finally accepted it, but I doubt this is more than a story at this point.
There are calculator languages where it starts at 1 if you prefer that stuff and you can make your own tool for c++ if you really need this, but put a huge fucking sign everywhere in case real humans look at this shit.

How do you write for loops?

So Rust is built for incompetent people?

Attached: 50210694_2388282321204695_4593206801432566617_n.jpg (828x828, 67K)

>0 is just easier because it is a lower number than 1.
what?
you know what else is lower than 1, -4906367, why don't we start there?

Writing in C doesn't make you competent, it makes you volatile. Only egomaniacs don't trust machines. Scared SJW software will prove you wrong?

The C lie is that a sufficiently advanced programmer will be able to write correct and fast software.
The lisp lie on the other hand is that a sufficiently advanced compiler can build correct and fast software.
It's obvious to every person with a brain that both are fundamentally not achievable, but it should also be obvious which option can be developed further.

In other words, your mad programming skills will not outlive you while a single compiler is capable of being continuously perfected for many centuries and can handle the entire world's programming needs without ever needing to be trained or needing rest.

>Only egomaniacs don't trust machines
This is why modern software is so bloated and full of bugs.

Attached: 1529261033107_.gif (500x357, 639K)

Negative numbers are larger than 0 when you look at how they are represented, but I get that you were just being retarded because you think it is funny.

There is no usage difference between starting at 0 or 1, nobody is so incompetent they can't use either. So because it is easier to implement, it makes sense to stick with 0.

Yep.
>I know better...
>Bah, the compiler's bugged...
>I'll do it iteratively for more performance...
>I don't need that library, I'll do it myself...

No, you are being retarded by saying 0 is "easier" than 1. That makes absolutely no sense from any angle. People start counting at 1. Indices start at 1 (except in this case). There's no reason why they shouldn't be this way on computers too. It's not "easier" to implement. It just exists this way now because of convention

0 is the first natural number

and 1 is the first number we use to index things
you dont say "hey, can you grab me the zeroth book on that shelf"
you say the first

>People start counting at 1.
computers don't.
Nobody cares what makes sense from your angle, it makes sense for everyone else.
Try implementing it both ways yourself.

Of course I do. But you don't tell the computer "Give me the zeroth element", you say "Give me the element zero distance from the beginning"

Computers 'count' the same way humans do. Like I already said, offsets start at 0 for computers and humans. It makes sense for a pointer, because a pointer is an offset. Arrays are not pointers, and use an index

>first array index is 0
Why is that a bad design? It's the first integer number there is. And in C it literally reads pointer to array plus offset of 0, so putting 1 there would be wrong.

But if you like 1 as first index so much, go pay for a Matlab licence, you tard.

>It makes sense for a pointer, because a pointer is an offset.
Why aren't pointers starting at 1?
None of this stuff actually matters. The C array is a pointer, it makes sense they behave the same way.

The only advantage starting at 1 is ending at size.
But all I am saying is that
for(int i = 0; i < size; i++)

is easier than
for(int i = 1; i

>Why aren't pointers starting at 1?
because they are offsets
C array is a pointer, but C arrays are shit and other languages dont work that way anymore
0-based indexing requires you to litter your code with Length-1 all over the place

>Women in charge of understanding easy concepts
Just do something else, like painting or cleaning the house or something

Attached: 1361373025412.jpg (400x417, 107K)

not to forget, mutable typing and non-enforced variable declarations

Arrays in C(++) are sequential bytes allocated on the stack. When a function is finished running, the stack is deallocated, including the array. Accessing it will probably segfault.

If you are calling a function inside of the function and pass an array as an argument, congratulations, you're engaging in worst-practices. Don't. Fucking. Do. That. Moron.

If you need a sequential series of bytes to pass between scopes, use malloc() or new to allocate it on the heap. Arguments can only be values, because all concurrent stacks have to be exclusive ranges of memory. When you pass a pointer to an address allocated another stack, you're basically passing an integer that represents a memory address which is NOT within the scope of the current stack. Do NOT fucking alias pointers that point to another stack. The heap exists for a reason. Fucking use it.

It's not a design flaw at all. You just don't understand how computers work and you don't know how to write safe code. Go write ASM to learn about low-level state/memory management, because you clearly need it.

Attached: 1555055984174.jpg (5000x5000, 1.79M)

>0-based indexing requires you to litter your code with Length-1 all over the place
You should try to learn programming before coming with statements like this.

huh?
if you want to access the last element it's
array[length-1]

>anything you or another faggot from here comes up with

C's major design flaw:
No operator overloading.

And they'll never add it for absolutely 0 fucking reason.

Sure. But it is not something you do all the time, so it isbn't likely to litter your code all that much.

If you need to access it that many times, fucking cache it.

Yes I do access the last element of arrays all the time, and you're telling me to learn programming? Are you a webdev or something?

Are you an idiot?

>0-based indexing requires you to litter your code with Length-1 all over the place
I never said that you absolute retard. Are you sure you are old enough to be here?

Said the retard who's too damn stupid to type
endIndex = length - 1


Meanwhile the far more common task of for loops is made a hell of a lot cleaner by not requiring an extra equivalence operator every time you want to iterate over the array.

seething rust brainlet

Cneed

>Meanwhile the far more common task of for loops is made a hell of a lot cleaner by not requiring an extra equivalence operator every time you want to iterate over the array.
for i = 1 to length
stop embarrassing yourself
and yeah I really want to assign a new variable every time I want to index something, that's even worse

#define REVERSEINDEX(a, i) a[length - (i + 1)];
#define ENDINDEX(a) REVERSEINDEX(a, 0);
// or with overloading, negative indexing starting at 1
template
class Array {

private:
T *buffer;
int length;

public:
int getLength() { return length; }
int operator[] (int x) {
if ( x < 0 ) return buffer[length - x];
return buffer[x];
}

template
Array::Array (size, ptr) {
buffer = new T[size];
length = size;
}

Array a(5);
for (int i = 0; i < a.getLength; ++i) {
a[i] = i;
}


Then a[-1] = 4
Not that hard, numbnuts.

This is ugly as fuck, at that point why use an equals sign and not just
for i set as 1, to length

>For all the screaming rust retards do about memory safety, all of rust's safety features basically exist to stop you doing exactly what you just did and for good reason.
Wut. You should be able to do the same thing in rust, except that Rust's sizeof is just a generic function and returns size in bytes. If you compare size of u8 slice and raw pointers they will have same sizes as in C.

Please actually study why Rust's compiler complains about the things that it does.

>Spreadsheet
>data starts at row "2"

Array decay was a mistake.

>t. never used pointer arithmetic in C

That's not array decay, moron.

>0-based indexing requires you to litter your code with Length-1 all over the place

Have you ever programmed in VBA?
It uses 1-based indexing and it's far, far worse.
You end up having to do "+1" or "-1" in nearly every row of code.
Never again.

the syntax is irrelevant, the point is for loops do not require 0 based indexing, you can just switch the continue condition with an exit condition, or whatever

not equivalent

Array decay takes place on this line.
char* y = x;
The conflation of pointers with arrays on the whole is just awful and it leads to many people having deep misconceptions about how C works.

I don't understand what you mean. Complain about what?
You can create slice in Rust and you can get raw pointer to it. You can use sizeof to get size of the slice and size of the pointer.

>I do access the last element of arrays all the time
I don't do many things over and over again, but even if this is the case in your specific scenario, you can get around it. It isn't necessary to do all the time. It is much more frequent I access all elements than one.

Formerly Assembly