Re:Reasons Python Sucks
by lights0123 on Saturday January 14, 2023 @07:27PM
(#34385516)
"Reason 7: Pass By Object Reference": isn't this the case of almost every GC'd language? Java, JS, PHP, Swift, and C# all do so, although C# doesn't if your type is a "struct" not a class. Go is the only popular exception I can think of.
[ Parent
| on HN ]
C, C++ also pass by value, but yes.
any language with immutability by default, say Clojure.
If the object is immutable you can't really tell if it was passed by value or by reference. It becomes an implementation detail.
Re:Reasons Python Sucks
by eyelidlessness on Saturday January 14, 2023 @08:16PM
(#34385793)
Yep, one of the theoretical promises of FP that’s totally vindicated (unless there’s a language bug, but they usually get this much right). And because you can’t tell, you don’t need to care.
For folks working in imperative languages, you can achieve this same bliss by either not modifying your function parameters in the first place (hopefully this is obvious if you care about the distinction and find the language behavior ambiguous)… or by just doing whatever copy/clone/value transfer would be appropriate as a first step if you have good reason to modify the value of a parameter to your otherwise pure function.
Python is actually different in that the whole "pass by value" vs. "pass by reference" distinction doesn't really apply. At the C level, yes, every Python object is "passed by reference" in the sense that pointers to its C structure are what get passed around. But at the Python level, Python "variables" aren't labels for memory locations, as they are in other languages; they're namespace bindings. And a function can't access the caller's namespace at all unless the global or nonlocal keywords are explicitly used. So in many ways Python's function call semantics are more like "pass by value" than "pass by reference"; but they're really not quite the same as either one.