[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Tutor] beginning to code

Bill wrote:
> Mark Lawrence wrote:
>> On 22/09/2017 08:01, Bill wrote:
>>> Steve D'Aprano wrote:
>>>> On Fri, 22 Sep 2017 02:57 pm, Bill wrote:
>>>>> I find Python to be more more
>>>>> like Java, with regard to "passing objects by reference".
>>>> Which is not a surprise, since both Python and Java use the same 
>>>> value passing
>>>> style: pass by object reference, or pass by sharing if you prefer.
>>>> Java people don't call it that. They call it pass by value, and 
>>>> categorically
>>>> deny that it is pass by reference. (They're right about the second 
>>>> point.)
>>> I figure that, internally, an address, a pointer, is being passed by 
>>> value to implement pass by reference.  Why do you say "they are 
>>> right" above? Are you saying it's not pass by reference?
>> Please see 
>> http://jeffknupp.com/blog/2012/11/13/is-python-callbyvalue-or-callbyreference-neither/ 
>> and http://effbot.org/zone/call-by-object.htm
> I would would agree with the description provided for the C++ example 
> provided
> string some_guy = "fred";
>  is replaced by
> char* some_guy="fred";

On second thought, so that the description is correct (matches the 
semantics), replace it by

char some_guy[10]="fred";

But then you need to use std::strcpy to reassign some_guy
to "george".

> To see that this is correct, note the some_guy may subsequently be 
> assigned to a character string much longer then "fred".  An additional 
> note: A character string literal, like "cat", never occurs more than 
> once in compiled C++ program unit.  This also shows that the provided 
> description can't be completely correct. One last thing,
> string some_guy = "fred"
> is really the same thing as
> string some_guy("fred");
> and both equivalently call the string constructor.
> The data type of "fred" is const char*, not (class) string.