On Mon, Jun 19, 2017 at 11:30 PM, Will Hawkins <hawki...@borlaugic.com> 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!

I think you are being misled by trying to use the language in the spec
to interpret the meaning of %T in the fmt package.  Perhaps the fmt
package docs should be updated, but the actual behavior is not going
to change.  What %T prints is the type of the value passed in, unless
the value passed in has an interface type, in which case it prints the
dynamic type of the value.

Ian

-- 
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