Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(453)

Issue 2305043: code review 2305043: fmt: allow %d on []byte (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
14 years, 5 months ago by r
Modified:
14 years, 5 months ago
Reviewers:
r2, rog
CC:
rsc, adg, golang-dev
Visibility:
Public.

Description

fmt: allow %d on []byte Fixes issue 1159.

Patch Set 1 #

Patch Set 2 : code review 2305043: fmt: allow %d on []byte #

Unified diffs Side-by-side diffs Delta from patch set Stats (+4 lines, -1 line) Patch
M src/pkg/fmt/fmt_test.go View 2 chunks +3 lines, -0 lines 0 comments Download
M src/pkg/fmt/print.go View 1 chunk +1 line, -1 line 0 comments Download

Messages

Total messages: 5
r
Hello rsc (cc: golang-dev@googlegroups.com), I'd like you to review this change.
14 years, 5 months ago (2010-10-04 03:22:57 UTC) #1
adg
LGTM On 4 October 2010 14:22, <r@golang.org> wrote: > Reviewers: rsc, > > Message: > ...
14 years, 5 months ago (2010-10-04 09:27:21 UTC) #2
r
*** Submitted as http://code.google.com/p/go/source/detail?r=70ddef42f94e *** fmt: allow %d on []byte Fixes issue 1159. R=rsc, adg ...
14 years, 5 months ago (2010-10-04 09:57:52 UTC) #3
rog
this is interesting. it seem slightly inconsistent, and the documentation has nothing to say about ...
14 years, 5 months ago (2010-10-04 10:43:31 UTC) #4
r2
14 years, 5 months ago (2010-10-04 11:56:25 UTC) #5
you're right that things aren't as well documented as they could be.  (is printf
ever well documented?)

but here's how to think about it.  after a recent rewrite, the verbs are
secondary.  that is, printf prints according to the type of the argument first. 
the verb can color the result, as you see with the struct example.  for
composite objects, the effect is mostly to apply the verb to its elements.

there's probably a good way to explain this, and i'm sure there are cases one
can construct where you don't get what you expect.  %d on []byte was one; %o
etc. on []byte won't work at the moment, but that's a lack of the implementation
rather than the approach.

-rob

On Oct 4, 2010, at 12:43 PM, roger peppe wrote:

> this is interesting.
> 
> it seem slightly inconsistent, and the documentation has nothing
> to say about behaviour with respect to slices other
> than slices of byte, AFAICS.
> 
> fmt.Sprintf("%d", []int{10, 11, 12}) -> "[10 11 12]"
> fmt.Sprintf("%x", []int{10, 11, 12}) -> "[a b c]"
> fmt.Sprintf("%d", []byte{10, 11, 12}) -> "[10 11 12]"
> fmt.Sprintf("%x", []byte{10, 11, 12}) -> "0a0b0c"
> 
> at the least, i think it should be documented that %d (and %o and... ?)
> work on slices; and if Printf works, why not Scanf too?
> 
> i had previously assumed that for anything other than the basic
> types, it was necessary to use %v. but
> 
>    fmt.Printf("%x\n", struct{a, b int; c string}{10,11,"foo"})
> 
> works too. what other interesting behaviour is lurking there?
> 
> On 4 October 2010 10:57,  <r@golang.org> wrote:
>> *** Submitted as
>> http://code.google.com/p/go/source/detail?r=70ddef42f94e ***
>> 
>> fmt: allow %d on []byte
>> Fixes issue 1159.
>> 
>> R=rsc, adg
>> CC=golang-dev
>> http://codereview.appspot.com/2305043
>> 
>> 
>> http://codereview.appspot.com/2305043/
>> 

Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b