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