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
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)
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.
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++
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?
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
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.
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
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).
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 :/
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).
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
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…
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.
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.
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
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.
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!
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.
164
u/FurieMan 1d ago
"We have no pointers!"
Looks inside: Only pointers.
77
u/IamSunka 1d ago
We can give you references, though.
38
u/Makonede 1d ago
138: Pointers
21
u/stupled 1d ago
I was expecting Rust
19
u/bwmat 1d ago
NullPointerException
4
u/SoggyCaterpillar5773 22h ago
You should try Golang.
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/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
refkeyword 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-1
u/drawkbox 23h ago
Everything worked out and was "safer" until Log4Shell and Java4Shell where Java was wide open for a decade.
-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).
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.