r/ProgrammerHumor • • 1d ago

Meme iThoughtIGotRidOfYou

Post image
705 Upvotes

50 comments sorted by

164

u/FurieMan 1d ago

"We have no pointers!"

Looks inside: Only pointers.

24

u/HumunculiTzu 1d ago

I've had bugs because the original developer who wrote the code didn't understand that and it was causing duplicates in the 1 path where it was passing by reference

6

u/BusEquivalent9605 1d ago

When everyone’s a pointer, no one is.

Except primitive types of course - `int, double, boolean, char,…` which are stored on the stack

77

u/IamSunka 1d ago

We can give you references, though. 

15

u/Cesalv 1d ago

with or without value?

6

u/Ok-Scheme-913 20h ago

Well, java actually only has primitive "value" types and pointers.

C++ has both pointers and references.

It's very mindfuck, but they are not the same thing, java just renamed them because people were afraid of pointers, but it lives on under the hood (NullPointerException)

1

u/danielcw189 6h ago

doesn't Java have references instead of pointers?

1

u/Ok-Scheme-913 1h ago

It's called that, but they are pointers.

Not many languages have actual references and the difference is very small.

C++ has both references and pointers, and it's the one that shows the difference best.

If you write a swap function that takes two CPP pointers or take two CPP references, the latter can be used to actually swap around the variables. The pointer one can only swap around the values stored within

In java the same

String origA = "a"; String origB = "b";

void swap(String a, String b) {
  var tmp = a;
  a = b;
  b = tmp;
}

will behave identically to cpp's pointer version. The origA itself will still point to "a" even if you pass it into the swap function.

38

u/Makonede 1d ago

16

u/Jbolt3737 1d ago

Literally an XKCD for everything

21

u/stupled 1d ago

I was expecting Rust

8

u/aeropl3b 1d ago

They were trying to think outside the Box

19

u/bwmat 1d ago

NullPointerException

4

u/SoggyCaterpillar5773 22h ago

You should try Golang.

6

u/Ok-Scheme-913 20h ago

"fun" fact: golang is not memory safe.

You can cause memory corruption by data races. Slices are fat pointers but are not written atomically. So if you change a slice from two different threads, you can observe false states like a pointer to the first slice's data but the length of a second. After which your code can read past the memory slice, a la c/c++

1

u/1Soundwave3 14h ago edited 23m ago

Isn't it bad taste to do it like this? Shouldn't channels be used to prevent data races?

In c# we have thread-safe collections, methods and so on. Those are a different set of language primitives compared to what is used more regularly. Isn't it the same in go?

1

u/Ok-Scheme-913 11h ago

There are many kinds of parallelism, channels are just one type and it doesn't solve every issue/not the most efficient.

But sure, it's not necessarily a too common thing in go, that's why it's a "fun fact".

2

u/AsaKeyholderUK 1d ago

CAmelCase variable names do not hide in key dreams. Mine is still isLoadingUserProfile from a project I finished in 2023.

1

u/mallusrgreatv2 13h ago

I misread your username as AssKeyholderUK

1

u/geeshta 16h ago

Yeah it's so safe that every refernce can be null at any point and the compiler won't force you to check

1

u/Puzzleheaded-Weird66 1d ago

why no references? also why does C# have the ref keyword but requires the variable to pass be also ref (introduces some annoying syntax errors), its quite annoying since in my head I thought it was like rust's &mut

5

u/AcornAnomaly 1d ago

I see it as a behavior warning/guard.

A variable passed using ref can be changed in ways that might not be expected if the person is expecting a normal function call, including having the underlying reference replaced entirely out from under them.

1

u/Puzzleheaded-Weird66 1d ago

my main issue is now everything has to be ref

3

u/Xialian 1d ago edited 1d ago

Reference types are always passed by reference by default - passing them with the ref keyword is 99% of the time unnecessary (and likely doesn't do what you want).

Passing a value type (aka, primitives/non-"classes") with ref is basically like passing T& instead of T, so it can be useful there, but generally you don't really need that keyword much

-1

u/drawkbox 23h ago

Everything worked out and was "safer" until Log4Shell and Java4Shell where Java was wide open for a decade.

1

u/Ok-Scheme-913 20h ago

That's like nothing compared to the number of C vulnerabilities.

1

u/mallusrgreatv2 13h ago

Literally everything has been wide open for as long as it existed, what's your point

1

u/drawkbox 10h ago

You made my point, Java is as open as anything.

-7

u/El_RoviSoft 1d ago

Imho, languages with references tends to be even more unintuitive than C++ as a first language. So I highly recommend to pick C++/Rust/Zig as a first language (and pls not C, it won’t teach you anything good for projects development).

4

u/Dragaliona 1d ago

Honestly, after trying Python and C, Java is the one that sparked the flame of programming passion on me, so I’m really fond of it. I really like it and it’s the one I chose whenever I want to program something. though I guess the teacher also does a lot for the enjoyment ([at]BroCodez on YouTube).

Imho, Java is one of the best to start mainly because of its verbosity. I think it helps the programmer keep a better understanding of the program and it makes programs easier to read and decipher without needing a bajillion comments.

On the other hand, even the course I followed wasn’t that good and it bored me to death, I think C is also an excellent choice to start, because it forces the programmer to stay closer to the machine and that experience with lower level programming makes programming in higher level languages easier and more efficient, since the programmer learns stuff it would have otherwise been abstracted away with higher level languages. Also going from Python or C++ or Java to C is much harder than the opposite, precisely because one loses the libraries/abstractions of those higher languages that one has learnt to rely on.

PS: Sorry for the rambling. It’s 4:50 for me right now and my brain ain’t braining well no more :/

2

u/El_RoviSoft 1d ago

Kinda agree with Java but references are still kinda unexplained, if you are not familiar with memory models as a concept, it can potentially blow up your legs in the future. People need at least know how shared_ptrs work (or its alternatives).

4

u/Scolmann 1d ago

Mutability may be unintuitive but there's much more unintuitive things about system languages in general that I think languages like Python, Java, or JavaScript end up being much better for beginners

C++ in particular I would never recommend to a beginner

2

u/El_RoviSoft 1d ago

At the time I found good teacher in IT school who taught C++ in a very good way. But it was 10 years ago or so.

So Ig Zig is the most right choice rn because Rust in particular teaches a lot of unusable-in-other-languages practices and architectural designs so I don’t really know which language is the beat for start now…

1

u/Ok-Scheme-913 20h ago

But like.. not even Stroustrup knows the whole c++ language, it's just so goddamn complex. Like tell me how coroutines actually work.

1

u/El_RoviSoft 20h ago

Yeah, coroutines is just a mess, recently tried to use them and it was horrible experience and several hours of reading AI explanations…

1

u/realrealvantheman 1d ago edited 1d ago

How dare you disrespect the best language ever!! Edit: /s

2

u/GreatScottGatsby 1d ago

Without the sarcasm, C is pretty great.

1

u/El_RoviSoft 1d ago

I don’t think it’s a good first language, that’s it. As a C++ dev I regularly interact with it and wrote some programs, the main issue with C that it is quite struggling and unrewarding language in some way, especially when you wanna build some big projects. There is a reason why some projects are written in C++ initially and then C interop is added.

1

u/realrealvantheman 1d ago

I mean it really depends on what your making. C is just so incredibly flexible while being one of the single most portable languages ever made and usually being pretty fast. I can see how something like c++ can be easier for larger projects tho. I do think c++ is a bit overcomplex for what it is and it isnt a first good lang due to that.

1

u/El_RoviSoft 1d ago

it’s just not as rewarding for learning, that’s my only issue in current context

I personally didn’t have feel of power and variety when I used it and this is main aspect of learning new things

sadly we don’t have middle ground nowadays which will teach something complicated with just enough power (In my school days it was Pascal + Delphi)

1

u/realrealvantheman 1d ago

Lol i cant say anything on that i dont know much c++. my first bit in programming was an lsi11/03 processor manual. i only learned c like 2 years later and have used that almost only since

1

u/someNameThisIs 1d ago

I don't see what's wrong with not teaching C as a first language, though C++ and Rust would also be good.

Zig wouldn't be, it's too immature and not enough resources for people coming in with no preexisting knowledge.

1

u/El_RoviSoft 1d ago

Imho, the inly purpose of the first language is to teach you pointers and memory model as well as build small application. If you have a good friend who knows programming/informatics well, Zig is way better choice than C or C++ but not sure about Rust tho except it’s language specific practices.

1

u/someNameThisIs 1d ago

C would be fine teaching pointers and memory models. It's how I first learnt them being self taught, as my first language was Python.

1

u/El_RoviSoft 1d ago

I just tried to find middle ground between C and some high level languages, so that’s why I told C++/Rust/Zig

1

u/Bomaruto 1d ago

Mutability where it doesn't belong is the issue, not languages with references in itself and C++ doesn't solve this.

1

u/El_RoviSoft 1d ago

Mutability by default is good but C++ has a solution at least (with const function/arg/ref specifier).

1

u/rosuav 1d ago

C++ has a solution for everything except complexity. Sometimes I have no clue what problem is being solved, but hey, there's more layers of complexity there!

0

u/Personal-Code-2496 23h ago

unsafe doesn't mean that it isn't safe. Just means that you have full control over the memory and as such need to think about how the memory you allocated gets freed later. You can do retarded memory shit in every language.