« first day (396 days earlier)      last day (439 days later) » 

00:33
Java is just a historical default assumption here I think :) nowadays C# is probably a safer guess anyway
(C# has both reference-semantic and value-semantic types, and user-defined types can be either: struct produces a value-semantic type, and class produces a reference-semantic type.)
That said, I strongly feel that we should have a suite of canonicals that explain the semantics either specifcially in Python terms, or in language-agnostic terms, or relying on the latter to explain the former. And that is the approach I'm going to take with the new stuff I'm writing for Codidact :)
which is to say, first I'll author something there that introduces the concepts of value semantics and reference semantics, and then I'll be able to have shorter Q&A that says things like "all Python variables have reference semantics"; "Java non-array primitives have value semantics"; "c# types defined with struct have value semantics"; "C and C++ use value semantics and emulating reference semantics is left to the user"
a proper explanation of this concept is crucial because the old "pass by value" terminology debate is dependent upon it, along with other "changes seen in some cases and not others" issues.
But more fundamentally, the conceptual problem in Python is that the = syntax gets used for both slice assignment (i.e. a form of mutation) and ordinary assignment (a form of replacement), while augmented assignment syntax can do either
In my own language design I vow not to repeat that.
@wjandrea Because in Java the semantics of assignment with primitive types and wrapper classes (like the int assignment the OP shows) is a notorious pain, but in R it isn't; and specifically, aliasing with ints vs Integers like the OP seems to be asking about is a thing in Java. I had also checked their SO post history and saw the R. We can't be 100% sure their use-case is Java, but it isn't R (and unlikely to be C# either)...
(well, it becomes "the same thing" again if you take the perspective of the globals() dict, or a stack-frame object, but I digress)
@smci This is why I endorse not thinking about other languages here; although there's some value in considering why OP expects a different result, a proper canonical would cover all possible reasonable expectations, because it's a small set.
Either way, my point stands: you have to actually ask them to clarify which language and which expected behavior, don't just rush to guillotine all discussion with "their confusion must be about the list assignment, it couldn't be with the int assignment" and start citing teh wring Python canonicals that don't fit.
I think that "why is the result for the integer different from the result for the list?" depends only on what is meant by "different from", and not on which result "makes more sense" to the person asking.
At least as long as we are still entertaining the idea of writing a canonical from scratch.
00:48
@KarlKnechtel I disagree: whether we like it or not, many new programmers are migrating from Java, JS or SQL, so 2/3 of the struggle is unlearning their assumptions from their language-of-origin and its quirks. It simply isn't effective communication to them to keep citing the Batchelder essay and insisting it's all very simple; Java programmers have been led to expect automatic unboxing and boxing. Anyway they'll use different terms ("array" instead of "list") so they won't find...
... let alone understand anything we write from a Python-only point of view.
@KarlKnechtel No, it won't be short: if you try to write a language-agnostic canonical complete with examples from all the main languages new programmers could be migrating from, it won't be short, or legible, and they won't even find, let alone read or understand it. It'll be a ton of work with no gain. But try to draft one by all means if you want...
(I'll just invite you to examine my work on Codidact in a few months perhaps)
(I don't really know what my priority order is for the main subjects)
 
6 hours later…
06:48
@smci This is a highly elaborate back-story. We'll see if the OP responds to your comments - my money is on "no" and the idea of boxing will be more confusing to them
07:40
@wjandrea There's Are Python variables pointers? Or else, what are they? which covers pretty much exactly that case.
07:53
22 messages moved from Python
23 messages moved from Python
08:18
2 messages moved from Python

« first day (396 days earlier)      last day (439 days later) »