7

We are having a game of 'semantic football' in the office over this matter: I am writing a method for an object which will represent the object as a string. That string should be such that when typed (more likely, cut and pasted) into the interpreter window (I will keep the language name out of this for now), will produce an object which is, for our purposes, identical to the one upon which the method was called. There is a spirited discussion over the 'best' name for this method.

The terms pickle, serialize, deflate, etc have been proposed. However, it seems that those terms assume some process for the de-pickling (unserialization, etc) that is not necessarily the language interpreter itself. That is, they do not specifically refer to the case where strings of valid code are produced. This is closer to a quine, but we are re-producing the object not the code, so this is not quite right.

any suggestions?

Nicole
  • 28,243

11 Answers11

12

If you were writing Perl, you'd essentially be duplicating Data::Dumper's functionality. It takes a Perl object and turns it into a string representation that can then be used to recreate that object (essentially -- this isn't really true for blessed objects). The description of this module says it creates "stringified perl data structures".

Thus the process is stringification. That's what I've always heard it called.

CanSpice
  • 221
6

In Python that is the "repr()" function. A string representation of the object.

S.Lott
  • 45,522
  • 6
  • 93
  • 155
4

I'd pick something along these lines:

  • toStringRep()
  • createStringRepresention()
  • strRep()
  • toSource()
  • toSourceString()
Michael K
  • 15,659
4

I nominate sourcification. I agree that "quine" isn't quite right, but the part where you're producing valid source code for the object seems key.

chaos
  • 347
4

Even if I see your point about serialize hinting at deserializing (or is it "unserializing" ?) being the opposite, that would still be my preferred wording because it naturally implies that the process returns a string equivalent.

wildpeaks
  • 2,711
2

I like the pickle idea. It quite nicely says nothing at all, leaving people seeing it asking themselves WTF and having to search for documentation and/or the implementation to figure out what client code is doing...all because of a function name that is completely random.

The guy that used to run the development team where I work liked the Master and Commander book series. He liked to name things after the boats mentioned in those books. I have to say that I never ceased being titillated by the cute wit it must have taken to use those names in code. It always brought a smile to my face as I right clicked the name in VS and said, "Go to Definition," and got to wait the 20 minutes for stupisense to lock up my computer and finally take me to some random location that had nothing to do with the symbol I was looking for.

1

The method name should say what it does, not why it does it, therefore:

toString() because it's how you phrased it in the title. What's done with the string afterwards (i.e whether the object can be recreated from it) is nothing to do with the method that creates the string so shouldn't influence the method name.

If you want to also have a toString() method that creates a human readable representation of the string you could make the other one more specific like stringify() to differentiate but I would only do this if necessary.

Alb
  • 3,359
1

It seems to me that you are looking to output not just a string, per se, but rather a blueprint of the object. Something that encapsulates how it behaves and all of its attributes. You stated that this string will need to be parsed by your language interpreter, which leads me to understand that this data is being stored in a language of its own. The language that only your language interpreter can read and write. Given that, what's this language called?

Whatever you decide that it is called could then be used in the name to clarify what is being done.

myLangRepresentingObject = LanguageInterpreter->convertObjectToMyLanguage( SomeObject );

For example, if the string stored the objects using the language, XML, you could use something like this:

xmlRepresentingObject = XmlInterpreter->convertObjectToXml( SomeObject );
1

In Common Lisp this is called the printer and the reader.

Quoting the Hyperspec :

"write, prin1, princ, print, and pprint write the printed representation of object to output-stream. "

"read parses the printed representation of an object from input-stream and builds such an object."

0

Aren't you basically looking for a Hash() function? Where you would create a string representation of an object state that is reversible (unlike a normal hash).

Edit:I repeal the Hash() idea.How about ToSnapshot() and FromSnapshot()?

TheZenker
  • 476
  • 3
  • 5
0

Encode or decode would be a a more general terminology for a bidirectional process. You may also consider transform for a one way process.

JustinC
  • 3,346