There might be a difference between the wording used in the formal
language specification and the documentation of packages?

Personally I cannot see why someone might interpret "type" in the
documentation of fmt.Printf as being the static type of interface{}.

V. 

On Tuesday, 20 June 2017 08:30:25 UTC+2, Will Hawkins wrote:
>
>
>
> On Tuesday, June 20, 2017 at 2:19:25 AM UTC-4, Volker Dobler wrote:
>>
>> On Tuesday, 20 June 2017 06:52:58 UTC+2, Will Hawkins wrote:
>>>
>>> I know that there is a difference between interface values and dynamic 
>>> types and dynamic values. Is it possible that the documentation about the 
>>> %T is misleading? Should it be more specific that it returns the variable's 
>>> "dynamic type." 
>>> [...] 
>>>
>> Should the documentation for %T be updated to say that it prints the 
>>> variable's dynamic type?
>>>
>>
>> Well, no.
>> Look at fmt.Printf: It take a format string and a bunch of interface{} 
>> values to
>> be printed. If %T would print the static type it always would print 
>> interface{}.
>> To be useful Printf has too look inside it's arguments and inside is a 
>> HelloInt.
>>
>
> Mr. Dobler,
>
> Thank you for your reply!
>
> I agree with your statement that to be useful, the Printf function must do 
> what it does. And, of course I want it to be useful :-)
>
> However, I am still concerned about this language from the spec:
>
> "The *static type* (or just *type*) of a variable is the type given in 
> its declaration, the type provided in the new call or composite literal, 
> or the type of an element of a structured variable."
>
> Where it says "just *type*" means that anywhere the documentation uses 
> the word "type" without qualification, it is referring to the static type. 
> In the case of Printf, then, *yes*, %T should always print "interface{}" 
> because that is the variable's static type.
>
> I 200% (that's more than 100% :-)) agree with you that is *not* useful. 
> However, based on the language in the spec, it is how I would expect it to 
> operate.
>
> I sincerely appreciate your willingness to read through my message and 
> offer your reply. I am already learning very much!
>
> Will
>  
>
>> The HelloListen basically gets lost while repacking the actual HelloInt 
>> into the
>> empty interface{} of Printf's arguments.
>> So all is fine, all is consistent and no documentation is misleading. 
>>
>> It is just that fmt.Printf is not a magical function working outside of 
>> the type
>> system. Any argument you supply is assigned to an empty interface. This
>> is how argument passing in Go works. You might try:
>> var empty interface{}
>> empty = hellolisten
>> fmt.Printf("empty: %T\n", empty)
>> which makes this repacking into an interface{} explicit and now it is 
>> obvious
>> that it will print main.HelloInt.
>>
>> V.
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to