3 ms·
"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 typ
by lights0123 4y ago
"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.
- deleted 4y ago[deleted]
- Barrin92 4y agoany language with immutability by default, say Clojure.
- ErikCorry 4y agoIf the object is immutable you can't really tell if it was passed by value or by reference. It becomes an implementation detail.
- eyelidlessness 4y agoYep, 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.
- pdonis 4y agoPython 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.
- layer8 4y agoAlso Lisp and Smalltalk & descendants pass by reference.