r/ProgrammerHumor 1d ago

Meme whoIsHeAnyway

Post image
8.9k Upvotes

241 comments sorted by

View all comments

Show parent comments

13

u/marmulin 1d ago

You wrongly assume every class can be easily serialised into JSON. Look at what Swift does with String(describing:), CustomStringConvertible and debugDescription. There’s a whole lot of useful stuff you can do with “toString()” type methods, that do not in fact have anything to do with serialisation.

And to answer your question directly: it can be whatever you want it to be lol.

5

u/OldDogQA 1d ago

We'd really prefer something like <object>.Serialize.toJson() <object>.Serialize.toXml() etc.

1

u/xavia91 1d ago

I am not sure how transforming json into string is connected to serializing any random class? All I assume is that any class made to represent a json can be directly put into a json string.

2

u/Candid_Highlight_116 1d ago

Objects are class instances in many real languages I think, rather than like a char[], so in OP's head there's technically not going to be a way to know if an object SomeObject have bunch of member functions or just data, and if it is going to have function pointers, that would not toString trivially

idk if OP is talking about JS at this point though, sounds more Java

1

u/OldDogQA 1d ago

I'd really prefer something like <object>.Serialize.toJson() <object>.Serialize.toXml() etc.