I think a lot about how Battlefield 1's menus were written in JavaScript so they could have their web developers build a videogame UI

The actually used React to make a game UI. Why.

The PS4 doesn't allow just-in-time compilation so you don't get the performance a modern javascript engine normally guarantees so on what planet is this a good idea

@wallhackio The JavaScript Planet, a dystopian world where JavaScript is the only programming language ever invented

@wallhackio How do I deallocate memory / destroy an object in JavaScript? So that I can delete this?

@wallhackio Nooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo :blobcat_notlikethis:

And in standard JavaScript? No NPM?

@wallhackio But can you do any memory management in JavaScript?

@aescling @vaporeon_

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

@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? :psyduck:

@wallhackio @aescling I did! I have a lot of trouble with the concept of references that are not pointers, but as far as I understood, it's just telling the compiler a different name for the same variable? Sort of like EQUIVALENCE in FORTRAN?

@vaporeon_ @aescling they do function as aliases to an existing object but they still pass by value when given to functions, so they can be used in any situation where a pointer can be used because C++ likes giving you multiple ways to solve every problem

@wallhackio @aescling Is there a meaningful performance difference? I could imagine that maybe the compiler could optimize more when using a reference, because pointers can point anywhere in the memory and references can't?

@vaporeon_ @aescling there's no optimization in using a reference over a pointer, it's a style thing

@wallhackio @aescling Really? I've been told that pointers are somewhat of a trouble for modern optimizing compilers because the user can always do some pointer arithmetics with them and there's no guarantee that they point at a valid value and that prevents some optimizations (I don't remember which ones)...

So references don't help with that?

@wallhackio @vaporeon_ yeah you don’t have pointer arithmetic at all in js. basically all implementations are using pointers under the hood and just not allowing the purrogrammer to manipulate the address they point to

@aescling @wallhackio I was asking about C++ 😅
Because Clodsire brought up that C++ has both pointers and references

@vaporeon_ @wallhackio

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);
}

@vaporeon_ @aescling yes. in C everything is passed by value between functions, so technically the pointer is copied from main to changeObj

but pointers are just numbers so the literal address in memory that pointer refers to doesn't change

@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

@aescling @wallhackio Or maybe my mental model of JavaScript etc. is just insufficient and I just need to read the correct documentation about it?

But honestly? In C, this is completely obvious, and in the JavaScript example, it is not unless you already have a mental model from C...

@vaporeon_ @wallhackio if you purrogram enough with pass-by-refurence languages you just get used to it :blobmeow_shrug:

@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 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

@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 :vaporeon: 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

@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

Show newer

@wallhackio @aescling Programming opinion: <iostream> is an abomination and should never have been created

Sign in to participate in the conversation
📟🐱 GlitchCat

A small, community‐oriented Mastodon‐compatible Fediverse (GlitchSoc) instance managed as a joint venture between the cat and KIBI families.