@wallhackio The JavaScript Planet, a dystopian world where JavaScript is the only programming language ever invented
@vaporeon_ I love JavaScript, so delete this please
@vaporeon_ I love JavaScript, so delete this
please
@wallhackio How do I deallocate memory / destroy an object in JavaScript? So that I can delete this
?
@vaporeon_ npm install memory-management
@wallhackio Nooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
And in standard JavaScript? No NPM?
@vaporeon_ it was a joke lmao
@wallhackio But can you do any memory management in JavaScript?
const deleteThis = () => {
const temp = { _this: this };
delete temp._this;
};
@aescling @vaporeon_ this will NOT do what it's being promised to do, this is a joke
@wallhackio @aescling What will it do?
@vaporeon_ @aescling it will create an object with a single property named _this
that has the value of whatever this
was where the arrow function was declared
and then it will delete that property from the object
@wallhackio @aescling So creating the object initializes _this
with a copy of the value of this
, and only that copy gets deleted?
@vaporeon_ @aescling yessir
@wallhackio @vaporeon_ not a copy but a refurence
@wallhackio @vaporeon_ what gets deleted is the refurence
@aescling @wallhackio Is a reference the JavaScript version of a pointer?
@vaporeon_ @wallhackio yeah basically
const o = { k: 1 };
function changeObj(o) {
o.k = 2
};
changeObj(o);
console.log(o); // { k: 2 }
@aescling @wallhackio LOL, is that because the pointer is a constant, but the contents of the object are not? In C terms, what happens here is this, right?
changeObj(struct object *o) {
o->k = 2;
}
main() {
const struct object *o = new_object(1);
changeObj(o);
printf("k: %d\n", o->k);
}
@aescling @wallhackio There are two types of languages: those that have explicit pointers and those that hide the concept of a pointer from the user and therefore become very confusing
@vaporeon_ @aescling C++ actually implicitly converts objects to references if the function is declared to take reference arguments
#include <iostream>
class T {};
void use_T(T& t) { std::cout << "I used a T!\n"; }
int main() {
T t;
use_T(t);
}
@vaporeon_ @aescling this is why they were introduced into the language actually
@vaporeon_ @aescling so that operator overloading would Work
@wallhackio @aescling Why does operator overloading need references?
@vaporeon_ @aescling using operators in C++ is sugar for a function call, where whatever is given to the operands is provided to the function that represents the operation
of course Bjarne could have decided that pointers of these operands would be provided to the function representing the operations, but that would be too simple. so instead, he added references, and also ruined the language forever
@vaporeon_ @aescling I don't like that they don't add anything new, and simply give you a second way to do something the language could already do
I think it is very Bad for languages to do that sort of thing
@aescling @vaporeon_ From what i've seen I would really like Go
@wallhackio @aescling It's funny how I have 1 comrade on here who really likes Go and another one who really doesn't like Go
@wallhackio @aescling is neutral about Go, they've never seen it nor programmed it
@wallhackio @aescling Want to try convincing Vaporeon about Go? Show me some cool code samples
@wallhackio @aescling Is there anything that it does better than C?
@vaporeon_ @wallhackio the type system is more expurressive and notably suppurrts a natural way of expurressing duck typing (i do think some type expurressions look kinda bad to read though)
compilation is quite fast (dealing with very slow C++ compile times was one of the major motivators fur creating the language)
concurrency is a furst class feature and apparently fairly intuitive to work with
@aescling @wallhackio "Duck typing"?
@vaporeon_ @wallhackio typing based on structure rather than inheritance—“if it has these methods with the purropurr type signatures, then it is one of these”
go calls this a “protocol”. it’s kind of like java interfaces but without ever having to explicitly declare that you are implementing one
@vaporeon_ @wallhackio the name comes from the phrase “if it looks like a duck, walks like a duck, and talks like a duck, it’s a duck”
@vaporeon_ @wallhackio as fur things Go is worse at than C: it is garbage collected lol
@vaporeon_ @aescling tell me who hates Go so I can report them
@wallhackio @vaporeon_ you would purrobably like go if you think like that