Pointers were a mistake

Pointers were a mistake.

Attached: tony_hoare.jpg (600x600, 41K)

Other urls found in this thread:

doc.rust-lang.org/stable/std/option/index.html
twitter.com/SFWRedditImages

How else would computers work

>Pointers were a mistake
Said no one ever
Pointers are the greatest idea

boomers were a mistake

Pointers are great for not having to make everything into a boilerplate object with getters and setters

you don't need pointers to pass things by reference

void myfunction(myClass &myObject
is *much* better than
void myfunction(myClass *myObject

What do you think passing by reference does retard

op is a mistake

>is *much* better than
You need to argue _WHY_ you feel that way.
A reference is just a pointer, and there is a guarantee that it is not null.

then who was memeory

How tf do you expect me to set arbitrary memory safely.

References are really pointers though
Just like Java works with pointers although it has not C like pointer syntax in the code (new actually always returns a pointer)

Pointers are much more basic than any language

what do you prefer to read through?

vector decryptAES(vector &ciphertext, array &key, array &iv) {
mbedtls_aes_context curctx;
mbedtls_aes_init(&curctx);
mbedtls_aes_setkey_enc(&curctx, &key[0], 128);
vector output(ciphertext.size());
mbedtls_aes_crypt_cbc(&curctx, MBEDTLS_AES_DECRYPT, ciphertext.size(), &iv[0], &ciphertext[0], &output[0]);
return output;
}

or
vector decryptAES(vector *ciphertext, array *key, array *iv) {
mbedtls_aes_context curctx;
mbedtls_aes_init(&curctx);
mbedtls_aes_setkey_enc(&curctx, &(*key)[0], 128);
vector output(ciphertext->size());
mbedtls_aes_crypt_cbc(&curctx, MBEDTLS_AES_DECRYPT, ciphertext->size(), &(*iv)[0], &(*ciphertext)[0], &(*output)[0]);
return output;
}

Or in Fortran:
subroutine Sub(addThis, toThis)
integer, intent(in) :: addThis
integer, intent(inout) :: toThis

toThis = toThis + addThis
end subroutine

Does anyone actually use getters and setters?

When the language builds them in, yes.

It's still a pointer, don't embarrass yourself

that's like saying a char and an int are both numbers so you shouldn't bother finding out the differences between them

Pointers are a basic abstraction of the underlying hardware. Hell, you essentially use pointers even in assembly, you just don't call them pointers.

std::array is stupid, if you had used a normal array, you could just say &ptr[0] instead of this &(*ptr)[0] madness.
Alternatively you could say &ptr->operator[](0)
Besides your example uses pointers when something clearly isn't null, which is retarded. I generally prefer pointers because when you see func(arg);, you can't easily tell whether it is pased by copy or reference.

>I generally prefer pointers because you can't easily tell whether it is pased by copy or reference
>i like it when i can't tell when something is passed by reference or by value
are you retarded or what

No, but you may be. Learn to read

Does func(arg) invoke a copy constructor or is it pased by refernce? You cannot tell. func(&arg) obviously does not invoke any copy constructor

> You don't need pointers to pass things by reference
> Post two examples of passing a pointer to a function
Have you ever coded in C before?

oh no

Attached: Capture.png (1239x457, 501K)

OOP oriented people do it everywhere. Considered 'good practice'.

>Playing with a microcontroller earlier
>Scrolling text on a 32 char display
>Fuck up a bounds check
>Screen starts winging through mem at 32char/s
>Most of it is gibberish that the display can't handle
>See some strings baked in from elsewhere in my firmware
>Doesn't fucking just crash like a bitch

Suggest an alternative then. References are still pointers.

Every time you need some action performed on getting or setting. And because eventually you WILL want to do that it's considered a good practice to define them in advance to avoid rewriting the code that's using your class later.

This kind of thinking is making the use of pc, to need minimum 8/12/16 GB of ram.

And what's wrong with that?

10 million years later, only one language understands how to do it right

doc.rust-lang.org/stable/std/option/index.html

Hoar never said such a thing, stupid. He said that __null__ pointer were a mistake.

In assembly, you are dealing with addresses.

Software engineering literate people.

If it's obvious that it's an array then passing arg is fine, otherwise pass &arg[0].

One of the main issues with pointers is not the difficulty, but the difficulty in optimizing.

Pointers make data analysis a lot harder for the compiler, a lot of what they can do relies on the strict aliasing rules of C and C++, that you can only access an object by its type's pointer, a char pointer, or a pointer to some aggregate/array type containing this type.

Why does this matter? In simple terms one of the main thing a compiler needs to do is take expressions that would be inefficient to literally execute and instead cache intermediate values that get shared. For example if you are iterating over a large array and you refer to myArray[i].name which is some pointer, the literal execution of this would be to load the address myArray from the stack, add (i * sizeof *myArray) to it, add offsetof(name, T) to it, and then load from that address.

If you refer to the same name (myArray[i].name) multiple times then can't you just remember the address of it? Well what if myArray changes? What if myArray[i].name changes? What if you cache its contents and that changes as well? Simple data analysis would protect us but the reality is that if we ever pass a pointer of any of these things to another function we lose all information about whether they get changed on execution of any external function, or the use of any local pointer which may have been aliased to it.

So pointers hurt optimization, which I'm sure is counter-intuitive to new C programmers.

why would you use private and public if you don't use getters and setters?

What’s even the point of pointers? I’m new to C and still don’t know what purpose they really serve
>no pun intended

If you used scanf you used pointers.

I scanf do anyfing I fwant.

heh
said the typical programming newbie

References are usually *implemented* as pointers, but they provide a different, clearer abstraction.
Instead of reasoning like "passing the address of object x to function f", and then have f dereference every time like a nigger, when using references you can see it as "i'm passing x itself, not copying it, to function f", and then have f operate on x directly. That's the advantage. Pointers themselves are an abstraction provided by C, since addresses are numerical values too.

Getters and setters make sense if you need to perform some logic when modifying a value in an object (for example, you have an object representing a square, and when changing its height, you should also change its width).
However, if you're not doing anything else, I don't really see the point. Despite what Uncle Martin's personal army would say, it's ok to make them public.

I lost 10 IQ points after reading this.

kek

this is just like saying "the alphabet was a mistake" because you don't like algebra

Attached: 1536364343655.gif (480x270, 1.76M)

Except char and int are different sizes, whereas pointers and pass by reference are literally the exact same thing

Pointers is the only benefit of a random access machine