this post was submitted on 03 Aug 2023
973 points (97.1% liked)
Programmer Humor
32710 readers
91 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
I'm not a programmer but I took a class in JavaScript. Unless I'm misunderstanding what you mean by reference, I don't recall that feature of the language. Can you explain?
A language reference (a manual). It’s not a language feature.
What I think he meant is that in JS every object is a reference or a pointer. This means that instead of the variable be the place in memory where the data is, the variable holds the address of where the data lives. This helps languages like JS and Python have variables that changes their types (you can assign a=true and later a=3 and everything will be fine). A non reference variable, as you can find in languages like C and Rust, is defined by its memory size statically, and the program can just pre-allocate a continuous block of memory that is enough for all the needed variables. This helps your cpu cache and access variables more efficiently. In reference types, memory can end up anywhere on your memory because it is allocated dynamically at runtime, so you access whatever memory that is free and available at the moment. Also the extra step of following a pointer just to get to a block containing a boolean (literally just one bit of memory) compounds and adds up to be actually noticeable in long calculations.