By my reading of the language spec, methods can't be declared on interface types like ...
14 years, 10 months ago
(2010-03-18 21:03:31 UTC)
#3
By my reading of the language spec, methods can't be declared on interface
types like Token.
If this is not the case, then a method on Token would probably be the way to
go.
On Thu, Mar 18, 2010 at 1:51 PM, Russ Cox <rsc@google.com> wrote:
> Looks reasonable.
> Maybe it should be a method on Token?
>
> Russ
>
Sorry, I'd forgotten that Token was an interface. Are you copying a generic Token or ...
14 years, 10 months ago
(2010-03-18 21:14:21 UTC)
#4
Sorry, I'd forgotten that Token was an interface.
Are you copying a generic Token or a specific one?
If the latter, you could use Copy directly if you
convert it to a concrete type first.
Alternately, we could change the Copy methods
to return Token instead of the concrete types,
but that's inconvenient in a different way.
Russ
On Thu, Mar 18, 2010 at 2:14 PM, Russ Cox <rsc@google.com> wrote: > Sorry, I'd ...
14 years, 10 months ago
(2010-03-18 21:22:09 UTC)
#5
On Thu, Mar 18, 2010 at 2:14 PM, Russ Cox <rsc@google.com> wrote:
> Sorry, I'd forgotten that Token was an interface.
>
> Are you copying a generic Token or a specific one?
> If the latter, you could use Copy directly if you
> convert it to a concrete type first.
>
I'm copying a generic Token. This is for the general case where someone
wants to keep copies of parsed tokens
for later processing.
(I created this because I wrote some code that emits tokens to a channel,
and it resulted in some corruption. I had
CopyToken in my code, but since it depends on what types might be Tokens, I
figured it should live in the xml package.)
>
> Alternately, we could change the Copy methods
> to return Token instead of the concrete types,
> but that's inconvenient in a different way.
>
Yeah. I also considered adding "CopyToken() Token" to Token interface, then
for each Token type just having CopyToken()
call Copy() (or return the receiver, if appropriate). That has some
benefits, but I concluded that just having CopyToken as a free function is
probably simpler.
>
> Russ
>
http://codereview.appspot.com/634042/diff/2001/3001 File src/pkg/xml/xml.go (right): http://codereview.appspot.com/634042/diff/2001/3001#newcode110 src/pkg/xml/xml.go:110: // Returns a deep copy of a Token. On ...
14 years, 10 months ago
(2010-03-19 23:48:07 UTC)
#7
Issue 634042: code review 634042: Added 'CopyToken' func to safely create a copy of an xm...
(Closed)
Created 14 years, 10 months ago by Kyle C
Modified 14 years, 10 months ago
Reviewers:
Base URL:
Comments: 4