Re:Ask HN: How is the job search coming along for people who...
by eptcyka on Tuesday December 06, 2022 @03:59PM
(#33886949)
What are you on about? Java, Python, Ruby, C#, JavaScript, most languages used to day have reference semantics for objects.
[ Parent
| on HN ]
Re:Ask HN: How is the job search coming along for people who...
by bin_bash on Wednesday December 07, 2022 @11:58AM
(#33896816)
I don't think any of the languages you mentioned support true pass-by-reference. (maybe C# and Java, but it's not common) I've heard what you're describing as "pass-by-value-reference" Go, however, supports pass-by-reference which allows you to write a function like this:
func swap(x *int, y *int) {
var temp int
temp = *x /* save the value at address x */
*x = *y /* put y into x */
*y = temp /* put temp into y */
}
Re:Ask HN: How is the job search coming along for people who...
by eptcyka on Wednesday December 07, 2022 @04:01PM
(#33900173)
Sure, you can't have the same code for Python, for instance, even if it was using objects, but you can have the same effect using a hack by copying the __dict__ from one object to another. However, you are still passing the object to a function by reference because the function can mutate the object and the object that the callee passed will also be mutated the same way, i.e. mutable objects are passed by reference, and values are passed as values. Which is how python, javascript, Java and the rest work. Obviously, you don't get to change what the reference is pointing to in most of these languages, but you can change the value that is being pointed to.