|
|
# ? Sep 26, 2013 23:32 |
|
|
# ? Jun 11, 2024 08:14 |
|
JewKiller 3000 posted:for primitives it makes a copy of the value on the callee's stack. for objects it does NOT copy the object, it makes a copy of the pointer to the original heap object on the callee's stack. if the object has mutable state and the callee invokes methods that modify it, the caller WILL see those changes reflected on his side, since the new pointer copy still points to the same heap object. see ok i admit i tend to poo poo on java without knowing that much about it (except i dont like the language and its slow), yospos bitch and all that but hold on: a function can mutate an object passed to it? but you can overwrite it locally with another object? thats really not what id call "pass by value", rather its exactly what passing by pointer in c++ accomplishes: you have a reference to an object, but you can make it refer to a different object without the caller noticing it. (whereas passing by value in c++ makes anything done to the object completely invisible to the caller) its much closer to "pass by reference" than to "pass by value" tbh. earlier you said passing by ref is a bad idea because you cant locally reason about whether a function that you call will modify your object but java has an even worse version of that particular problem: you need to actually read the functions code to see if it might invoke methods that mutate your object whereas in c++ if the signature of a function says "Butt a_butt" (pass by value) or "const Butt& a_butt" (const reference) you know that the function is not going to modify it. if it says "Butt& a_butt" (non-const reference) you know its likely to modify it (because otherwise it'd be a const ref).
|
# ? Sep 26, 2013 23:37 |
|
Zlodo posted:see ok i admit i tend to poo poo on java without knowing that much about it (except i dont like the language and its slow), yospos bitch and all that but hold on: java is doing exactly what passing a pointer in c++ is doing. the callee can make it refer to a different object without the caller noticing. that's why it isn't pass by reference. if i have the local variables Object x = a and Object y = b, i cannot call a function swap(x, y) which results in my local state changing to x = b and y = a. pass by reference would let me write that swap function (and you can write it in C++) Zlodo posted:its much closer to "pass by reference" than to "pass by value" tbh. earlier you said passing by ref is a bad idea because you cant locally reason about whether a function that you call will modify your object but java has an even worse version of that particular problem: you need to actually read the functions code to see if it might invoke methods that mutate your object that's true! mutability sucks a fat one in general Zlodo posted:whereas in c++ if the signature of a function says "Butt a_butt" (pass by value) or "const Butt& a_butt" (const reference) you know that the function is not going to modify it. if it says "Butt& a_butt" (non-const reference) you know its likely to modify it (because otherwise it'd be a const ref). yeah java does not have the const-correctness machinery of C++. there's final but it doesn't work exactly the same way
|
# ? Sep 26, 2013 23:48 |
|
a good snipe JewKiller 3000 posted:i know i need to stop posting about this but people won't stop being wrong so i can't. I too have the curse of having to post about IT
|
# ? Sep 27, 2013 00:00 |
|
JewKiller 3000 posted:java is doing exactly what passing a pointer in c++ is doing. the callee can make it refer to a different object without the caller noticing. that's why it isn't pass by reference. if i have the local variables Object x = a and Object y = b, i cannot call a function swap(x, y) which results in my local state changing to x = b and y = a. pass by reference would let me write that swap function (and you can write it in C++) i think the problem is youre really hung up on java being pass-by-value as an explicitly awesome thing when people are like "but brah i can still mutate what that object reference points to" and youre all like "but you can't mutate the reference!" and everyone is like who loving cares.
|
# ? Sep 27, 2013 00:13 |
|
FamDav posted:i think the problem is youre really hung up on java being pass-by-value as an explicitly awesome thing when people are like "but brah i can still mutate what that object reference points to" and youre all like "but you can't mutate the reference!" and everyone is like who loving cares. but it's still not pass-by-reference. I mean, you can say it's poo poo, and I'll agree. but it's not pass-by-reference. saying 'java is poo poo because it uses pass-by-reference semantics!' is a good way to have an argument that is completely different from the one you (presumably) intended to. this is why words are important sometimes.
|
# ? Sep 27, 2013 00:17 |
|
it's not that pass by value is awesome, just that pass by reference is worse, because it's another thing you have to worry about. also gucci posted that he preferred it and i wanted to argue against that i care because people are misusing technical terms in a way that helps nobody and confuses people trying to learn edit: or yeah what the guy above me said
|
# ? Sep 27, 2013 00:19 |
|
FamDav posted:i think the problem is youre really hung up on java being pass-by-value as an explicitly awesome thing when people are like "but brah i can still mutate what that object reference points to" and youre all like "but you can't mutate the reference!" and everyone is like who loving cares. not being able to mutate the reference is itself a pretty important distinction which is why we have the terms "pass by value" and "pass by reference"
|
# ? Sep 27, 2013 00:21 |
|
PleasingFungus posted:but it's still not pass-by-reference. i never said it was pass-by-reference. i'm not asking that question. that question is boring. what i said is that passing object references (by value) leads to unintended consequences, and JewKiller 3000 posted:it's another thing you have to worry about.
|
# ? Sep 27, 2013 00:23 |
cool discussion on pass by pointer semantics
|
|
# ? Sep 27, 2013 00:40 |
|
Mido posted:python is duck typed tcl or gtfo
|
# ? Sep 27, 2013 00:41 |
by cool I mean who the gently caress cares shut up
|
|
# ? Sep 27, 2013 00:42 |
|
Deacon of Delicious posted:so what does everyone think about semantic whitespace/brace styles/strong vs weak typing/global variables/spaces vs tabs/does java pass by reference or value/ide vs text editor lol allman strongish lol seriously i press tab i dont give a poo poo what comes out passes by reference by value a little of both
|
# ? Sep 27, 2013 00:43 |
can we just agree that Java not having const is a travesty and also that Java is a poo poo language and that c++ owns
|
|
# ? Sep 27, 2013 00:43 |
|
OBAMA BIN LinkedIn posted:can we just agree that Java not having const is a travesty and also that Java is a poo poo language and that c# owns
|
# ? Sep 27, 2013 00:46 |
|
OBAMA BIN LinkedIn posted:can we just agree that Java not having const is a travesty and also that Java is a poo poo language and that python owns
|
# ? Sep 27, 2013 00:52 |
|
|
# ? Sep 27, 2013 00:53 |
OBAMA BIN LinkedIn posted:can we just agree that Java not having const is a travesty and also that all programming languages are poo poo and that leaving work and going to do other poo poo owns
|
|
# ? Sep 27, 2013 00:54 |
|
oh, good timing
|
# ? Sep 27, 2013 00:59 |
|
OBAMA BIN LinkedIn posted:can we just agree that Java not having const is a travesty and also that Java is a poo poo language and that c++ owns I actually don't understand how const works in C++ since I'm a javatard. How does adding the keyword const prevent the caller from mutating the objects state or is is just a convention?
|
# ? Sep 27, 2013 01:12 |
|
Const references aren't worthwhile IMO. Good code won't mutate params and bad code will, and const doesn't change that. The right thing is to make objects logically immutable as much as possible, which const doesn't help much with. poo poo, C++11 had to introduce mutable because of the difference between a const object and an immutable one.
|
# ? Sep 27, 2013 01:16 |
|
Hard NOP Life posted:I actually don't understand how const works in C++ since I'm a javatard. How does adding the keyword const prevent the caller from mutating the objects state or is is just a convention? You mean callee mutating the object's state? It doesn't! If the callee wants to mutate the object they just won't declare the param as const.
|
# ? Sep 27, 2013 01:17 |
|
Nomnom Cookie posted:Const references aren't worthwhile IMO. Good code won't mutate params and bad code will, and const doesn't change that. The right thing is to make objects logically immutable as much as possible, which const doesn't help much with. poo poo, C++11 had to introduce mutable because of the difference between a const object and an immutable one. mutable has always existed
|
# ? Sep 27, 2013 01:25 |
|
i wish your posting was muteable
|
# ? Sep 27, 2013 01:31 |
|
FamDav posted:mutable has always existed I stand corrected. Const is still a bad idea, like checked exceptions.
|
# ? Sep 27, 2013 01:32 |
|
Nomnom Cookie posted:You mean callee mutating the object's state? It doesn't! If the callee wants to mutate the object they just won't declare the param as const. youre right, not using the keyword is exactly like not using the keyword
|
# ? Sep 27, 2013 01:35 |
|
Nomnom Cookie posted:I stand corrected. Const is still a bad idea, like checked exceptions. oh poo poo. there goes the shaggarsignal
|
# ? Sep 27, 2013 01:37 |
|
the two interesting arguments about const/mutable keywords: 1) should you ever be allowed to mutate something 2) should you be allowed to mutate by default
|
# ? Sep 27, 2013 01:37 |
|
FamDav posted:the two interesting arguments about const/mutable keywords: 1) No 2) See 1)
|
# ? Sep 27, 2013 01:42 |
|
Malcolm XML posted:1) No same
|
# ? Sep 27, 2013 01:43 |
|
FamDav posted:the two interesting arguments about const/mutable keywords: Is additional enforcement necessary beyond encapsulation? The answer is no.
|
# ? Sep 27, 2013 01:44 |
|
Talking about what languages should "allow" you to do is just another way of talking about good code and bad code. My argument is that good code will employ immutability as much as is practical, and good OOP code will have as many classes immutable as practical. In other words, controlling mutability is the responsibility of a module, not the module's users. If declaring a reference const gains you anything, well, why are you using a mutable object to do an immutable object's job?
|
# ? Sep 27, 2013 01:50 |
|
checked exceptions are good
|
# ? Sep 27, 2013 01:53 |
|
const int i = 0; i =5;
|
# ? Sep 27, 2013 01:56 |
|
Shaggar posted:checked exceptions are good Nope they're bad. Like const, just whips & chains with no reacharound.
|
# ? Sep 27, 2013 01:57 |
|
Hard NOP Life posted:I actually don't understand how const works in C++ since I'm a javatard. How does adding the keyword const prevent the caller from mutating the objects state or is is just a convention? const int* const Method3(const int* const&) const; what's hard to understand about that? it would be neat if final in java (and val in scala) trickled down to the members of objects so instead of having a final reference to an object, the object becomes immutable.
|
# ? Sep 27, 2013 01:57 |
|
Nomnom Cookie posted:Nope they're bad. Like const, just whips & chains with no reacharound. nope. checked exceptions own forever and there is literrally no argument against them other than "I hate safety AND typing"
|
# ? Sep 27, 2013 01:58 |
|
FamDav posted:the two interesting arguments about const/mutable keywords: 1) yes but only in rare cases, and before you use it, think hard about whether you really need to 2) absolutely not
|
# ? Sep 27, 2013 01:59 |
|
Condiv posted:const int* const Method3(const int* const&) const; You're conflating reference mutation with value mutation. If the object is supposed to be immutable, then it will be written that way. If it's supposed to be mutable, then why the hell are you trying to make it immutable? Const StringBuilder is a ridiculous notion.
|
# ? Sep 27, 2013 02:07 |
|
|
# ? Jun 11, 2024 08:14 |
|
Nomnom Cookie posted:You're conflating reference mutation with value mutation. If the object is supposed to be immutable, then it will be written that way. If it's supposed to be mutable, then why the hell are you trying to make it immutable? Const StringBuilder is a ridiculous notion. passing a reference by value is equivalent to passing a value by reference also the reason const exists is to give the compiler additional information so it can catch dumb programmer mistakes. the only problem is they make you have to declare const instead of declaring mutable.
|
# ? Sep 27, 2013 02:21 |