FAQ
Hi,

Using the emoding/json or encoding/xml packages, is it possible to
unmarshal JSON/XML into enums?
For example, I have an XML field which should have only two possible values
and I can define these in Go as:

type myType string

const (
possibleValueOne myType = "valueOne"
possibleValueTwo myType = "valueTwo"
)

Then in the struct where I'm doing the unmarshalling I have:

type MyStruct struct {
TheType myType
}

Does it make sense to do something like this?

Thanks,
Robert

--

Search Discussions

  • Kyle Lemons at Dec 27, 2012 at 5:32 pm
    If you implement http://golang.org/pkg/encoding/json/#Unmarshaler you will
    be able to decode a string description of the type into a (pointer to a)
    myType value.

    On Thu, Dec 27, 2012 at 7:54 AM, Robert D. wrote:

    Hi,

    Using the emoding/json or encoding/xml packages, is it possible to
    unmarshal JSON/XML into enums?
    For example, I have an XML field which should have only two possible
    values and I can define these in Go as:

    type myType string

    const (
    possibleValueOne myType = "valueOne"
    possibleValueTwo myType = "valueTwo"
    )

    Then in the struct where I'm doing the unmarshalling I have:

    type MyStruct struct {
    TheType myType
    }

    Does it make sense to do something like this?

    Thanks,
    Robert

    --

    --
  • Robert D. at Dec 28, 2012 at 3:13 pm
    Thanks, this is indeed what I was looking for.
    How about the encoding/xml package? Is it possible to achive something
    similar for XML? It doesn't seem to have an Unmarshaler interface type.
    By the way, isn't the correct spelling "Unmarshaller" or is there a reason
    for it being spelled that way?

    Robert
    On Thursday, December 27, 2012 6:31:50 PM UTC+1, Kyle Lemons wrote:

    If you implement http://golang.org/pkg/encoding/json/#Unmarshaler you
    will be able to decode a string description of the type into a (pointer to
    a) myType value.


    On Thu, Dec 27, 2012 at 7:54 AM, Robert D. <robert...@gmail.com<javascript:>
    wrote:
    Hi,

    Using the emoding/json or encoding/xml packages, is it possible to
    unmarshal JSON/XML into enums?
    For example, I have an XML field which should have only two possible
    values and I can define these in Go as:

    type myType string

    const (
    possibleValueOne myType = "valueOne"
    possibleValueTwo myType = "valueTwo"
    )

    Then in the struct where I'm doing the unmarshalling I have:

    type MyStruct struct {
    TheType myType
    }

    Does it make sense to do something like this?

    Thanks,
    Robert

    --

    --
  • Johann Höchtl at Dec 28, 2012 at 4:00 pm

    Am Freitag, 28. Dezember 2012 16:13:12 UTC+1 schrieb Robert D.:
    Thanks, this is indeed what I was looking for.
    How about the encoding/xml package? Is it possible to achive something
    similar for XML? It doesn't seem to have an Unmarshaler interface type.
    By the way, isn't the correct spelling "Unmarshaller" or is there a reason
    for it being spelled that way?
    Some of the people involved in Go have an inclination to such things:
    http://unix.stackexchange.com/questions/10893/what-did-ken-thompson-mean-when-he-said-id-spell-create-with-an-e


    Robert
    On Thursday, December 27, 2012 6:31:50 PM UTC+1, Kyle Lemons wrote:

    If you implement http://golang.org/pkg/encoding/json/#Unmarshaler you
    will be able to decode a string description of the type into a (pointer to
    a) myType value.

    On Thu, Dec 27, 2012 at 7:54 AM, Robert D. wrote:

    Hi,

    Using the emoding/json or encoding/xml packages, is it possible to
    unmarshal JSON/XML into enums?
    For example, I have an XML field which should have only two possible
    values and I can define these in Go as:

    type myType string

    const (
    possibleValueOne myType = "valueOne"
    possibleValueTwo myType = "valueTwo"
    )

    Then in the struct where I'm doing the unmarshalling I have:

    type MyStruct struct {
    TheType myType
    }

    Does it make sense to do something like this?

    Thanks,
    Robert

    --

    --
  • Kyle Lemons at Dec 29, 2012 at 8:50 am

    On Fri, Dec 28, 2012 at 7:13 AM, Robert D. wrote:

    Thanks, this is indeed what I was looking for.
    How about the encoding/xml package? Is it possible to achive something
    similar for XML?
    No, unfortunately (at least, not yet).

    It doesn't seem to have an Unmarshaler interface type.
    By the way, isn't the correct spelling "Unmarshaller" or is there a reason
    for it being spelled that way?
    I don't know why, but historically "Marshal" is spelled with one L (in
    multiple programming languages). The opposite, then, is "Unmarshal" and
    the idiom in Go for a one-function interface is funcName + "er", thus
    "Unmarshaler".

    Robert

    On Thursday, December 27, 2012 6:31:50 PM UTC+1, Kyle Lemons wrote:

    If you implement http://golang.org/**pkg/encoding/json/#Unmarshaler<http://golang.org/pkg/encoding/json/#Unmarshaler>you will be able to decode a string description of the type into a (pointer
    to a) myType value.

    On Thu, Dec 27, 2012 at 7:54 AM, Robert D. wrote:

    Hi,

    Using the emoding/json or encoding/xml packages, is it possible to
    unmarshal JSON/XML into enums?
    For example, I have an XML field which should have only two possible
    values and I can define these in Go as:

    type myType string

    const (
    possibleValueOne myType = "valueOne"
    possibleValueTwo myType = "valueTwo"
    )

    Then in the struct where I'm doing the unmarshalling I have:

    type MyStruct struct {
    TheType myType
    }

    Does it make sense to do something like this?

    Thanks,
    Robert

    --

    --
    --
  • Robert D. at Dec 29, 2012 at 1:03 pm

    On Saturday, December 29, 2012 9:41:57 AM UTC+1, Kyle Lemons wrote:
    On Fri, Dec 28, 2012 at 7:13 AM, Robert D. <robert...@gmail.com<javascript:>
    wrote:
    Thanks, this is indeed what I was looking for.
    How about the encoding/xml package? Is it possible to achive something
    similar for XML?
    No, unfortunately (at least, not yet).

    It doesn't seem to have an Unmarshaler interface type.
    By the way, isn't the correct spelling "Unmarshaller" or is there a
    reason for it being spelled that way?
    I don't know why, but historically "Marshal" is spelled with one L (in
    multiple programming languages). The opposite, then, is "Unmarshal" and
    the idiom in Go for a one-function interface is funcName + "er", thus
    "Unmarshaler".
    Well, historically "marshal" is spelled with one L, because this is the
    correct gramatical spelling, and the oposite is then indeed "unmarshal".
    However, I would argue that your (and however wrote this code)
    interpretation of the following Go idiom:

    *By convention, one-method interfaces are named by the method name plus the
    -er suffix: Reader, Writer, Formatter etc.*
    *
    *
    is incorrect. I could just stop here and argue that it is obviously
    incorrect because if you look at the example above you have the example
    "formatter" interface which is formed by suffixing "format" with "-er", and
    of course, that doubles the "t".

    In English "-er" is not just something that you add at the end of a word to
    form another word, it is called agentive ending
    (http://en.wikipedia.org/wiki/Agentive_ending) and it is used in order to
    create a noun <http://en.wikipedia.org/wiki/Noun> meaning "someone or
    something that does the action the verb describes".
    There are also some spelling rules in regards to building words using
    agentive endings, one of which says: "for two-syllable verbs that end in a
    single vowel followed by a single consonant other than w,x, or y, double
    the final consonant then add the agent suffix.

    Following these rules it is therefore clear that the correct spellings are
    marshaller and unmarshaller.

    It is ridiculous that such basic english spelling mistakes like this which
    tend to turn a language into a ghetto slip in the code and not only are
    tolerated but people argue about them being the correct form.

    Robert

    Robert

    On Thursday, December 27, 2012 6:31:50 PM UTC+1, Kyle Lemons wrote:

    If you implement http://golang.org/**pkg/encoding/json/#Unmarshaler<http://golang.org/pkg/encoding/json/#Unmarshaler>you will be able to decode a string description of the type into a (pointer
    to a) myType value.

    On Thu, Dec 27, 2012 at 7:54 AM, Robert D. wrote:

    Hi,

    Using the emoding/json or encoding/xml packages, is it possible to
    unmarshal JSON/XML into enums?
    For example, I have an XML field which should have only two possible
    values and I can define these in Go as:

    type myType string

    const (
    possibleValueOne myType = "valueOne"
    possibleValueTwo myType = "valueTwo"
    )

    Then in the struct where I'm doing the unmarshalling I have:

    type MyStruct struct {
    TheType myType
    }

    Does it make sense to do something like this?

    Thanks,
    Robert

    --

    --
    --
  • Nigel Tao at Dec 30, 2012 at 5:48 am

    On Sat, Dec 29, 2012 at 9:11 PM, Robert D. wrote:
    However, I would argue that your (and however wrote this code)
    interpretation of the following Go idiom:
    You misspelled "whoever". :-)

    It is ridiculous that such basic english spelling mistakes like this which
    tend to turn a language into a ghetto slip in the code and not only are
    tolerated but people argue about them being the correct form.
    The misspelling is unfortunate, but it is not something we can change
    without breaking backwards compatibility with Go 1. Even so, I don't
    think that this mistake makes a ghetto inevitable. As previously
    mentioned, Unix misspelled creat with only one 'e', yet it has been
    remarkably successful.

    --
  • Bryanturley at Dec 30, 2012 at 3:51 am

    On Saturday, December 29, 2012 6:45:49 PM UTC-7, Nigel Tao wrote:
    On Sat, Dec 29, 2012 at 9:11 PM, Robert D. wrote:
    However, I would argue that your (and however wrote this code)
    interpretation of the following Go idiom:
    You misspelled "whoever". :-)

    It is ridiculous that such basic english spelling mistakes like this which
    tend to turn a language into a ghetto slip in the code and not only are
    I just spent 5 minutes trying to figure out how to do a drive by emailing,
    guess I am not thug enough.
    ;)

    tolerated but people argue about them being the correct form.
    The misspelling is unfortunate, but it is not something we can change
    without breaking backwards compatibility with Go 1. Even so, I don't
    think that this mistake makes a ghetto inevitable. As previously
    mentioned, Unix misspelled creat with only one 'e', yet it has been
    remarkably successful.
    Really that was an accident? I thought it was a space/time saver.

    --
  • Johann Höchtl at Dec 30, 2012 at 3:26 pm

    Am Sonntag, 30. Dezember 2012 04:51:52 UTC+1 schrieb bryanturley:

    On Saturday, December 29, 2012 6:45:49 PM UTC-7, Nigel Tao wrote:
    On Sat, Dec 29, 2012 at 9:11 PM, Robert D. wrote:
    However, I would argue that your (and however wrote this code)
    interpretation of the following Go idiom:
    You misspelled "whoever". :-)

    It is ridiculous that such basic english spelling mistakes like this which
    tend to turn a language into a ghetto slip in the code and not only are
    I just spent 5 minutes trying to figure out how to do a drive by emailing,
    guess I am not thug enough.
    ;)

    tolerated but people argue about them being the correct form.
    The misspelling is unfortunate, but it is not something we can change
    without breaking backwards compatibility with Go 1. Even so, I don't
    think that this mistake makes a ghetto inevitable. As previously
    mentioned, Unix misspelled creat with only one 'e', yet it has been
    remarkably successful.
    Really that was an accident? I thought it was a space/time saver.

    <history>
    early Unix had a 6 character limitation (actually 6 characters, dot, suffix
    1 character). But 'create' fits within 6 characters.
    </history>


    --
  • Michael Jones at Jan 2, 2013 at 3:22 am
    That was no accident. That was Ken's decision. One that he continued in Go
    (early versions) and then decided to change.

    On Sat, Dec 29, 2012 at 7:51 PM, bryanturley wrote:


    On Saturday, December 29, 2012 6:45:49 PM UTC-7, Nigel Tao wrote:
    On Sat, Dec 29, 2012 at 9:11 PM, Robert D. wrote:
    However, I would argue that your (and however wrote this code)
    interpretation of the following Go idiom:
    You misspelled "whoever". :-)

    It is ridiculous that such basic english spelling mistakes like this which
    tend to turn a language into a ghetto slip in the code and not only are
    I just spent 5 minutes trying to figure out how to do a drive by emailing,
    guess I am not thug enough.
    ;)

    tolerated but people argue about them being the correct form.
    The misspelling is unfortunate, but it is not something we can change
    without breaking backwards compatibility with Go 1. Even so, I don't
    think that this mistake makes a ghetto inevitable. As previously
    mentioned, Unix misspelled creat with only one 'e', yet it has been
    remarkably successful.
    Really that was an accident? I thought it was a space/time saver.

    --



    --
    Michael T. Jones | Chief Technology Advocate | mtj@google.com | +1
    650-335-5765

    --
  • Robert D. at Dec 30, 2012 at 1:26 pm

    On Sunday, December 30, 2012 2:45:49 AM UTC+1, Nigel Tao wrote:
    On Sat, Dec 29, 2012 at 9:11 PM, Robert D. wrote:
    However, I would argue that your (and however wrote this code)
    interpretation of the following Go idiom:
    You misspelled "whoever". :-)
    Only I didn't include it in my programming language, did I?
    You and some other posters here are totally missing the point. There is a
    big difference between writing a word in an email and writing a "word" in a
    programming language which will supposedly be used by millions of people
    who will have to put up with bad grammar.

    It is ridiculous that such basic english spelling mistakes like this which
    tend to turn a language into a ghetto slip in the code and not only are
    tolerated but people argue about them being the correct form.
    The misspelling is unfortunate, but it is not something we can change
    without breaking backwards compatibility with Go 1. Even so, I don't
    think that this mistake makes a ghetto inevitable. As previously
    mentioned, Unix misspelled creat with only one 'e', yet it has been
    remarkably successful.
    --
  • Chris dollin at Dec 30, 2012 at 1:43 pm

    On 30 December 2012 13:25, Robert D. wrote:

    You and some other posters here are totally missing the point. There is a
    big difference between writing a word in an email and writing a "word" in a
    programming language which will supposedly be used by millions of people who
    will have to put up with bad grammar.
    They already do -- programming language grammar is not
    natural language grammar, even though bits of it are copied
    from that source.

    Micro-details about consonant doubling in a preferred
    (by someone) variant of English are not even in the noise.

    Chris

    --
    Chris "allusive" Dollin

    --
  • DisposaBoy at Dec 30, 2012 at 11:18 am

    On Saturday, December 29, 2012 10:11:25 AM UTC, Robert D. wrote:

    On Saturday, December 29, 2012 9:41:57 AM UTC+1, Kyle Lemons wrote:
    On Fri, Dec 28, 2012 at 7:13 AM, Robert D. wrote:

    Thanks, this is indeed what I was looking for.
    How about the encoding/xml package? Is it possible to achive something
    similar for XML?
    No, unfortunately (at least, not yet).

    It doesn't seem to have an Unmarshaler interface type.
    By the way, isn't the correct spelling "Unmarshaller" or is there a
    reason for it being spelled that way?
    I don't know why, but historically "Marshal" is spelled with one L (in
    multiple programming languages). The opposite, then, is "Unmarshal" and
    the idiom in Go for a one-function interface is funcName + "er", thus
    "Unmarshaler".
    Well, historically "marshal" is spelled with one L, because this is the
    correct gramatical spelling, and the oposite is then indeed "unmarshal".
    However, I would argue that your (and however wrote this code)
    interpretation of the following Go idiom:

    *By convention, one-method interfaces are named by the method name plus
    the -er suffix: Reader, Writer, Formatter etc.*
    *
    *
    is incorrect. I could just stop here and argue that it is obviously
    incorrect because if you look at the example above you have the example
    "formatter" interface which is formed by suffixing "format" with "-er", and
    of course, that doubles the "t".

    In English "-er" is not just something that you add at the end of a word
    to form another word, it is called agentive ending (
    http://en.wikipedia.org/wiki/Agentive_ending) and it is used in order to
    create a noun <http://en.wikipedia.org/wiki/Noun> meaning "someone or
    something that does the action the verb describes".
    There are also some spelling rules in regards to building words using
    agentive endings, one of which says: "for two-syllable verbs that end in a
    single vowel followed by a single consonant other than w,x, or y, double
    the final consonant then add the agent suffix.

    Following these rules it is therefore clear that the correct spellings are
    marshaller and unmarshaller.

    It is ridiculous that such basic english spelling mistakes like this which
    tend to turn a language into a ghetto slip in the code and not only are
    tolerated but people argue about them being the correct form.

    Robert
    Sir, please don't try to make the language into a language-nazi-ghetto.
    It's ridiculous that you should be arguing about such trivial matter
    especially when Marshaler is a perfectly fine word. I also find it somewhat
    ironic that someone as holy as yourself doesn't knows how to spell the word
    "spelt".

    Robert

    On Thursday, December 27, 2012 6:31:50 PM UTC+1, Kyle Lemons wrote:

    If you implement http://golang.org/**pkg/encoding/json/#Unmarshaler<http://golang.org/pkg/encoding/json/#Unmarshaler>you will be able to decode a string description of the type into a (pointer
    to a) myType value.

    On Thu, Dec 27, 2012 at 7:54 AM, Robert D. wrote:

    Hi,

    Using the emoding/json or encoding/xml packages, is it possible to
    unmarshal JSON/XML into enums?
    For example, I have an XML field which should have only two possible
    values and I can define these in Go as:

    type myType string

    const (
    possibleValueOne myType = "valueOne"
    possibleValueTwo myType = "valueTwo"
    )

    Then in the struct where I'm doing the unmarshalling I have:

    type MyStruct struct {
    TheType myType
    }

    Does it make sense to do something like this?

    Thanks,
    Robert

    --

    --
    --
  • Robert D. at Dec 30, 2012 at 1:27 pm

    On Sunday, December 30, 2012 12:18:51 PM UTC+1, DisposaBoy wrote:

    On Saturday, December 29, 2012 10:11:25 AM UTC, Robert D. wrote:


    On Saturday, December 29, 2012 9:41:57 AM UTC+1, Kyle Lemons wrote:
    On Fri, Dec 28, 2012 at 7:13 AM, Robert D. wrote:

    Thanks, this is indeed what I was looking for.
    How about the encoding/xml package? Is it possible to achive something
    similar for XML?
    No, unfortunately (at least, not yet).

    It doesn't seem to have an Unmarshaler interface type.
    By the way, isn't the correct spelling "Unmarshaller" or is there a
    reason for it being spelled that way?
    I don't know why, but historically "Marshal" is spelled with one L (in
    multiple programming languages). The opposite, then, is "Unmarshal" and
    the idiom in Go for a one-function interface is funcName + "er", thus
    "Unmarshaler".
    Well, historically "marshal" is spelled with one L, because this is the
    correct gramatical spelling, and the oposite is then indeed "unmarshal".
    However, I would argue that your (and however wrote this code)
    interpretation of the following Go idiom:

    *By convention, one-method interfaces are named by the method name plus
    the -er suffix: Reader, Writer, Formatter etc.*
    *
    *
    is incorrect. I could just stop here and argue that it is obviously
    incorrect because if you look at the example above you have the example
    "formatter" interface which is formed by suffixing "format" with "-er", and
    of course, that doubles the "t".

    In English "-er" is not just something that you add at the end of a word
    to form another word, it is called agentive ending (
    http://en.wikipedia.org/wiki/Agentive_ending) and it is used in order to
    create a noun <http://en.wikipedia.org/wiki/Noun> meaning "someone or
    something that does the action the verb describes".
    There are also some spelling rules in regards to building words using
    agentive endings, one of which says: "for two-syllable verbs that end in a
    single vowel followed by a single consonant other than w,x, or y, double
    the final consonant then add the agent suffix.

    Following these rules it is therefore clear that the correct spellings
    are marshaller and unmarshaller.

    It is ridiculous that such basic english spelling mistakes like this
    which tend to turn a language into a ghetto slip in the code and not only
    are tolerated but people argue about them being the correct form.

    Robert
    Sir, please don't try to make the language into a language-nazi-ghetto.
    It's ridiculous that you should be arguing about such trivial matter
    especially when Marshaler is a perfectly fine word. I also find it somewhat
    ironic that someone as holy as yourself doesn't knows how to spell the word
    "spelt".
    I find it even more ironic that you are
    wrong. http://grammarist.com/spelling/spelled-spelt/

    Robert

    On Thursday, December 27, 2012 6:31:50 PM UTC+1, Kyle Lemons wrote:

    If you implement http://golang.org/**pkg/encoding/json/#Unmarshaler<http://golang.org/pkg/encoding/json/#Unmarshaler>you will be able to decode a string description of the type into a (pointer
    to a) myType value.

    On Thu, Dec 27, 2012 at 7:54 AM, Robert D. wrote:

    Hi,

    Using the emoding/json or encoding/xml packages, is it possible to
    unmarshal JSON/XML into enums?
    For example, I have an XML field which should have only two possible
    values and I can define these in Go as:

    type myType string

    const (
    possibleValueOne myType = "valueOne"
    possibleValueTwo myType = "valueTwo"
    )

    Then in the struct where I'm doing the unmarshalling I have:

    type MyStruct struct {
    TheType myType
    }

    Does it make sense to do something like this?

    Thanks,
    Robert

    --

    --
    --
  • Andy Balholm at Jan 2, 2013 at 5:58 pm

    On Sunday, December 30, 2012 3:18:51 AM UTC-8, DisposaBoy wrote:
    Sir, please don't try to make the language into a language-nazi-ghetto.
    It's ridiculous that you should be arguing about such trivial matter
    especially when Marshaler is a perfectly fine word. I also find it somewhat
    ironic that someone as holy as yourself doesn't knows how to spell the word
    "spelt".
    The mention of "spelt" tipped me off: Robert uses British English, some of
    the others in this thread use American English. One of the differences
    between the two is that American English doesn't double final consonants
    when adding suffixes as often as British English does. For example, we
    write "traveler" and the Brits write "traveller".

    So the Marshaler interface is named in American English. This is consistent
    with the name of the image/color (not colour) package.

    --
  • Robert D. at Jan 2, 2013 at 6:30 pm

    On Wednesday, January 2, 2013 6:58:47 PM UTC+1, Andy Balholm wrote:
    On Sunday, December 30, 2012 3:18:51 AM UTC-8, DisposaBoy wrote:

    Sir, please don't try to make the language into a language-nazi-ghetto.
    It's ridiculous that you should be arguing about such trivial matter
    especially when Marshaler is a perfectly fine word. I also find it somewhat
    ironic that someone as holy as yourself doesn't knows how to spell the word
    "spelt".
    The mention of "spelt" tipped me off: Robert uses British English, some of
    the others in this thread use American English. One of the differences
    between the two is that American English doesn't double final consonants
    when adding suffixes as often as British English does. For example, we
    write "traveler" and the Brits write "traveller".

    So the Marshaler interface is named in American English. This is
    consistent with the name of the image/color (not colour) package.
    Thanks so much Andy for taking the time to understand the problem giving
    the only rational and to the point explanation in this whole thread. It all
    makes perfect sense now.

    Robert

    --
  • Rodrigo Moraes at Dec 30, 2012 at 11:37 am

    On Dec 29, 8:11 am, "Robert D." wrote:
    In English "-er" is not just something that you add at the end of a word to
    form another word, it is called agentive ending
    (http://en.wikipedia.org/wiki/Agentive_ending)
    Independently of the misspelling nitpicks, you have a point about the
    "bad" convention. It is a little unfortunate that Go didn't set a
    convention that would work all the time. It would be useful to
    recognize an interface by its name, all the time, but because -er
    can't be used everywhere, this is not the case. I believe they didn't
    choose a convention like IMarshal to not look like java (:P), but as
    ugly as it is it would be more valuable than the -er convention which
    clearly has broken legs and force people to use names that are not
    easily recognized as an interface.

    Not a big deal, but I always wished interface names followed a
    stronger convention. Too late, now.

    -- rodrigo

    --
  • Minux at Dec 30, 2012 at 12:21 pm

    On Sunday, December 30, 2012, Rodrigo Moraes wrote:
    On Dec 29, 8:11 am, "Robert D." wrote:
    In English "-er" is not just something that you add at the end of a word to
    form another word, it is called agentive ending
    (http://en.wikipedia.org/wiki/Agentive_ending)
    Independently of the misspelling nitpicks, you have a point about the
    "bad" convention. It is a little unfortunate that Go didn't set a
    convention that would work all the time. It would be useful to
    recognize an interface by its name, all the time, but because -er
    can't be used everywhere, this is not the case. I believe they didn't
    choose a convention like IMarshal to not look like java (:P), but as
    ugly as it is it would be more valuable than the -er convention which
    clearly has broken legs and force people to use names that are not
    easily recognized as an interface.
    Go has an emphasis on small interfaces and interface composition,
    so i think this incomplete -er naming convention is actually beneficial --
    it forces us to make the interface smaller to have a nice idiomatic -er
    name.

    --
  • Rodrigo Moraes at Dec 30, 2012 at 12:40 pm

    On Dec 30, 10:21 am, minux wrote:
    Go has an emphasis on small interfaces and interface composition,
    so i think this incomplete -er naming convention is actually beneficial --
    it forces us to make the interface smaller to have a nice idiomatic -er
    name.
    But the convention is commonly not used, as in (funny names
    followed :P):

    http://golang.org/pkg/crypto/#PrivateKey -> PrivateKeyer
    http://golang.org/pkg/crypto/cipher/#Block -> Blocker
    http://golang.org/pkg/crypto/cipher/#BlockMode -> BlockModer
    http://golang.org/pkg/crypto/cipher/#Stream -> Streamer
    http://golang.org/pkg/fmt/#ScanState -> ScanStater
    http://golang.org/pkg/net/http/#CookieJar -> CookieJarer
    http://golang.org/pkg/net/http/#File -> Filer
    http://golang.org/pkg/text/template/parse/#Node -> Noder
    etc.

    ...or in so many user packages.

    It seems to me that it would be beneficial if the convention was
    strong to the point that all interfaces could be recognized by their
    names. Not a big deal, but not the case.

    -- rodrigo

    --
  • Minux at Dec 30, 2012 at 3:19 pm

    On Sun, Dec 30, 2012 at 8:40 PM, Rodrigo Moraes wrote:
    On Dec 30, 10:21 am, minux wrote:
    Go has an emphasis on small interfaces and interface composition,
    so i think this incomplete -er naming convention is actually beneficial --
    it forces us to make the interface smaller to have a nice idiomatic -er
    name.
    But the convention is commonly not used, as in (funny names
    followed :P):

    http://golang.org/pkg/crypto/#PrivateKey -> PrivateKeyer
    this is not the same interface as we are discussing.
    http://golang.org/pkg/crypto/cipher/#Block -> Blocker
    it seems you don't understand the idiom about interface naming.
    quote Kyle Lemons here:
    the idiom in Go for a one-function interface is funcName + "er".
    note the funcName here. (e.g. Read() -> Reader, Read()+Close()->ReadCloser)
    and we don't use that naming convention when an interface contains
    more than 3 methods.
  • Rodrigo Moraes at Dec 30, 2012 at 4:32 pm

    On Dec 30, 1:18 pm, minux wrote:
    it seems you don't understand the idiom about interface naming.
    quote Kyle Lemons here:
    the idiom in Go for a one-function interface is funcName + "er".
    No, I do get it. Still there are several places in the standard
    packages where this idiom is not followed, and several multiple-
    function interfaces follow the -er idiom inconsistently, because it is
    obviously not practical.

    My wish -- maybe I didn't express it clearly -- was that there was a
    general interface naming convention, practical and strong enough to
    identify interfaces by name.

    -- rodrigo

    --
  • Minux at Dec 30, 2012 at 4:48 pm

    On Mon, Dec 31, 2012 at 12:32 AM, Rodrigo Moraes wrote:
    On Dec 30, 1:18 pm, minux wrote:
    it seems you don't understand the idiom about interface naming.
    quote Kyle Lemons here:
    the idiom in Go for a one-function interface is funcName + "er".
    No, I do get it. Still there are several places in the standard
    packages where this idiom is not followed, and several multiple-
    function interfaces follow the -er idiom inconsistently, because it is
    obviously not practical.
    My wish -- maybe I didn't express it clearly -- was that there was a
    general interface naming convention, practical and strong enough to
    identify interfaces by name.
    This is also not practical. How can you stop people from naming an interface
    arbitrarily? If you want to do that, the only way is to enforce the naming
    convention at the compiler level and I'm not sure you want to do that.
    Note that even a single exception will defeat the whole goal of identifying
    interface by name (and no doubt, if we don't enforce the rule at compiler
    level [i.e. in language spec], people will break the rule for various
    reasons).

    --
  • Rodrigo Moraes at Dec 30, 2012 at 5:01 pm

    On Dec 30, 2:47 pm, minux wrote:
    This is also not practical. How can you stop people from naming an interface
    arbitrarily? If you want to do that, the only way is to enforce the naming
    convention at the compiler level and I'm not sure you want to do that.
    Note that even a single exception will defeat the whole goal of identifying
    interface by name (and no doubt, if we don't enforce the rule at compiler
    level [i.e. in language spec], people will break the rule for various
    reasons).
    Fair enough. I'm not suggesting that it should be forced by the
    compiler, just part of the idiom. Most would follow, and of course
    some would break the rule. Not everybody uses go fmt but we can say
    that it has widespread usage. If we had a naming convention for
    interfaces that was as accepted like go fmt is, it would be good
    enough for me. :-)

    -- rodrigo

    --
  • Rodrigo Moraes at Dec 30, 2012 at 12:01 pm

    On Dec 29, 8:11 am, "Robert D." wrote:
    It is ridiculous that such basic english spelling mistakes like this which
    tend to turn a language into a ghetto slip in the code and not only are
    tolerated but people argue about them being the correct form.
    This is unconfirmed, but some believe that Unmarshaler is a tribute to
    the HTTP referer header field. Both serve the same purpose: to remind
    us that we are humans and that love and compassion are everywhere, and
    that the joy of life resides in small things like a breeze in the
    face, lemonade or Jun Miyake songs.

    -- rodrigo

    --
  • Minux at Dec 30, 2012 at 12:16 pm

    On Saturday, December 29, 2012, Robert D. wrote:
    On Saturday, December 29, 2012 9:41:57 AM UTC+1, Kyle Lemons wrote:
    On Fri, Dec 28, 2012 at 7:13 AM, Robert D. wrote:

    Thanks, this is indeed what I was looking for.
    How about the encoding/xml package? Is it possible to achive something
    similar for XML?
    No, unfortunately (at least, not yet).

    It doesn't seem to have an Unmarshaler interface type.
    By the way, isn't the correct spelling "Unmarshaller" or is there a
    reason for it being spelled that way?
    I don't know why, but historically "Marshal" is spelled with one L (in
    multiple programming languages). The opposite, then, is "Unmarshal" and
    the idiom in Go for a one-function interface is funcName + "er", thus
    "Unmarshaler".
    Well, historically "marshal" is spelled with one L, because this is the
    correct gramatical spelling, and the oposite is then indeed "unmarshal".
    However, I would argue that your (and however wrote this code)
    interpretation of the following Go idiom:

    *By convention, one-method interfaces are named by the method name plus
    the -er suffix: Reader, Writer, Formatter etc.*
    *
    *
    is incorrect. I could just stop here and argue that it is obviously
    incorrect because if you look at the example above you have the example
    "formatter" interface which is formed by suffixing "format" with "-er", and
    of course, that doubles the "t".
    In English "-er" is not just something that you add at the end of a word
    to form another word, it is called agentive ending (
    http://en.wikipedia.org/wiki/Agentive_ending) and it is used in order to
    create a noun <http://en.wikipedia.org/wiki/Noun> meaning "someone or
    something that does the action the verb describes".
    There are also some spelling rules in regards to building words using
    agentive endings, one of which says: "for two-syllable verbs that end in a
    single vowel followed by a single consonant other than w,x, or y, double
    the final consonant then add the agent suffix.
    Following these rules it is therefore clear that the correct spellings are
    marshaller and unmarshaller.
    You are still arguing about this even you've being given one example
    that says marshaler is accepted on the issue tracker.

    http://www.merriam-webster.com/dictionary/marshaler

    It is ridiculous that such basic english spelling mistakes like this which
    tend to turn a language into a ghetto slip in the code and not only are
    tolerated but people argue about them being the correct form.
    --
  • Robert D. at Dec 30, 2012 at 1:31 pm

    On Sunday, December 30, 2012 1:16:49 PM UTC+1, minux wrote:
    On Saturday, December 29, 2012, Robert D. wrote:
    On Saturday, December 29, 2012 9:41:57 AM UTC+1, Kyle Lemons wrote:
    On Fri, Dec 28, 2012 at 7:13 AM, Robert D. wrote:

    Thanks, this is indeed what I was looking for.
    How about the encoding/xml package? Is it possible to achive something
    similar for XML?
    No, unfortunately (at least, not yet).

    It doesn't seem to have an Unmarshaler interface type.
    By the way, isn't the correct spelling "Unmarshaller" or is there a
    reason for it being spelled that way?
    I don't know why, but historically "Marshal" is spelled with one L (in
    multiple programming languages). The opposite, then, is "Unmarshal" and
    the idiom in Go for a one-function interface is funcName + "er", thus
    "Unmarshaler".
    Well, historically "marshal" is spelled with one L, because this is the
    correct gramatical spelling, and the oposite is then indeed "unmarshal".
    However, I would argue that your (and however wrote this code)
    interpretation of the following Go idiom:

    *By convention, one-method interfaces are named by the method name plus
    the -er suffix: Reader, Writer, Formatter etc.*
    *
    *
    is incorrect. I could just stop here and argue that it is obviously
    incorrect because if you look at the example above you have the example
    "formatter" interface which is formed by suffixing "format" with "-er", and
    of course, that doubles the "t".
    In English "-er" is not just something that you add at the end of a word
    to form another word, it is called agentive ending (
    http://en.wikipedia.org/wiki/Agentive_ending) and it is used in order to
    create a noun <http://en.wikipedia.org/wiki/Noun> meaning "someone or
    something that does the action the verb describes".
    There are also some spelling rules in regards to building words using
    agentive endings, one of which says: "for two-syllable verbs that end in a
    single vowel followed by a single consonant other than w,x, or y, double
    the final consonant then add the agent suffix.
    Following these rules it is therefore clear that the correct spellings are
    marshaller and unmarshaller.
    You are still arguing about this even you've being given one example
    that says marshaler is accepted on the issue tracker.
    If you would pay attention at the time you would notice that this was
    posted before your answer in the issues tracker.

    All in all, I did a bit of research and it turns out that as you say it is
    also an accepted form, only it is much less spread than the marshaller
    form. So I would still argue that choosing the less widespread form is a
    stupid thing to do. Anyway, it will probably not change so we will have to
    live with it. Would be great though if coders and their reviewers would use
    Google to check their impressive grammar skills.

    >

    --
  • Minux at Dec 30, 2012 at 3:42 pm

    On Sun, Dec 30, 2012 at 9:31 PM, Robert D. wrote:
    On Sunday, December 30, 2012 1:16:49 PM UTC+1, minux wrote:
    On Saturday, December 29, 2012, Robert D. wrote:
    On Saturday, December 29, 2012 9:41:57 AM UTC+1, Kyle Lemons wrote:
    On Fri, Dec 28, 2012 at 7:13 AM, Robert D. wrote:

    Thanks, this is indeed what I was looking for.
    How about the encoding/xml package? Is it possible to achive something
    similar for XML?
    No, unfortunately (at least, not yet).

    It doesn't seem to have an Unmarshaler interface type.
    By the way, isn't the correct spelling "Unmarshaller" or is there a
    reason for it being spelled that way?
    I don't know why, but historically "Marshal" is spelled with one L (in
    multiple programming languages). The opposite, then, is "Unmarshal" and
    the idiom in Go for a one-function interface is funcName + "er", thus
    "Unmarshaler".
    Well, historically "marshal" is spelled with one L, because this is the
    correct gramatical spelling, and the oposite is then indeed "unmarshal".
    However, I would argue that your (and however wrote this code)
    interpretation of the following Go idiom:

    *By convention, one-method interfaces are named by the method name plus
    the -er suffix: Reader, Writer, Formatter etc.*
    *
    *
    is incorrect. I could just stop here and argue that it is obviously
    incorrect because if you look at the example above you have the example
    "formatter" interface which is formed by suffixing "format" with "-er", and
    of course, that doubles the "t".
    In English "-er" is not just something that you add at the end of a word
    to form another word, it is called agentive ending (
    http://en.wikipedia.org/wiki/**Agentive_ending<http://en.wikipedia.org/wiki/Agentive_ending>)
    and it is used in order to create a noun<http://en.wikipedia.org/wiki/Noun> meaning
    "someone or something that does the action the verb describes".
    There are also some spelling rules in regards to building words using
    agentive endings, one of which says: "for two-syllable verbs that end in a
    single vowel followed by a single consonant other than w,x, or y, double
    the final consonant then add the agent suffix.
    Following these rules it is therefore clear that the correct spellings
    are marshaller and unmarshaller.
    You are still arguing about this even you've being given one example
    that says marshaler is accepted on the issue tracker.
    If you would pay attention at the time you would notice that this was
    posted before your answer in the issues tracker.

    All in all, I did a bit of research and it turns out that as you say it is
    also an accepted form, only it is much less spread than the marshaller
    form. So I would still argue that choosing the less widespread form is a
    stupid thing to do. Anyway, it will probably not change so we will have to
    live with it. Would be great though if coders and their reviewers would use
    Google to check their impressive grammar skills.
    You first argue that it is *incorrect*, and after given evidence that it's
    indeed correct,
    then you argue that it is stupid to use a less widespread form, what's you
    point here?

    The word marhsaler is used in projects written in languages other than Go
    too:
    http://code.google.com/codesearch#search/&q=Marshaler&type=cs
    You'd better file an issue for each of them to correct the "misspelling" or
    the
    stupid naming.

    --
  • Bryanturley at Dec 30, 2012 at 3:58 pm

    On Sunday, December 30, 2012 9:30:07 AM UTC-6, minux wrote:

    The word marhsaler is used in projects written in languages other than Go
    too:
    http://code.google.com/codesearch#search/&q=Marshaler&type=cs
    You'd better file an issue for each of them to correct the "misspelling"
    or the
    stupid naming.
    I would rather see a spec for english that is as simple as the spec for go.
    Or mass deprecations of english language stupidity.
    I mean look at the feature creep in english alone ....

    --
  • Minux at Dec 30, 2012 at 4:01 pm

    On Sun, Dec 30, 2012 at 11:58 PM, bryanturley wrote:
    On Sunday, December 30, 2012 9:30:07 AM UTC-6, minux wrote:

    The word marhsaler is used in projects written in languages other than Go
    too:
    http://code.google.com/**codesearch#search/&q=**Marshaler&type=cs<http://code.google.com/codesearch#search/&q=Marshaler&type=cs>
    You'd better file an issue for each of them to correct the "misspelling"
    or the
    stupid naming.
    I would rather see a spec for english that is as simple as the spec for go.
    Or mass deprecations of english language stupidity.
    I mean look at the feature creep in english alone ....
    There will be lots of exceptions (pun intended) that we Go users won't be
    happy with the spec of english.

    --
  • Robert D. at Dec 30, 2012 at 5:15 pm
    No, in fact, you didn't show any proof of it being correct. You pointed me
    to some website that I cannot read without an account and I don't take that
    as evidence. On the other hand I gave you some plain simple grammar rules
    regarding this issue which do prove what I wanted to point out.
    Also, if you bother to check a more realistic source, like the Oxford
    English Dictionary for example, you will find out to your astonishment that
    the suggested correct form is Marshaller.
    And yes, I admitted that the Marshaler variant may also be __correct__ but
    you have failed to prove it. I found sparing references of it on the web
    and it looks like a deprecated form or something which is very seldom used.
    And that is why I said and will say again, it is ridiculously stupid to
    choose the less popular form when it is supposed to be used by many other
    people who might dislike your tastes in grammar?

    Oh and by the way, this returns twice as many results
    http://code.google.com/codesearch#search/&q=Marshaller&type=cs
    If you check Google you will have an even better answer.

    Also you might want to reduce your level of arrogance as it totally fails
    to impress me.
    On Sunday, December 30, 2012 4:30:07 PM UTC+1, minux wrote:



    On Sun, Dec 30, 2012 at 9:31 PM, Robert D. <robert...@gmail.com<javascript:>
    wrote:
    On Sunday, December 30, 2012 1:16:49 PM UTC+1, minux wrote:
    On Saturday, December 29, 2012, Robert D. wrote:
    On Saturday, December 29, 2012 9:41:57 AM UTC+1, Kyle Lemons wrote:
    On Fri, Dec 28, 2012 at 7:13 AM, Robert D. wrote:

    Thanks, this is indeed what I was looking for.
    How about the encoding/xml package? Is it possible to achive
    something similar for XML?
    No, unfortunately (at least, not yet).

    It doesn't seem to have an Unmarshaler interface type.
    By the way, isn't the correct spelling "Unmarshaller" or is there a
    reason for it being spelled that way?
    I don't know why, but historically "Marshal" is spelled with one L (in
    multiple programming languages). The opposite, then, is "Unmarshal" and
    the idiom in Go for a one-function interface is funcName + "er", thus
    "Unmarshaler".
    Well, historically "marshal" is spelled with one L, because this is the
    correct gramatical spelling, and the oposite is then indeed "unmarshal".
    However, I would argue that your (and however wrote this code)
    interpretation of the following Go idiom:

    *By convention, one-method interfaces are named by the method name
    plus the -er suffix: Reader, Writer, Formatter etc.*
    *
    *
    is incorrect. I could just stop here and argue that it is obviously
    incorrect because if you look at the example above you have the example
    "formatter" interface which is formed by suffixing "format" with "-er", and
    of course, that doubles the "t".
    In English "-er" is not just something that you add at the end of a
    word to form another word, it is called agentive ending (
    http://en.wikipedia.org/wiki/**Agentive_ending<http://en.wikipedia.org/wiki/Agentive_ending>)
    and it is used in order to create a noun<http://en.wikipedia.org/wiki/Noun> meaning
    "someone or something that does the action the verb describes".
    There are also some spelling rules in regards to building words using
    agentive endings, one of which says: "for two-syllable verbs that end in a
    single vowel followed by a single consonant other than w,x, or y, double
    the final consonant then add the agent suffix.
    Following these rules it is therefore clear that the correct spellings
    are marshaller and unmarshaller.
    You are still arguing about this even you've being given one example
    that says marshaler is accepted on the issue tracker.
    If you would pay attention at the time you would notice that this was
    posted before your answer in the issues tracker.

    All in all, I did a bit of research and it turns out that as you say it
    is also an accepted form, only it is much less spread than the marshaller
    form. So I would still argue that choosing the less widespread form is a
    stupid thing to do. Anyway, it will probably not change so we will have to
    live with it. Would be great though if coders and their reviewers would use
    Google to check their impressive grammar skills.
    You first argue that it is *incorrect*, and after given evidence that it's
    indeed correct,
    then you argue that it is stupid to use a less widespread form, what's you
    point here?

    The word marhsaler is used in projects written in languages other than Go
    too:
    http://code.google.com/codesearch#search/&q=Marshaler&type=cs
    You'd better file an issue for each of them to correct the "misspelling"
    or the
    stupid naming.
    --
  • Minux at Dec 30, 2012 at 5:55 pm

    On Mon, Dec 31, 2012 at 1:15 AM, Robert D. wrote:

    No, in fact, you didn't show any proof of it being correct. You pointed me
    to some website that I cannot read without an account and I don't take that
    as evidence. On the other hand I gave you some plain simple grammar rules
    regarding this issue which do prove what I wanted to point out.
    ok, how about this:
    http://www.collinsdictionary.com/dictionary/english/marshaler

    also quote wikipedia:
    http://en.wikipedia.org/wiki/Marshalling_(computer_science) (emphasis added
    by me)
    In computer science, marshalling (__*sometimes spelled marshaling with a
    single l*__) is the process of transforming the memory representation of
    an object to a data format suitable for storage or transmission, and it is
    typically used when data must be moved between different parts of a
    computer program or from one program to another [snip]

    One final word: no matter how you think about it (stupid or ridiculous, you
    choose the word),
    it simply can't be changed in the whole life of Go 1 so there is no use
    arguing.
    Not to mention that Issue
    4595<http://code.google.com/p/go/issues/detail?id=4595> is
    closed as WontFix, so it's unlikely to change even in Go 2.

    --
  • Bryanturley at Dec 31, 2012 at 2:42 am

    On Sunday, December 30, 2012 11:46:47 AM UTC-6, minux wrote:

    On Mon, Dec 31, 2012 at 1:15 AM, Robert D. <robert...@gmail.com<javascript:>
    wrote:
    No, in fact, you didn't show any proof of it being correct. You pointed
    me to some website that I cannot read without an account and I don't take
    that as evidence. On the other hand I gave you some plain simple grammar
    rules regarding this issue which do prove what I wanted to point out.
    ok, how about this:
    http://www.collinsdictionary.com/dictionary/english/marshaler

    also quote wikipedia:
    http://en.wikipedia.org/wiki/Marshalling_(computer_science) (emphasis
    added by me)
    In computer science, marshalling (__*sometimes spelled marshaling with a
    single l*__) is the process of transforming the memory representation of
    an object to a data format suitable for storage or transmission, and it is
    typically used when data must be moved between different parts of a
    computer program or from one program to another [snip]

    One final word: no matter how you think about it (stupid or ridiculous,
    you choose the word),
    it simply can't be changed in the whole life of Go 1 so there is no use
    arguing.
    Not to mention that Issue 4595<http://code.google.com/p/go/issues/detail?id=4595> is
    closed as WontFix, so it's unlikely to change even in Go 2.
    Everyone is doing it wrong

    from Old French *mareschal; * related to Old High German *marahscalc *
    groom, from *marah * horse + *scalc * servant

    --
  • Bryanturley at Dec 31, 2012 at 2:42 am

    On Sunday, December 30, 2012 8:41:56 PM UTC-6, bryanturley wrote:

    On Sunday, December 30, 2012 11:46:47 AM UTC-6, minux wrote:

    On Mon, Dec 31, 2012 at 1:15 AM, Robert D. wrote:

    No, in fact, you didn't show any proof of it being correct. You pointed
    me to some website that I cannot read without an account and I don't take
    that as evidence. On the other hand I gave you some plain simple grammar
    rules regarding this issue which do prove what I wanted to point out.
    ok, how about this:
    http://www.collinsdictionary.com/dictionary/english/marshaler

    also quote wikipedia:
    http://en.wikipedia.org/wiki/Marshalling_(computer_science) (emphasis
    added by me)
    In computer science, marshalling (__*sometimes spelled marshaling with
    a single l*__) is the process of transforming the memory representation
    of an object to a data format suitable for storage or transmission, and it
    is typically used when data must be moved between different parts of a
    computer program or from one program to another [snip]

    One final word: no matter how you think about it (stupid or ridiculous,
    you choose the word),
    it simply can't be changed in the whole life of Go 1 so there is no use
    arguing.
    Not to mention that Issue 4595<http://code.google.com/p/go/issues/detail?id=4595> is
    closed as WontFix, so it's unlikely to change even in Go 2.
    Everyone is doing it wrong

    from Old French *mareschal; * related to Old High German *marahscalc *
    groom, from *marah * horse + *scalc * servant
    I demand Go 2 HAS PONIES

    --
  • Robert D. at Jan 2, 2013 at 6:30 pm

    On Monday, December 31, 2012 3:41:56 AM UTC+1, bryanturley wrote:

    On Sunday, December 30, 2012 11:46:47 AM UTC-6, minux wrote:

    On Mon, Dec 31, 2012 at 1:15 AM, Robert D. wrote:

    No, in fact, you didn't show any proof of it being correct. You pointed
    me to some website that I cannot read without an account and I don't take
    that as evidence. On the other hand I gave you some plain simple grammar
    rules regarding this issue which do prove what I wanted to point out.
    ok, how about this:
    http://www.collinsdictionary.com/dictionary/english/marshaler

    also quote wikipedia:
    http://en.wikipedia.org/wiki/Marshalling_(computer_science) (emphasis
    added by me)
    In computer science, marshalling (__*sometimes spelled marshaling with
    a single l*__) is the process of transforming the memory representation
    of an object to a data format suitable for storage or transmission, and it
    is typically used when data must be moved between different parts of a
    computer program or from one program to another [snip]

    One final word: no matter how you think about it (stupid or ridiculous,
    you choose the word),
    it simply can't be changed in the whole life of Go 1 so there is no use
    arguing.
    Not to mention that Issue 4595<http://code.google.com/p/go/issues/detail?id=4595> is
    closed as WontFix, so it's unlikely to change even in Go 2.
    Everyone is doing it wrong

    from Old French *mareschal; * related to Old High German *marahscalc *
    groom, from *marah * horse + *scalc * servant
    What? I was talking about using double "l" in the word "marshaler" not
    "marshal". You probably misunderstood me.

    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedDec 27, '12 at 12:54p
activeJan 2, '13 at 6:30p
posts34
users11
websitegolang.org

People

Translate

site design / logo © 2021 Grokbase