this post was submitted on 12 Dec 2024
261 points (99.2% liked)

Programmer Humor

32733 readers
674 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 

top 21 comments
sorted by: hot top controversial new old
[–] SelfProgrammed@lemmy.today 40 points 2 weeks ago (6 children)

Here's a secret I wish someone told me in high school: literally everything is pass by value, it's just that sometimes the value is an address. It demystified pointers for me.

[–] MyNameIsRichard@lemmy.ml 17 points 2 weeks ago

Yeah, when I grokked that simple fact pointers became easy.

[–] ddplf@szmer.info 7 points 2 weeks ago* (last edited 2 weeks ago)

It's the opposite, everything is passed by reference but primitives are also addresses and therefore passed by value

You can't pass objects or functions as value

[–] asudox@discuss.tchncs.de 7 points 2 weeks ago (1 children)

That got me confused with rust references and why the dereference operator even exists as well.

[–] Ephera@lemmy.ml 3 points 2 weeks ago (1 children)

I mean, Rust has the additional thing that a reference is a pointer + a borrow, so it's not quite as similar to a pass-by-value.

And as for the dereference operator, occasionally you can use it to turn a reference into an owned value, often by making a copy of the value (but in that case, you can usually also use .to_owned()).

A case where I don't think there's an alternative to the dereference operator, is if you've got a mutable reference and you want to replace the value that's underneath: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=04621490e1d0fd6fe1af7f2e843547fb
At the very least, if you remove the asterisk, the compiler will tell you very precisely that you need to add it back.

[–] asudox@discuss.tchncs.de 1 points 2 weeks ago

yeah. references aren't the same as pointers in c++ but similar, so it's something along those lines.

[–] underisk@lemmy.ml 5 points 2 weeks ago

They taught you about pointers in high school? The only course available to me that even touched on programming just covered how to use C to do conditionals, read keyboard input, and print text to a terminal. The bulk of the course was learning MS Office.

[–] propter_hog@hexbear.net 3 points 2 weeks ago

That's true in Java, not necessarily in other languages

[–] Swedneck@discuss.tchncs.de 1 points 1 week ago

pointers are just symlinks in programming

[–] SnotFlickerman@lemmy.blahaj.zone 17 points 2 weeks ago

Thanks for the pointers.

[–] TimeSquirrel@kbin.melroy.org 15 points 2 weeks ago (1 children)

Lemme tell you something, DO NOT learn BASIC as your first language. As a hobbyist, I avoided C/C++ for 25 years because I just didn't get pointers and memory manipulation, and messed around with other languages like JS and PHP instead (also BASIC's GOTO and GOSUB kinda ruined me as a programmer for a few years). But once it finally clicked a couple years ago, I now want to write EVERYTHING in C/C++.

I think plain C at least should be everybody's first language. It literally reprograms your brain to think exactly like how a computer internally functions. I never got that with other languages, because they were so far removed from the actual machine.

Edit: also, after learning some of it, it's pretty neat when you do stuff like look at parts of the Linux kernel source code and think "wow, I know what's actually happening here now!".

[–] yogthos@lemmy.ml 6 points 2 weeks ago

I actually think that everybody should learn a functional language like Scheme first because it teaches you to think about state explicitly. It's very easy for somebody who learned a functional language to pick up an imperative one, but it's very hard for people to go the other way around.

[–] Mihies@programming.dev 12 points 2 weeks ago (1 children)
[–] Tolookah@discuss.tchncs.de 12 points 2 weeks ago (1 children)

She reads memory all the time

[–] alphacyberranger@sh.itjust.works 4 points 2 weeks ago* (last edited 2 weeks ago)

Lmao good one

[–] PowerCrazy@lemmy.ml 10 points 2 weeks ago (1 children)

I "understood" on a basic level what pointers were when i was first learning programing as a 12-13year old. But I never understood HOW to use them, or manipulate them, or what functions you use to interact with them, or how to examine them, or how to declare them, etc etc. And since I was young I never got the opportunity to take an actual programming class that taught any of that throughout high school. By the time I got to college I went with Electrical Engineering instead of computer science and so my journey with pointers ended.

Now I do python and never have to think about pointers.

[–] geneva_convenience@lemmy.ml 2 points 1 week ago (1 children)

Every Python variable is a pointer

[–] PowerCrazy@lemmy.ml 2 points 1 week ago

Sounds like the perfect evolution of pointers then.

[–] red@lemmy.zip 6 points 1 week ago

as someone who learnt assembly before any low level programming language understanding pointer's was never a problem for me,

[–] KingThrillgore@lemmy.ml 6 points 2 weeks ago

at last I finally see

[–] veroxii@aussie.zone 6 points 2 weeks ago

I'm a little disappointed peanuts weren't worked into this somehow.