Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
Lensflare2126716hHuh?
IIRC, that’s a short cut for (*p).member
So you can't just use the dot, it would try to access the member on the pointer directly.
It’s not like C# where you have value types and reference types. So you need to have something else than a dot.
But I agree, they should have come up with something that is just one character.
Maybe @, but that would probably look like shit, just like objective c -
BordedDev301216hFor the keys issue, it's also why I hate `:` in kotlin. I tolerate it in python and typescript since they are modifications of the original language, but it makes me ewwww whenever a lang tries to use it.
Probably for making the compiler impl easier? I'm pretty sure it's comes from the 90s a modern lang would probably simplify it indeed. -
donkulator53816hThey're very different operations though. If they used the same operator it would be confusing. -
Hazarth915315hGolang does that. When you're working with a pointer it dereferences via dot and if It's a value copy (which is the default behavior) it accesses the value member.
So It's definitely doable to use the dot for everything. I think the reason why C's approach might be better is that it's explicit.
Explicit is always better (as in, less error prone) than implicit, so I get it.
It's not a big issue in Go eitherway. -
Lensflare2126714h@BordedDev what’s your issue with : ?
Imo it’s much better than Java's "extends" keyword 😂 -
AlgoRythm5019712h@Hazarth I honestly feel like the ambiguity is caused by the fact that the c language separated them into two different operations in the first place! If c used the period for everything, then another language later on introduced the ->, we would think it is too verbose and dumb! They fundamentally do the same thing, just a dereference is in the air somewhere. -
afaIk10510hDe-referencing is noted with the * symbol, you use -> because you are working with the heap memory (dynamic alloc, objects must be destroyed explicitly etc...), dot symbol (.) is for stack memory (auto managed by the compiler), etc... -
@afaIk I don’t think that’s true.
You can have a pointer pointing at a value created on the stack and still use -> even though it’s not on the heap.
struct A { int foo };
A a;
A *p = &a;
p->foo;

Can anyone make a good case for the dereference-property operator being "->"
What the fuck, those keys are nowhere near where I rest my fingers while typing.
Not only that, but it's a sequence of two characters. For what reason!?!?!?
In fact, can anyone tell me what the reason is that we have a specific operator for this operation?! Why not just use the period for everything? If the left hand side is a pointer, the period can dereference and THEN resolve the scope. Otherwise, just resolve the scope to the property. Since resolving the scope on a pointer directly does nothing (IE, if you were to write "pointer.property" in current c/c++/etc), this means the operation is unambiguous and doesn't need to be two operators.
FUCK.
rant